Skip to content
Skip to article
Docs Overview & Auth
View as Markdown

API reference

Base URL & authentication

Set the router root and an active router API key in your shell. Replace my-agent with the slug on your router page. For self-hosting, use your instance's host. In Bash or Zsh, run the second command, paste the key, and press Enter.

export DODO_ROUTER_URL="https://api.dodorouter.com/r/my-agent"
read -rs DODO_ROUTER_API_KEY && export DODO_ROUTER_API_KEY

Send the router key as Authorization: Bearer … or x-api-key: …. The key must belong to the router named in the URL. Configure the upstream provider credential on the routing step. Create a router and provider key.

Client SDK base URL Path appended by the SDK
OpenAI Chat Completions $DODO_ROUTER_URL/v1 /chat/completions
OpenAI Responses $DODO_ROUTER_URL/v1 /responses
OpenAI Realtime WebSocket Router root with wss:// scheme /v1/realtime
Google Gen AI SDK (Gemini Live) $DODO_ROUTER_URL, API version v1beta /ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent
Anthropic Messages $DODO_ROUTER_URL /v1/messages

The dashboard's Connect your app panel supplies the complete URL for your client and router. Run a Python or Node.js example.

Verify your connection with the models list

curl -i "$DODO_ROUTER_URL/v1/models" \
  -H "Authorization: Bearer $DODO_ROUTER_API_KEY"

A 200 verifies the URL, router key and billing access without calling a provider. The OpenAI-compatible list contains one entry. Its id is the router slug and created is the router creation time in Unix seconds. To check the routing chain itself, send a generation request. Chat Completions example.

{"object":"list","data":[{"id":"my-agent","object":"model","created":1775808000,"owned_by":"dodo"}]}

Endpoints

Append these paths to DODO_ROUTER_URL. Each uses the router API key.

Method Path Use
POST /v1/chat/completions Send a conversation in OpenAI format. Chat Completions
POST /v1/messages Send Anthropic messages and content blocks. Messages
POST /v1/messages/count_tokens Size an Anthropic prompt. Count input tokens
POST /v1/responses Send text or typed input items. Responses
GET (WebSocket upgrade) /v1/realtime Exchange live audio with an OpenAI Realtime model. Realtime audio
GET (WebSocket upgrade) /ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent Stream speech with the Google Gen AI SDK. Gemini Live audio
GET /v1/models List this router's model entry.
POST /recordings/start Start a capture window. Recordings API
GET /recordings/active Read the active capture window.
POST /recordings/active/stop Finish the active capture window.

At the host root, POST /v1/chat/completions is the legacy Chat Completions route. Its router key identifies the router. Two unauthenticated host routes are available for operations. GET /health returns {"status":"ok"} or HTTP 503 when the database is unavailable or the instance is draining. GET /api/version returns the running version.

The model field is ignored

Your routing chain selects the provider and model to try. Use "model":"default" where the SDK requires a model name. To change which model serves calls, edit the routing step. Read model on a completed generation response to see which model answered. Routing steps and fallback.

Track usage by application user

To attribute a Chat Completions, Messages or Responses request, set X-Dodo-User-Id in trusted application code. Use one header containing a stable customer ID or random UUID. After trimming, the ID must be valid UTF-8, nonempty, at most 255 bytes and free of control characters. Invalid values return HTTP 400 before dispatch.

X-Dodo-User-Id: customer-42
X-Session-Id: conversation-18
X-Session-Name: Support ticket 104

DodoRouter records the user ID locally and removes its header before forwarding. The optional session headers group related calls in Logs. If you configure a custom session header such as x-thread-id, its name header becomes x-thread-id-name. Both attribution and sessions work on streaming requests. Sessions.

Open the trace for a request

Use curl -i to include response headers. On a logged request, copy x-request-id and open /logs/{request_id}?tab=trace on the dashboard host while signed in. The trace shows the sequence of attempts, including a fallback that recovered from an earlier failure. It becomes available once the request log is stored. A connected agent can pass the same ID to get_log. Agent access.

Successful non-streaming generation calls return x-timing-total-ms and x-timing-provider-ms. Chat Completions also returns x-timing-overhead-ms.

Idempotency

For a non-streaming generation request, choose one Idempotency-Key per logical operation. Keep the same key, endpoint and payload when retrying. The example uses a batch row ID so rerunning the command can recover its previous answer.

curl -i "$DODO_ROUTER_URL/v1/chat/completions" \
  -H "Authorization: Bearer $DODO_ROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: example-batch-row-42" \
  -d '{"model":"default","messages":[{"role":"user","content":"Reply with pong."}]}'
Result How to handle it
200 with Idempotent-Replayed: true Use the stored answer. The replay has its own zero-cost, zero-token log entry linked to the original.
409 while the original is running Wait for the first call to finish, then retry with the same key. OpenAI-format responses use error.code: idempotency_in_progress.
409 because the normalized request changed Use a fresh key for a different operation. OpenAI-format responses use error.code: idempotency_key_reused. Messages returns error.type: idempotency_error with an explanation for either conflict.
400 when stream is true Use a non-streaming request for stored-response replay, or remove the header to stream.

Keys belong to a router and expire 24 hours after reservation. DodoRouter consumes the header locally. It can replay a successful answer only while the full response is available in storage. A failed generation releases its key. An expired key or a missing or truncated stored answer can cause a fresh provider call and charge.

Error format

Read the HTTP status and the JSON error.message. After streaming starts, also read the endpoint's error event. Provider limits and supported input types vary by routing step.

Status What to check
400 Inspect the message. Common causes include an empty routing chain, a final context-overflow error, invalid user attribution or a streaming request with an idempotency key.
401 Use an active router key for the slug in the URL. Missing, invalid, revoked and mismatched keys return Invalid API key.
402 Billing is enabled and the router owner needs an active subscription. Open Billing.
409 Check the idempotency key and whether its first request has completed.
502 The routing chain could not serve the request. Open the trace to inspect the last provider error and preceding attempts.

A stream with HTTP 200 can still end in a provider error. The Chat Completions and Messages endpoints can return an HTTP error before opening their streams. Responses opens its stream before dispatch on a configured router, so a provider failure can arrive as an SSE error before any output text. Troubleshooting.

Cache diagnostics

DodoRouter groups cache comparisons by router and session. It records keyed signatures of the final provider payload and any outbound prompt_cache_key, together with explicit retention options and cache breakpoints. Provider-supplied cache-read and cache-write tokens remain the usage measurements.

Signatures use a router-scoped HMAC derived from the deployment's secret_key_base. Secret rotation interrupts comparisons across the rotation. The signatures and diagnostic metadata follow log retention, including when stored bodies are removed. Diagnostics retain component byte sizes and bounded item signatures. Requests with more than 4,096 combined message, tool and system items omit the fingerprint. Read cache evidence through MCP.