Chat & Completions
The three wire formats that reach `codai`: OpenAI Chat Completions, Anthropic Messages, OpenAI Responses.
All three endpoints route to the same model chain and share auth, rate limits, prompt caching and usage recording. Pick the one your SDK already speaks — the wire formats guide explains the differences and the headers guide covers every x-codai-* extension you see below.
Authorization
bearerAuth A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by /v1/realtime.
In: header
Header Parameters
Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128Groups requests of one conversation for receipts, stickiness and prompt caching.
length <= 128Test-time-compute effort tier. Wins over the reasoning_effort body field. max is a codai extension above OpenAI's high; none is accepted as an alias of minimal.
Value in
- "minimal"
- "low"
- "medium"
- "high"
- "max"
1/true enables extended thinking on models that support it (budget from x-codai-thinking-budget, default 16384 tokens).
Positive integer thinking-token budget used when x-codai-thinking is on. Also marks the request as caller-tuned so the effort planner does not override it.
1 keeps the full thinking budget on tool-continuation turns instead of the dampened budget the gateway applies by default.
0/false disables prompt caching for a DIRECT model id. Ignored (caching forced ON) for the codai / codai-* router aliases.
1/true opts this request out of task counting. Only valid on utility aliases; on codai the request is rejected with 400.
Client-chosen task correlation id. Requests sharing it are attributed to one task; echoed back as the x-codai-task-id response header when known within 150 ms.
pass or fail — self-reported outcome that closes the attached task. Honoured only for desktop/CLI surfaces (x-codai-client) and only together with a machine x-codai-task-evidence.
Value in
- "pass"
- "fail"
Evidence kind backing x-codai-task-outcome; only exec_verdict and reexec close a task.
Value in
- "exec_verdict"
- "reexec"
Explicit client surface tag used for task attribution (desktop/<ver>, phone-android/<ver>, codai-cli/<ver>, hub/<ver>). Anything else is classified as proxy.
1 makes the turn fully stateless: no memory read, nothing persisted, no sticky routing.
1 skips reading prior memory but still persists this turn.
1 restricts memory recall to entries promoted to proven.
1 rotates to a fresh server-minted session namespace for this request, ignoring x-codai-session-id.
Repository scope hint (e.g. owner/name) used to select the session playbook; most IDE proxies cannot send it, so the gateway also infers scope from the transcript.
Caller-supplied agent identifier persisted with the usage event for per-agent analytics.
1 forbids delegate_to_model sub-agent fan-out and forces the native streaming path.
agent requests agent mode (server-side agent prompt + server tools). 403 when the key/plan is not entitled.
Value in
- "agent"
1/true enables gateway-side tools without full agent mode (agent mode implies it).
1/true opts into multi-model orchestration (fan-out to sub-tasks). Requires at least two models in the key allowlist.
verify opts into the FrugalGPT cascade (cheap draft, frontier verify). Result reported in x-codai-cascade-status.
Best-of-N sampling count (e.g. 3); 0/off explicitly disables the automatic best-of. Result in x-codai-best-of-status.
Judge depth for best-of-N.
Opt-in/out of the self-verification reflect pass (1/0). Result in x-codai-reflect-status.
Opt-in/out of step-level process verification (1/0). Result in x-codai-step-verify-status.
Opt-in/out of the long-horizon plan check (1/0). Result in x-codai-plan-status.
1 runs iterative consensus across all tiers (non-stream, router alias only). Result in x-codai-consensus-status.
Opt-in server-side transcript compaction (1). Savings reported in x-codai-compacted / x-codai-compact-saved-chars.
1/on enables relevance retrieval over the transcript before dispatch (x-codai-retrieval-reduced).
Opt-in/out of the learned-heuristics prompt injection (1/0).
Identity-preamble mode override (on / off / shadow).
Per-request playbook mode override; x-codai-no-playbook: 1 is the hard kill-switch.
1 disables session playbook injection for this request.
1 adds the full router decision trace as extra x-codai-router-* response headers.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
OpenAI Chat Completions body. Unknown fields are accepted (passthrough) and forwarded to OpenAI-compatible upstreams; Anthropic upstreams ignore them.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/chat/completions" \ -H "Content-Type: application/json" \ -d '{ "messages": [ { "role": "system" } ] }'{ "id": "chatcmpl_9f1c2b7e4d", "object": "chat.completion", "created": 1790108310, "model": "claude-sonnet-5", "choices": [ { "index": 0, "message": { "role": "system", "content": "string", "name": "string", "tool_call_id": "string", "tool_calls": [ { "id": "toolu_01Xy9k3mQ", "type": "function", "function": { "name": "string", "arguments": "{\"path\":\"src/index.ts\"}" } } ] }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0, "prompt_tokens_details": { "cached_tokens": 0 }, "cache_creation_input_tokens": 0 }}Authorization
bearerAuth A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by /v1/realtime.
In: header
Header Parameters
Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128Groups requests of one conversation for receipts, stickiness and prompt caching.
length <= 128Anthropic-style API key header. Alternative to Authorization: Bearer; ignored when a Bearer header
is present.
Test-time-compute effort tier. Wins over the body reasoning_effort. none is normalised to
minimal; unknown values are ignored.
Value in
- "minimal"
- "low"
- "medium"
- "high"
- "max"
Enable extended thinking upstream (1 or true). Default budget 16384 tokens.
Value in
- "1"
- "true"
- "0"
- "false"
Thinking budget in tokens (positive integer). On adaptive-thinking models it is mapped to an effort level. Setting it also tells the compute allocator not to inject its own budget.
Prompt-caching opt-out (0 / false). Only honoured on direct model calls — caching is forced ON
for the codai router alias.
Value in
- "0"
- "false"
- "1"
- "true"
Force (1) or suppress (0) server-side conversation compaction for this request.
Value in
- "0"
- "1"
1 disables sub-agent delegation for this request. Combined with stream: true and no tools this
unlocks the native pass-through streaming path on sub-agent-capable tiers.
Value in
- "1"
1 opts out of task counting. Only honoured for eligible utility aliases; on a full model the request
is rejected with 400.
Value in
- "1"
Best-of-N sampling on the buffered path (tier-gated; ignored when not entitled).
Sub-agent depth at which best-of applies on the buffered path.
Free-form client identifier recorded on the task opened for this turn.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Public Anthropic Messages request. Unknown top-level fields pass validation and are ignored unless listed here as a codai extension.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "Content-Type: application/json" \ -d '{ "model": "codai", "messages": [ { "role": "user", "content": "string" } ], "max_tokens": 4096 }'{ "id": "msg_1f0d5b7a-4c2e-4a9b-9c1d-2e3f4a5b6c7d", "type": "message", "role": "assistant", "model": "codai", "content": [ { "type": "text", "text": "string" } ], "stop_reason": "end_turn", "stop_sequence": "string", "usage": { "input_tokens": 0, "output_tokens": 0, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0 }}Authorization
bearerAuth A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by /v1/realtime.
In: header
Header Parameters
Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128Groups requests of one conversation for receipts, stickiness and prompt caching.
length <= 128Effort tier; when present it wins and reasoning.effort from the body is not mapped.
Value in
- "minimal"
- "low"
- "medium"
- "high"
- "max"
0/false disables prompt caching for a direct model id (ignored for the codai alias). Forwarded to the inner chat-completions call.
Forwarded to the inner call; only valid on utility aliases (400 on codai).
Forwarded to the inner call — stateless turn, nothing persisted.
Forwarded to the inner call — client surface tag for task attribution.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/responses" \ -H "Content-Type: application/json" \ -d '{}'{ "id": "resp_chatcmpl_9f1c2b7e4d", "object": "response", "created_at": 0, "status": "completed", "model": "string", "output": [ { "type": "function_call", "id": "fc_toolu_01Xy9k3mQ", "call_id": "string", "name": "string", "arguments": "string", "status": "completed" } ], "output_text": "string", "usage": { "input_tokens": 0, "input_tokens_details": { "cached_tokens": 0 }, "output_tokens": 0, "total_tokens": 0 }}