feat(billing): add image quality pricing and usage tracking

This commit is contained in:
ZheFox
2026-05-18 00:11:30 +08:00
parent 680b617b00
commit c024c782e4
13 changed files with 559 additions and 12 deletions
@@ -816,6 +816,11 @@ fn openai_image_stream_standardized_usage(
.dimensions
.insert("image_size".to_string(), serde_json::json!(size));
}
if let Some(quality) = image_request_quality(report_context) {
standardized_usage
.dimensions
.insert("image_quality".to_string(), serde_json::json!(quality));
}
(standardized_usage.signal_score() > 0).then_some(standardized_usage)
}
@@ -1049,6 +1054,16 @@ fn image_request_size(report_context: Option<&Value>) -> Option<String> {
.map(ToOwned::to_owned)
}
fn image_request_quality(report_context: Option<&Value>) -> Option<String> {
report_context
.and_then(|value| value.get("image_request"))
.and_then(|value| value.get("quality"))
.and_then(Value::as_str)
.map(str::trim)
.filter(|value| !value.is_empty())
.map(ToOwned::to_owned)
}
fn image_bridge_model(report_context: Option<&Value>) -> Option<String> {
report_context.and_then(|context| {
context