[Bug] openai-compatibility: Responses→Chat translation injects non-standard `reasoning_content` into assistant tool-call messages; strict-schema upstreams reject with 422 `extra_forbidden`
Summary
When CLIProxyAPI translates an OpenAI Responses request (POST /v1/responses) into Chat Completions for an openai-compatibility channel, it injects a non-standard reasoning_content field into messages[].assistant entries that carry tool_calls. When the replayed input contains no type: "reasoning" item — the normal shape for agent tool loops where the client sets reasoning.effort / reasoning_effort but only replays plain assistant messages plus function_call / function_call_output items — the injected value is the placeholder string [reasoning unavailable].
Upstreams that validate the Chat Completions request schema strictly (FastAPI/Pydantic extra="forbid", e.g. https://api.mistral.ai/v1/chat/completions) reject the whole request with HTTP 422:
{"detail":[{"input":"[reasoning unavailable]","loc":["body","messages",2,"assistant","reasoning_content"],"msg":"Extra inputs are not permitted","type":"extra_forbidden"}]}
Lenient upstreams (DeepSeek, Moonshot, most relays) silently ignore or accept the field, which is why this goes unnoticed on those providers. Against strict-schema upstreams (such as Mistral API) it is deterministic: every multi-turn tool-loop request that enables reasoning fails with HTTP 422.
Environment
- CLIProxyAPI v8.0.48 (linux/amd64)
- Channel:
openai-compatibility→https://api.mistral.ai/v1 - Downstream client: OpenAI Python SDK,
POST /v1/responses,reasoning_effort: max,stream: true, agent-style tool loop
Reproduction
config.yaml:
openai-compatibility:
- name: Mistral
base-url: https://api.mistral.ai/v1
api-key-entries:
- api-key: sk-xxxx
models:
- name: deepseek-v4-1-flash-1017
alias: deepseek-v4.1-flash
thinking:
levels: [low, high, max]
Request — reasoning enabled at the root, with a standard multi-turn tool-loop replay in input containing no type: "reasoning" item:
curl -sS http://127.0.0.1:8317/v1/responses \
-H "Authorization: Bearer $CPA_KEY" -H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"reasoning": {"effort": "max"},
"stream": false,
"input": [
{"type":"message","role":"user","content":[{"type":"input_text","text":"hi"}]},
{"type":"message","role":"assistant","status":"completed",
"content":[{"type":"output_text","text":"running a tool"}]},
{"type":"function_call","call_id":"call_1","name":"terminal","arguments":"{}"},
{"type":"function_call_output","call_id":"call_1","output":"{}"}
]
}'
Actual
CPA translates to POST .../v1/chat/completions with an assistant message containing a non-standard reasoning_content field (and specifically the [reasoning unavailable] placeholder):
{"role":"assistant","content":"running a tool","tool_calls":[...],"reasoning_content":"[reasoning unavailable]"}
Mistral API answers 422 extra_forbidden, loc: ["body","messages",2,"assistant","reasoning_content"].
Expected
- Standard OpenAI-compatible upstreams (such as
api.mistral.ai) that strictly validate Chat Completions assistant messages should not receivereasoning_content(or synthetic[reasoning unavailable]placeholders) inmessages[]. - Reasoning replay / placeholder injection on
assistanttool-call turns should only be preserved for upstreams/models that actually require or acceptreasoning_contenton assistant messages (or stripped before sending to strict upstreams).
Root cause
In internal/translator/openai/openai/responses/openai_openai-responses_request.go:
hasReasoningInSessionflips totruewhenever the request root carriesreasoning.effort/reasoning_effort/reasoning(≈ L127-143).fallbackToolReasoning()manufactures"[reasoning unavailable]"wheneverhasReasoningInSessionis true and no reasoning text was collected (≈ L162-170).flushPendingToolCalls()unconditionally writesreasoning_contentinto the assistant message that carriestool_calls(≈ L189-197 and L205-212), andappendPendingReasoningMessage()synthesizes assistant messages withreasoning_content(≈ L238).OpenAICompatExecutor(internal/runtime/executor/openai_compat_executor.go) forwards the translated Chat Completions payload directly to the upstream without strippingreasoning_contentfor upstreams that reject extra fields.
Thanks for the detailed report.
ConvertOpenAIResponsesRequestToOpenAIChatCompletions injects reasoning_content (and the "[reasoning unavailable]" fallback on tool-call turns when reasoning is active in the session) because several OpenAI-compatible reasoning upstreams (such as DeepSeek and Moonshot/Kimi) require reasoning_content to be present on assistant messages carrying tool_calls.
For strict-schema OpenAI-compatible upstreams (such as api.mistral.ai) that forbid reasoning_content on messages[].assistant, you can strip the field at the final payload stage using request.payload.filter in config.yaml:
Option 1: Strip reasoning_content from all assistant messages for the model/provider
request:
payload:
filter:
- models:
- name: "deepseek-v4.1-flash" # matches alias, upstream model name, or wildcard (e.g. "*")
protocol: "openai"
params:
- 'messages.#(role=="assistant")#.reasoning_content'
Option 2: Strip only the synthetic [reasoning unavailable] placeholder
request:
payload:
filter:
- models:
- name: "deepseek-v4.1-flash"
protocol: "openai"
params:
- 'messages.#(reasoning_content=="[reasoning unavailable]")#.reasoning_content'
(Note: Use the #(...)# query syntax shown above so the payload filter expands and removes the field across all matching entries in messages[].)
Closing this issue as resolved via configuration. Feel free to reopen if you run into any issues with the filter rule above.