fix(passthrough): proxy provider-native error bodies, clean decode errors, cap stop sequences - #966
SantiagoDePolonia wants to merge 3 commits into
Conversation
…rors, cap stop sequences
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
|
Warning Review limit reachedNext included review available in 41 minutes. View limit detailsLimit details: You’ve used all 4 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (25)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
|
Greptile's finding is addressed in a3d4dcb: the Responses |
|
@coderabbitai review |
|
@greptileai review |
Rate Limit Exceeded
|
|
@coderabbitai review |
Rate Limit Exceeded
|
Fixes three findings from the dialect e2e run (4, 7, 10), each verified against
mainfirst.Passthrough errors are provider-native again (finding 4).
docs/features/passthrough-api.mdxpromises that provider error bodies and status codes are proxied, but every non-2xx was re-rendered in the gateway's OpenAI envelope, so the Anthropic SDK lost its typed errors and the upstreamrequest_id./p/{provider}(and the/v1/messagesnative-forwarding path) now relay the upstream JSON error body, status and content type untouched. Gateway-generated failures — authentication, rate limits, budgets, a provider that is not enabled, an unreachable upstream — keep the gateway's shape, as does an upstream body that is not JSON, is empty, or exceeds 1 MiB. Only the body, its media type and the headers the gateway already relayed on errors cross back, so upstream credentials, cookies and base URLs still cannot leak. Logs and the audit row keep the classified gateway error.Clean JSON decode errors (finding 7).
goccy/go-jsonwording reached clients verbatim:json: slice unexpected end of JSON inputfor a complete document,cannot unmarshal number \"for a string value, plus Go struct field names. Decode failures now name the offending member and the type it should have —messages: must be an array,max_tokens: must be an integer,messages[1].role: must be a string— with the member set asparamon the OpenAI envelope. Truncated and non-JSON bodies get an honest message instead of a byte-level decoder complaint. The canonical chat/responses types wrap the nested decode error so the position that identifies the member survives theirUnmarshalJSON.stop_sequencesbeyond four (finding 10). OpenAI, Azure OpenAI and Groq capstopat four items; Anthropic accepts more, and the Messages API docs say stop sequences are honored on every provider. Following Postel's law the gateway now truncates the list to each provider's limit (logging a warning) instead of letting the request fail upstream over a limit the client cannot know; Anthropic still receives the full list. The Messages API doc records the limit.Tested
go build ./...,go test -race ./internal/...,make lint,make test-race(only the pre-existingTestVersionEndpoint*local/UTC date flake fails).{"type":"error",...}withrequest_idandanthropic-pythonraises its typedNotFoundErrorwith the native body; gateway auth / disabled-provider errors stay OpenAI-shaped; success bodies still byte-verbatim; malformed bodies on/v1/chat/completions,/v1/messagesand/v1/responsesreturn the new messages; six stop sequences now succeed onopenai/gpt-4.1-miniandgroq/openai/gpt-oss-20band are still applied in full on Anthropic.