Skip to content
Skip to article
Docs Chat Completions
View as Markdown

Chat Completions (OpenAI format)

POST /r/{router_slug}/v1/chat/completions

Send a JSON messages array. A user message with text is enough to exercise the routing chain. The examples use the router URL and key from the API reference.

curl "$DODO_ROUTER_URL/v1/chat/completions" \
  -H "Authorization: Bearer $DODO_ROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "default",
    "messages": [{"role": "user", "content": "Reply with pong."}]
  }'

For a text answer, read choices[0].message.content. For a tool call, inspect choices[0].message.tool_calls and send the tool result in the next request using the matching tool_call_id. Model support for tools and other options depends on the provider that serves the request.

A completed text response includes fields like these. Token counts and model names vary.

{
  "choices": [{"index": 0, "message": {"role": "assistant", "content": "pong"}, "finish_reason": "stop"}],
  "model": "gpt-5.5",
  "usage": {"prompt_tokens": 13, "completion_tokens": 5, "total_tokens": 18}
}

With the OpenAI SDK, use $DODO_ROUTER_URL/v1 as the base URL and call chat.completions.create. For retries of a non-streaming request, reuse its idempotency key. Python and Node.js examples · Retry behavior.

Audio input and output

Choose an OpenAI Chat Completions audio model such as gpt-audio-1.5 on the routing step. This Python example sends a WAV file and saves the spoken answer. Install the openai package and set the router URL and key as shown in the API reference.

import base64
import os
from pathlib import Path
from openai import OpenAI

client = OpenAI(base_url=os.environ["DODO_ROUTER_URL"].rstrip("/") + "/v1",
                api_key=os.environ["DODO_ROUTER_API_KEY"])
clip = base64.b64encode(Path("input.wav").read_bytes()).decode("ascii")
result = client.chat.completions.create(
    model="default", modalities=["text", "audio"],
    audio={"voice": "alloy", "format": "wav"},
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "Answer the question in this clip."},
        {"type": "input_audio", "input_audio": {"format": "wav", "data": clip}},
    ]}],
)
audio = result.choices[0].message.audio
Path("reply.wav").write_bytes(base64.b64decode(audio.data))
print(audio.transcript)

For a text answer to an audio question, omit audio and modalities. To continue an audio conversation, send the returned audio.id on an assistant message while the provider reference is valid. For streaming audio output, request pcm16, decode each choices[0].delta.audio.data chunk separately, and append the resulting bytes in order. A partially delivered audio stream ends if the provider disconnects. GPT-Realtime-2.1 uses a separate WebSocket endpoint. Realtime audio · OpenAI audio guide.

Audio requests skip routing steps whose wire format cannot carry the request or whose catalog entry explicitly excludes the requested audio direction. A custom model with unknown capabilities can still receive the request.

Streaming

Set stream to true. The -N switch lets cURL print SSE data as it arrives.

curl -N "$DODO_ROUTER_URL/v1/chat/completions" \
  -H "Authorization: Bearer $DODO_ROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"default","stream":true,"messages":[{"role":"user","content":"Reply with pong."}]}'

Read successive data: entries. Append text from choices[0].delta.content and accumulate any tool-call argument fragments. The terminal marker is data: [DONE]. A failure before output can return an HTTP error with a JSON body. If all remaining attempts fail after the stream opens, a data: entry carries an error object before [DONE]. A client should check for that object before treating the stream as successful.