fix(anthropic): return API error for malformed non-streaming responses - #875
Open
leseb wants to merge 1 commit into
Open
fix(anthropic): return API error for malformed non-streaming responses#875leseb wants to merge 1 commit into
leseb wants to merge 1 commit into
Conversation
The Anthropic-to-OpenAI filter rewrites response headers to advertise an Anthropic response contract, but an upstream can return HTTP 200 with a body that cannot be transformed (malformed JSON, empty, or missing). Previously the filter forwarded that broken body unchanged under Anthropic headers, so clients received a response that did not conform to the advertised contract. transform_non_streaming_body now replaces any untransformable success body with a schema-complete Anthropic api_error envelope and preserves the upstream request id (now captured on the success path as well). Adds unit, proxy integration, and synthetic fixture coverage (messages/malformed-success). Closes praxis-proxy#835 Signed-off-by: Sébastien Han <seb@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Anthropic-to-OpenAI filter rewrites response headers to advertise an Anthropic response contract, but an upstream can return HTTP 200 with a body that cannot be transformed (malformed JSON, empty, or missing) — previously that broken body was forwarded unchanged, so clients received a response that did not conform to the advertised contract.
transform_non_streaming_bodynow replaces any untransformable success body with a schema-complete Anthropicapi_errorenvelope and preserves the upstream request id (now captured on the success path too). This is the smallest complete change: it only rewrites the body on the failure-to-transform path and leaves successful translations untouched.Related issue
Closes #835
Validation
cargo test -p praxis-ai-apis --lib anthropic(206 passed), covering missing / empty / malformed non-streaming success bodiesanthropic_to_openai_replaces_malformed_success_bodyproxy test andall_inference_fixtures_replaywith the new syntheticmessages/malformed-successrecordingmake lint(clippy, rustfmt, deps, docs, examples,check-inference, README sync) andmake buildChecklist
anthropic/messages-to-openai.yamlconfig.sync-inference-readme.Signed-off-bytrailer.Breaking changes
None. Only responses that previously could not be transformed change behavior: instead of a non-conformant body forwarded under Anthropic headers, clients now receive a valid Anthropic
api_errorenvelope. (The HTTP status stays200because Praxis 0.5.3 cannot change an already-selected status during response-body processing; exact500conformance needs deferred-header support in Praxis core.)