Skip to content

fix(proxy): strip cache_control from OpenAI format conversion#3841

Open
cc10143 wants to merge 2 commits into
farion1231:mainfrom
cc10143:feat/capability-injection
Open

fix(proxy): strip cache_control from OpenAI format conversion#3841
cc10143 wants to merge 2 commits into
farion1231:mainfrom
cc10143:feat/capability-injection

Conversation

@cc10143
Copy link
Copy Markdown

@cc10143 cc10143 commented Jun 7, 2026

Summary

Fixes two format conversion bugs in anthropic_to_openai that 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_control field (e.g. {"type": "ephemeral"}) was being passed through to OpenAI-format messages, content blocks, and tools. Strict API validators reject unknown fields with 400 Extra inputs are not permitted.

Fix: Remove cache_control passthrough from:

  • System message array items
  • Text content blocks within messages
  • Tool definitions
  • System message merge logic in normalize_openai_system_messages

Bug 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 when cache_control was present, which prevented simplification.

Fix: Always simplify single text block content to plain string, regardless of cache_control presence.

Related Issue

Closes #3805

Test Plan

  • 57 transform tests pass (1539 total lib tests)
  • New regression test test_regression_gh3805_no_cache_control_leak_to_openai validates:
    • No cache_control in any message
    • No cache_control in content parts
    • system content is plain string
    • user content is plain string
    • No cache_control in tools

@cc10143 cc10143 force-pushed the feat/capability-injection branch from 377b5d7 to 6bb3e62 Compare June 7, 2026 13:23
cc10143 added 2 commits June 7, 2026 21:32
…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
@cc10143 cc10143 force-pushed the feat/capability-injection branch from 6bb3e62 to 7f01ef1 Compare June 7, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] 代理层自动注入模型能力声明 (Model Capability Injection)

1 participant