codai docs
API referenceGateway

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.

POST
/v1/chat/completions

Authorization

bearerAuth
AuthorizationBearer <token>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by /v1/realtime.

In: header

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128
x-codai-session-id?string

Groups requests of one conversation for receipts, stickiness and prompt caching.

Lengthlength <= 128
x-codai-effort?string

Test-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"
x-codai-thinking?string

1/true enables extended thinking on models that support it (budget from x-codai-thinking-budget, default 16384 tokens).

x-codai-thinking-budget?string

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.

x-codai-thinking-pin?string

1 keeps the full thinking budget on tool-continuation turns instead of the dampened budget the gateway applies by default.

x-codai-cache?string

0/false disables prompt caching for a DIRECT model id. Ignored (caching forced ON) for the codai / codai-* router aliases.

x-codai-no-task?string

1/true opts this request out of task counting. Only valid on utility aliases; on codai the request is rejected with 400.

x-codai-task-id?string

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.

x-codai-task-outcome?string

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"
x-codai-task-evidence?string

Evidence kind backing x-codai-task-outcome; only exec_verdict and reexec close a task.

Value in

  • "exec_verdict"
  • "reexec"
x-codai-client?string

Explicit client surface tag used for task attribution (desktop/<ver>, phone-android/<ver>, codai-cli/<ver>, hub/<ver>). Anything else is classified as proxy.

x-codai-incognito?string

1 makes the turn fully stateless: no memory read, nothing persisted, no sticky routing.

x-codai-no-recall?string

1 skips reading prior memory but still persists this turn.

x-codai-proven-only?string

1 restricts memory recall to entries promoted to proven.

x-codai-new-session?string

1 rotates to a fresh server-minted session namespace for this request, ignoring x-codai-session-id.

x-codai-repo?string

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.

x-codai-agent-id?string

Caller-supplied agent identifier persisted with the usage event for per-agent analytics.

x-codai-disable-subagents?string

1 forbids delegate_to_model sub-agent fan-out and forces the native streaming path.

x-codai-mode?"agent"

agent requests agent mode (server-side agent prompt + server tools). 403 when the key/plan is not entitled.

Value in

  • "agent"
x-codai-server-tools?string

1/true enables gateway-side tools without full agent mode (agent mode implies it).

x-codai-orchestrate?string

1/true opts into multi-model orchestration (fan-out to sub-tasks). Requires at least two models in the key allowlist.

x-codai-cascade?string

verify opts into the FrugalGPT cascade (cheap draft, frontier verify). Result reported in x-codai-cascade-status.

x-codai-best-of?string

Best-of-N sampling count (e.g. 3); 0/off explicitly disables the automatic best-of. Result in x-codai-best-of-status.

x-codai-best-of-depth?string

Judge depth for best-of-N.

x-codai-reflect?string

Opt-in/out of the self-verification reflect pass (1/0). Result in x-codai-reflect-status.

x-codai-step-verify?string

Opt-in/out of step-level process verification (1/0). Result in x-codai-step-verify-status.

x-codai-plan?string

Opt-in/out of the long-horizon plan check (1/0). Result in x-codai-plan-status.

x-codai-consensus?string

1 runs iterative consensus across all tiers (non-stream, router alias only). Result in x-codai-consensus-status.

x-codai-compact?string

Opt-in server-side transcript compaction (1). Savings reported in x-codai-compacted / x-codai-compact-saved-chars.

x-codai-retrieval?string

1/on enables relevance retrieval over the transcript before dispatch (x-codai-retrieval-reduced).

x-codai-heuristics?string

Opt-in/out of the learned-heuristics prompt injection (1/0).

x-codai-identity?string

Identity-preamble mode override (on / off / shadow).

x-codai-playbook?string

Per-request playbook mode override; x-codai-no-playbook: 1 is the hard kill-switch.

x-codai-no-playbook?string

1 disables session playbook injection for this request.

x-codai-debug?string

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  }}
POST
/v1/messages

Authorization

bearerAuth
AuthorizationBearer <token>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by /v1/realtime.

In: header

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128
x-codai-session-id?string

Groups requests of one conversation for receipts, stickiness and prompt caching.

Lengthlength <= 128
x-api-key?string

Anthropic-style API key header. Alternative to Authorization: Bearer; ignored when a Bearer header is present.

x-codai-effort?string

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"
x-codai-thinking?string

Enable extended thinking upstream (1 or true). Default budget 16384 tokens.

Value in

  • "1"
  • "true"
  • "0"
  • "false"
x-codai-thinking-budget?string

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.

x-codai-cache?string

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"
x-codai-compact?string

Force (1) or suppress (0) server-side conversation compaction for this request.

Value in

  • "0"
  • "1"
x-codai-disable-subagents?"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"
x-codai-no-task?"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"
x-codai-best-of?string

Best-of-N sampling on the buffered path (tier-gated; ignored when not entitled).

x-codai-best-of-depth?string

Sub-agent depth at which best-of applies on the buffered path.

x-codai-client?string

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  }}
POST
/v1/responses

Authorization

bearerAuth
AuthorizationBearer <token>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by /v1/realtime.

In: header

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128
x-codai-session-id?string

Groups requests of one conversation for receipts, stickiness and prompt caching.

Lengthlength <= 128
x-codai-effort?string

Effort tier; when present it wins and reasoning.effort from the body is not mapped.

Value in

  • "minimal"
  • "low"
  • "medium"
  • "high"
  • "max"
x-codai-cache?string

0/false disables prompt caching for a direct model id (ignored for the codai alias). Forwarded to the inner chat-completions call.

x-codai-no-task?string

Forwarded to the inner call; only valid on utility aliases (400 on codai).

x-codai-incognito?string

Forwarded to the inner call — stateless turn, nothing persisted.

x-codai-client?string

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  }}