Surplus API Output Specification
Surplus standardizes reasoning output, token accounting, and reasoning request translation across every text provider so a single client integration behaves consistently regardless of which seller serves the request. The contract follows OpenRouter's canonical output shape and is enforced identically on both the API service (ECS) and the edge routing plane (Cloudflare Worker).
Scope & Surfaces
| Surface | Path(s) | Output contract |
|---|---|---|
| Chat Completions | POST /v1/chat/completions, POST /min{N}/v1/chat/completions (non-streaming, long-running assembled, and SSE stream: true) | Canonical reasoning, permanent reasoning_content alias, structured reasoning_details, canonical usage.completion_tokens_details.reasoning_tokens, and local reasoning.exclude enforcement across every text provider. |
| Responses API | POST /v1/responses, POST /min{N}/v1/responses | Native OpenAI Responses format: reasoning items inside output[] and usage.output_tokens_details.reasoning_tokens. reasoning.exclude is ignored on /v1/responses. |
| Anthropic Messages | POST /anthropic/v1/messages, POST /anthropic/min{N}/v1/messages | Native Anthropic Messages format: thinking and redacted_thinking content blocks. Inbound reasoning, reasoning_effort, and standalone output_config.effort (when thinking is absent) are relayed into canonical routing and translated per seller. The Chat Completions reasoning.exclude output stripper is not applied on this surface. |
| Media & Embeddings | /v1/images/*, /v1/audio/*, /v1/video/*, /v1/music/*, /v1/embeddings | Unchanged; no reasoning fields or reasoning usage normalization apply. |
POST /v1/chat/completions, POST /min{N}/v1/chat/completions (non-streaming, long-running assembled, and SSE stream: true)Output contract · Canonical reasoning, permanent reasoning_content alias, structured reasoning_details, canonical usage.completion_tokens_details.reasoning_tokens, and local reasoning.exclude enforcement across every text provider.POST /v1/responses, POST /min{N}/v1/responsesOutput contract · Native OpenAI Responses format: reasoning items inside output[] and usage.output_tokens_details.reasoning_tokens. reasoning.exclude is ignored on /v1/responses.POST /anthropic/v1/messages, POST /anthropic/min{N}/v1/messagesOutput contract · Native Anthropic Messages format: thinking and redacted_thinking content blocks. Inbound reasoning, reasoning_effort, and standalone output_config.effort (when thinking is absent) are relayed into canonical routing and translated per seller. The Chat Completions reasoning.exclude output stripper is not applied on this surface./v1/images/*, /v1/audio/*, /v1/video/*, /v1/music/*, /v1/embeddingsOutput contract · Unchanged; no reasoning fields or reasoning usage normalization apply.For per-model reasoning capability metadata, see Models. For request-side parameter adaptation details, see Reasoning Controls and Parameter Compatibility.
Chat Completions Output Contract (Non-Streaming & Assembled)
Every non-streaming and long-running assembled Chat Completions response normalizes each choices[i].message object to the same canonical reasoning fields:
| Field | Type | Contract |
|---|---|---|
choices[i].message.reasoning | string (optional) | Canonical readable reasoning text produced by the model. |
choices[i].message.reasoning_content | string (optional) | Permanent backward-compatible alias mirroring reasoning identically. |
choices[i].message.reasoning_details | array (optional) | Canonical structured array of OpenRouter-shaped reasoning objects for display and multi-turn replay. |
choices[i].message.reasoningType · string (optional)Contract · Canonical readable reasoning text produced by the model.choices[i].message.reasoning_contentType · string (optional)Contract · Permanent backward-compatible alias mirroring reasoning identically.choices[i].message.reasoning_detailsType · array (optional)Contract · Canonical structured array of OpenRouter-shaped reasoning objects for display and multi-turn replay.reasoning_details Entry Shapes
Each element in reasoning_details uses one of three discriminated shapes:
reasoning.text:{ "type": "reasoning.text", "text": "...", "format"?: "...", "index"?: 0, "signature"?: "..." }reasoning.summary:{ "type": "reasoning.summary", "summary": "...", "format"?: "...", "index"?: 0 }reasoning.encrypted:{ "type": "reasoning.encrypted", "data": "...", "id"?: "...", "format"?: "...", "index"?: 0 }
format and index are always present on entries synthesized by Surplus, and are optional on upstream pass-through entries and Anthropic redacted encrypted entries (redacted_thinking mapped to reasoning.encrypted).
Preservation, Scrubbing, and Omission Rules
- Signed & encrypted detail fidelity: Complete upstream signed
reasoning.textentries (carrying bothsignatureandtext) andreasoning.encryptedentries are preserved verbatim without mutating their signed fields. When an upstream provider emits only raw reasoning text (reasoningorreasoning_content), Surplus synthesizes areasoning.textentry inreasoning_details. - Encrypted blob scrubbing: Host-specific encrypted payload leaks — including
__ENCRYPTED_REASONING__sentinel blocks appended insidereasoning_content/reasoningand non-standardreasoning_encryptedmessage fields — are scrubbed out of readable text and the message root, and moved into a structuredreasoning.encryptedentry insidereasoning_details(without duplicating an existingreasoning.encryptedentry). - Clean omission when no reasoning was produced: When a model produces no reasoning — including non-reasoning models, models that emit no thought text (such as OpenAI o-series), or upstream responses carrying empty
reasoning: "",reasoning_content: "", orreasoning_details: []— all three fields (reasoning,reasoning_content, andreasoning_details) are omitted fromchoices[i].message.
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "claude-opus-4.6",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "42",
"reasoning": "Let me verify the arithmetic step by step...",
"reasoning_content": "Let me verify the arithmetic step by step...",
"reasoning_details": [
{
"type": "reasoning.text",
"text": "Let me verify the arithmetic step by step...",
"format": "anthropic-claude-v1",
"index": 0,
"signature": "EqoBCkgIARAA..."
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 180,
"total_tokens": 204,
"completion_tokens_details": {
"reasoning_tokens": 168
},
"buyer_cost_micro": 4120
}
}Chat Completions Streaming Contract (SSE)
On stream: true, every chat.completion.chunk frame applies the same contract to choices[i].delta:
delta.reasoninganddelta.reasoning_content: Mirror the readable reasoning text fragment for that chunk.delta.reasoning_details: Mirrors the structured reasoning fragments for that chunk. On Anthropic-wire streams wheresignature_deltaarrives as a separate signature-only fragment, Surplus stamps matchingformatandindex: 0so streaming clients merge the signature cleanly onto the activereasoning.textblock. Complete signedreasoning.textentries (signature+text) are preserved verbatim.- Encrypted payload scrubbing: Non-standard
delta.reasoning_encryptedis moved intodelta.reasoning_details(type: "reasoning.encrypted") and scrubbed from the delta root.__ENCRYPTED_REASONING__sentinel blocks (including multi-delta encrypted continuations) are scrubbed fromdelta.reasoninganddelta.reasoning_content. - Empty & excluded delta dropping: When normalization or
reasoning.exclude: trueleaves every choice'sdeltaempty on a chunk that carries nocontent,tool_calls,function_call,refusal,finish_reason, orusage, that empty SSE frame is dropped cleanly.
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning":"Step 1...","reasoning_content":"Step 1...","reasoning_details":[{"type":"reasoning.text","text":"Step 1...","format":"anthropic-claude-v1","index":0}]},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"42"},"finish_reason":null}]}Excluding Reasoning Output (reasoning.exclude: true / include_reasoning: false)
To let a model reason internally while hiding reasoning fields from the response, send "reasoning": { "exclude": true } (or legacy "include_reasoning": false):
- Model still reasons and is billed: Exclusion hides reasoning output from the buyer response; it does not turn reasoning off. Hidden reasoning tokens remain billed at the output rate and are reported in
usage.completion_tokens_details.reasoning_tokenswhen known (omitted when unreported upstream). - Stripped across all Chat delivery modes:
reasoning,reasoning_content,reasoning_details(and anyreasoning_encrypted) are stripped from non-streaming, long-running assembled, and SSE streaming Chat Completions responses, and excluded reasoning-only SSE deltas are dropped. - Precedence: An explicit boolean
reasoning.excludetakes precedence over legacyinclude_reasoning. For example, sending"reasoning": { "exclude": false }together with"include_reasoning": falsekeeps reasoning output visible. - Surface scope: Exclusion applies to Chat Completions only.
reasoning.excludeis ignored on/v1/responses. On Anthropic-wire sellers routed from Chat Completions,reasoning.exclude: truealso setsthinking.display: "omitted".
Canonical usage Object & Token Accounting
All Chat Completions responses (non-streaming, assembled, and final SSE usage chunks requested via stream_options: { "include_usage": true }) obey a single token-accounting contract:
-
Single canonical reasoning token count:
usage.completion_tokens_details.reasoning_tokensis the only reasoning token field emitted on Chat Completions. -
Alias canonicalization & cleanup: Non-canonical upstream reasoning-token fields are moved into
usage.completion_tokens_details.reasoning_tokensand their alias leaves are removed from the buyer-visible response:usage.completionTokensDetails.reasoningTokensusage.output_tokens_details.reasoning_tokens- top-level
usage.reasoning_tokens - top-level
usage.thoughts_token_count
Unrelated sibling keys inside
completionTokensDetailsoroutput_tokens_detailsare preserved; empty containers are deleted once the alias leaf is removed. -
Inclusion invariant:
usage.completion_tokensalways includesreasoning_tokenson buyer-visible responses — including Google Vertex and any upstream host (such as Venice GPT routes) that reports reasoning tokens separately fromcompletion_tokens— andusage.total_tokens = usage.prompt_tokens + usage.completion_tokens. -
Omit, never invent: When an upstream provider does not report a reasoning token count (for example Anthropic direct, AWS Bedrock, Snowflake, or Google AI Studio when absent),
usage.completion_tokens_details.reasoning_tokensis omitted rather than estimated or zero-filled. -
max_tokensreasoning-budget warning: On reasoning models,max_tokenscaps total completion tokens including hidden reasoning tokens. Setting a very smallmax_tokenscan exhaust the entire budget on reasoning, returning emptycontentwithfinish_reason: "length". -
Billing &
buyer_cost_micro:usage.buyer_cost_microcontinues to reflect the exact settled charge in integer microdollars when the request has a known priced charge (and is omitted when the charge is unknown). Output normalization never alters settlement or billing.
Unified Reasoning Request Contract & Cross-Provider Translation
Buyers can send any of three reasoning controls on /v1/chat/completions, and Surplus translates them automatically to the serving provider's native dialect:
- Unified object (recommended):
"reasoning": { "effort"?, "max_tokens"?, "enabled"?, "exclude"? }(or"reasoning": falseto disable). - Flat effort string:
"reasoning_effort": "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max". - Legacy boolean:
"include_reasoning": true | false. When a nativereasoningobject is absent,include_reasoning: truemaps toreasoning: { "enabled": true }andinclude_reasoning: falsemaps toreasoning: { "exclude": true }. Explicitreasoning.excludealways takes precedence overinclude_reasoningon Chat output.
Provider-Wire Translation
- Nested-capable chat hosts (
openrouter,venice,mordiem,concentrate,softforge,pearl): Flatreasoning_effortmoves intoreasoning.effort(after host-specific effort-mapping rules). OpenRouter receivesreasoning.excludedirectly; non-OpenRouter nested hosts strip unsupportedreasoning.excludeupstream while Surplus enforces exclusion locally on the response. - Flat-only chat hosts (OpenAI, DeepSeek, Google, Mistral, DashScope, Uncensored, Groq, Fireworks, Together, and all other flat chat hosts): Unified
reasoningobjects (andreasoning: false) project to flatreasoning_effort(enabled: false/reasoning: false→"none",enabled: true→"medium",max_tokens→ nearest effort bucket) and remove the unsupported nestedreasoningkey. Models whose catalogsupported_parameterslistsreasoningretainreasoning_effort. - Anthropic Messages wire (Anthropic direct, Bedrock Mantle Claude, Snowflake Cortex, Vertex Anthropic, and Anthropic-wire lanes): Translates
reasoning,reasoning_effort, standaloneoutput_config.effort, orinclude_reasoning: trueinto Anthropicthinkingusing OpenRouter's exact effort-to-budget ratio formula:
| Effort | Ratio of max_tokens |
|---|---|
max | 0.95 |
xhigh | 0.95 |
high | 0.80 |
medium (also default for enabled: true / include_reasoning: true) | 0.50 |
low | 0.20 |
minimal | 0.10 |
maxRatio of max_tokens · 0.95xhighRatio of max_tokens · 0.95highRatio of max_tokens · 0.80medium (also default for enabled: true / include_reasoning: true)Ratio of max_tokens · 0.50lowRatio of max_tokens · 0.20minimalRatio of max_tokens · 0.10The raw budget (floor(max_tokens * ratio), or floor(reasoning.max_tokens) when explicitly supplied) is clamped to [1,024, 128,000] and strictly < max_tokens (min(raw, max_tokens - 1)). When max_tokens <= 1,024, no thinking block is emitted because Anthropic's minimum thinking budget is 1,024 (disclosed in X-SI-Adapted-Params without inflating max_tokens). Sampling parameters (temperature, top_p, top_k) are suppressed when thinking is enabled (disclosed as thinking_sampling_suppressed if sent). Adaptive-only models (claude-opus-4.7, claude-opus-4.8, and Claude 5.x) automatically translate to adaptive thinking (thinking: { "type": "adaptive" } + output_config.effort).
Invalid Native Thinking Budget (400 invalid_reasoning_budget)
If a request on /v1/chat/completions or /anthropic/v1/messages explicitly sends native Anthropic thinking: { "type": "enabled", "budget_tokens": N } with budget_tokens >= max_tokens (or max_completion_tokens on Chat Completions), Surplus fails fast at intake with HTTP 400 instead of silently stripping thinking:
- On
/v1/chat/completions: OpenAI error envelope witherror.code: "invalid_reasoning_budget"anderror.param: "thinking.budget_tokens". - On
/anthropic/v1/messages: Anthropic's native error envelope (type: "error",error.type: "invalid_request_error").
By contrast, unified reasoning.max_tokens is never rejected at intake: on Anthropic-wire sellers it is clamped safely below max_tokens when max_tokens > 1,024 (with X-SI-Adapted-Params: reasoning), or emits no thinking block when max_tokens <= 1,024.
Provider & Model Caveats
Surplus standardizes wire shape and token accounting without fabricating data an upstream provider never returned:
- Models that emit no thought text: OpenAI o-series (and some reasoning models) reason internally without returning readable reasoning text.
reasoning,reasoning_content, andreasoning_detailsstay absent;usage.completion_tokens_details.reasoning_tokensis still reported when known. - Providers that do not report
reasoning_tokens: Anthropic direct, AWS Bedrock, Snowflake, and Google AI Studio (OpenAI-compatible wire) do not emit a separate reasoning token count. Surplus omitsusage.completion_tokens_details.reasoning_tokensrather than estimating or zero-filling it. - Gemini thought summaries &
gemini-4-*dialects: Gemini reasoning models return summarized thought blocks rather than raw internal chain-of-thought. For effort-onlygemini-4-*models, budget dialects (thinking.budget_tokens,reasoning.max_tokens, andextra_body.google.thinking_config.thinking_budget) are automatically translated toreasoning_effort/reasoning.effort. - Cross-provider replay signature stripping: Signed reasoning replay carriers (
signature,reasoning_details, andreasoning_contenton assistant history turns) are stripped automatically when replaying conversation history to hosts that reject foreign reasoning replay fields (such as Fireworks and strict chat hosts), while preserved intact on native providers. - Per-model upstream quirks handled automatically:
glimpsemapshighandmax→xhigh, andminimal→low(OpenRouter rejects"high"with HTTP 400).claude-opus-4.7andclaude-opus-4.8translate to adaptive thinking (thinking: { "type": "adaptive" }+output_config.effort).- Claude 5.5 on Vertex requests summarized display (
display: "summarized") where supported so Vertex returns readable thinking summaries rather than signature-only blocks (otherwise Vertex may emit signature-only thinking).
- Capability discovery: Per-model reasoning capabilities (
mandatory,default_enabled,supported_efforts,default_effort,supports_max_tokens) are published dynamically underreasoningonGET /v1/models. See Models.
See Also
- Reasoning Controls for request parameters, adaptation rules, and billing.
- Models for the
GET /v1/modelsreasoningcapability object. - Chat Completions, Responses, and Messages for endpoint contracts.
- Long-Running Responses for assembled non-streaming response framing.