@@ -183,6 +183,8 @@ pub struct ProxyOpts {
183183 pub cache : Arc < ChatCache > ,
184184 /// Prefix for auto-generated IDs (e.g., "chatcmpl", "img", "emb").
185185 pub id_prefix : String ,
186+ /// Model name included in the signed text.
187+ pub model_name : String ,
186188 /// If set, report usage to the cloud API after a successful response.
187189 pub usage_reporter : Option < UsageReporter > ,
188190 /// What kind of usage to extract from the response.
@@ -251,7 +253,7 @@ pub async fn proxy_json_request(
251253 let response_sha256 = hex:: encode ( Sha256 :: digest ( response_body. as_bytes ( ) ) ) ;
252254
253255 // Sign and cache
254- let text = format ! ( "{request_sha256}:{response_sha256}" ) ;
256+ let text = format ! ( "{}:{ request_sha256}:{response_sha256}" , opts . model_name ) ;
255257 let signed = opts. signing . sign_chat ( & text) . map_err ( |e| {
256258 error ! ( error = %e, "Signing failed" ) ;
257259 AppError :: Internal ( e)
@@ -304,6 +306,7 @@ pub async fn proxy_streaming_request(
304306 let signing = opts. signing . clone ( ) ;
305307 let cache = opts. cache . clone ( ) ;
306308 let usage_reporter = opts. usage_reporter . clone ( ) ;
309+ let model_name = opts. model_name . clone ( ) ;
307310
308311 let ( tx, rx) = tokio:: sync:: mpsc:: channel :: < Result < Bytes , std:: io:: Error > > ( 64 ) ;
309312
@@ -355,7 +358,7 @@ pub async fn proxy_streaming_request(
355358 if !upstream_error && !downstream_closed && parser. seen_done {
356359 let response_sha256 = hex:: encode ( hasher. finalize ( ) ) ;
357360 if let Some ( ref id) = parser. chat_id {
358- let text = format ! ( "{request_sha256}:{response_sha256}" ) ;
361+ let text = format ! ( "{model_name}:{ request_sha256}:{response_sha256}" ) ;
359362 match signing. sign_chat ( & text) {
360363 Ok ( signed) => {
361364 if let Ok ( signed_json) = serde_json:: to_string ( & signed) {
@@ -457,7 +460,7 @@ pub async fn proxy_multipart_request(
457460 serde_json:: to_string ( & response_data) . map_err ( |e| AppError :: Internal ( e. into ( ) ) ) ?;
458461 let response_sha256 = hex:: encode ( Sha256 :: digest ( response_body. as_bytes ( ) ) ) ;
459462
460- let text = format ! ( "{request_sha256}:{response_sha256}" ) ;
463+ let text = format ! ( "{}:{ request_sha256}:{response_sha256}" , opts . model_name ) ;
461464 let signed = opts. signing . sign_chat ( & text) . map_err ( |e| {
462465 error ! ( error = %e, "Signing failed" ) ;
463466 AppError :: Internal ( e)
@@ -566,7 +569,7 @@ pub async fn sign_and_cache_json_response(
566569 serde_json:: to_string ( & response_data) . map_err ( |e| AppError :: Internal ( e. into ( ) ) ) ?;
567570 let response_sha256 = hex:: encode ( Sha256 :: digest ( response_body. as_bytes ( ) ) ) ;
568571
569- let text = format ! ( "{request_sha256}:{response_sha256}" ) ;
572+ let text = format ! ( "{}:{ request_sha256}:{response_sha256}" , opts . model_name ) ;
570573 let signed = opts. signing . sign_chat ( & text) . map_err ( |e| {
571574 error ! ( error = %e, "Signing failed" ) ;
572575 AppError :: Internal ( e)
@@ -595,6 +598,7 @@ pub async fn proxy_streaming_response(
595598 let signing = opts. signing . clone ( ) ;
596599 let cache = opts. cache . clone ( ) ;
597600 let usage_reporter = opts. usage_reporter . clone ( ) ;
601+ let model_name = opts. model_name . clone ( ) ;
598602 let request_sha256 = request_sha256. to_string ( ) ;
599603
600604 let ( tx, rx) = tokio:: sync:: mpsc:: channel :: < Result < Bytes , std:: io:: Error > > ( 64 ) ;
@@ -643,7 +647,7 @@ pub async fn proxy_streaming_response(
643647 if !upstream_error && !downstream_closed && parser. seen_done {
644648 let response_sha256 = hex:: encode ( hasher. finalize ( ) ) ;
645649 if let Some ( ref id) = parser. chat_id {
646- let text = format ! ( "{request_sha256}:{response_sha256}" ) ;
650+ let text = format ! ( "{model_name}:{ request_sha256}:{response_sha256}" ) ;
647651 match signing. sign_chat ( & text) {
648652 Ok ( signed) => {
649653 if let Ok ( signed_json) = serde_json:: to_string ( & signed) {
@@ -842,6 +846,7 @@ mod tests {
842846 signing,
843847 cache,
844848 id_prefix : "test" . to_string ( ) ,
849+ model_name : "test-model" . to_string ( ) ,
845850 usage_reporter : None ,
846851 usage_type : UsageType :: default ( ) ,
847852 }
0 commit comments