fix(proxy): strip cache_control from OpenAI format conversion#3841
Open
cc10143 wants to merge 2 commits into
Open
fix(proxy): strip cache_control from OpenAI format conversion#3841cc10143 wants to merge 2 commits into
cc10143 wants to merge 2 commits into
Conversation
377b5d7 to
6bb3e62
Compare
…1231#3805) - Remove cache_control passthrough from system messages, text blocks, and tools to prevent 400 errors on strict OpenAI-compatible endpoints - Always simplify single text block content to plain string format - Fixes two format conversion bugs reported in issue farion1231#3805
6bb3e62 to
7f01ef1
Compare
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
Fixes two format conversion bugs in
anthropic_to_openaithat cause 400 errors when routing Anthropic requests to strict OpenAI-compatible endpoints (GLM, Qwen, etc.):Bug 1: cache_control field leaks to OpenAI output
Anthropic's
cache_controlfield (e.g.{"type": "ephemeral"}) was being passed through to OpenAI-format messages, content blocks, and tools. Strict API validators reject unknown fields with400 Extra inputs are not permitted.Fix: Remove
cache_controlpassthrough from:normalize_openai_system_messagesBug 2: Content array not simplified to string for single text blocks
When a message contains a single text block (
[{"type": "text", "text": "Hello"}]), some strict backends expect"content": "Hello"(string) instead of"content": [{"type": "text", "text": "Hello"}](array). The previous code kept array format whencache_controlwas present, which prevented simplification.Fix: Always simplify single text block content to plain string, regardless of
cache_controlpresence.Related Issue
Closes #3805
Test Plan
test_regression_gh3805_no_cache_control_leak_to_openaivalidates:cache_controlin any messagecache_controlin content partssystemcontent is plain stringusercontent is plain stringcache_controlin tools