Skip to content

cURL

Inspect Router requests and responses directly from a terminal.

cURL is the quickest way to validate your base URL, API key, model choice, and raw response shape before adding an SDK.

Configure the environment

bash
export ROUTER_BASE_URL="https://api-router.optimai.network/v1"export ROUTER_API_KEY="YOUR_ROUTER_API_KEY"

Copy the current base URL from Developer API. Keep the API key out of shell history when working on a shared computer.

List model editions

bash
curl --fail-with-body --silent --show-error \  "$ROUTER_BASE_URL/models" \  -H "Authorization: Bearer $ROUTER_API_KEY" \  | jq

Choose an id with enough ready_providers for your immediate test, then respect its context_length, max_output_tokens, and max_prompt_bytes.

Create a completion

bash
curl --fail-with-body --silent --show-error \  "$ROUTER_BASE_URL/chat/completions" \  -H "Authorization: Bearer $ROUTER_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "model": "gemma3:1b",    "messages": [      { "role": "user", "content": "Explain edge inference in one sentence." }    ],    "max_tokens": 100,    "temperature": 0.3  }' \  | jq -r '.choices[0].message.content'

Inspect headers and errors

Add --include to see the status, X-Request-Id, and Retry-After headers. Remove --fail-with-body temporarily if you want to inspect a non-2xx JSON error while debugging.

bash
curl --include --silent \  "$ROUTER_BASE_URL/chat/completions" \  -H "Authorization: Bearer $ROUTER_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model":"unknown","messages":[{"role":"user","content":"Hello"}]}'

Stream events

Use --no-buffer so cURL prints server-sent events as they arrive.

bash
curl --no-buffer --silent --show-error \  "$ROUTER_BASE_URL/chat/completions" \  -H "Authorization: Bearer $ROUTER_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "model": "gemma3:1b",    "messages": [{ "role": "user", "content": "Write a short welcome." }],    "stream": true  }'

Each payload begins with data:. The terminal success marker is data: [DONE].

Continue with the models endpoint or chat-completions reference.