From e1e9fc43c17f886ab6b06f95d50ec554e33c824b Mon Sep 17 00:00:00 2001 From: Longwu Ou Date: Wed, 18 Mar 2026 12:30:22 -0400 Subject: [PATCH] fix: normalize model name in TranslateRequest fallback to prevent prefix leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no request translator is registered for a format pair (e.g. openai-response → openai-response), TranslateRequest returned the raw payload unchanged. This caused client-side model prefixes (e.g. "copilot/gpt-5-mini") to leak into upstream requests, resulting in "The requested model is not supported" errors from providers. The fallback path now updates the "model" field in the payload to match the resolved model name before returning. --- sdk/translator/registry.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sdk/translator/registry.go b/sdk/translator/registry.go index ace97137..98909c10 100644 --- a/sdk/translator/registry.go +++ b/sdk/translator/registry.go @@ -3,6 +3,9 @@ package translator import ( "context" "sync" + + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" ) // Registry manages translation functions across schemas. @@ -39,7 +42,9 @@ func (r *Registry) Register(from, to Format, request RequestTransform, response } // TranslateRequest converts a payload between schemas, returning the original payload -// if no translator is registered. +// if no translator is registered. When falling back to the original payload, the +// "model" field is still updated to match the resolved model name so that +// client-side prefixes (e.g. "copilot/gpt-5-mini") are not leaked upstream. func (r *Registry) TranslateRequest(from, to Format, model string, rawJSON []byte, stream bool) []byte { r.mu.RLock() defer r.mu.RUnlock() @@ -49,6 +54,11 @@ func (r *Registry) TranslateRequest(from, to Format, model string, rawJSON []byt return fn(model, rawJSON, stream) } } + if model != "" && gjson.GetBytes(rawJSON, "model").String() != model { + if updated, err := sjson.SetBytes(rawJSON, "model", model); err == nil { + return updated + } + } return rawJSON }