Skip to content

Make your first request

Create an API key, choose a model, and connect your application in a few clear steps.

Create an API key

Open API keys in Router and create a key for your application. Copy the secret when it appears and store it securely; it is only shown once. Explicitly enable paid requests for this key before sending inference. Existing keys stay disabled until you opt them in.

Keep the key on your server. Never put it in browser code, a public repository, or a shared screenshot.

Choose your model

Open the model catalog and choose a supported API edition. Check its enforced limits and current availability. A listed model does not guarantee eligible provider capacity.

The examples below use gemma3:1b. Replace it with the exact edition you intend to use. Auto routing is the default; Router selects the lowest eligible conservative credit reservation and rotates equal rounded reservations. To choose one public computer/model offer, follow choosing a provider.

Set your environment

Copy the base URL from Developer API. It must end in /v1.

bash
export ROUTER_BASE_URL="https://api-router.optimai.network/v1"read -rsp "Router API key: " ROUTER_API_KEYexport ROUTER_API_KEYecho

The silent prompt keeps the secret out of the command itself. You can instead load it from your server’s secret manager.

For an SDK example, install openai with pip install openai (Python) or pnpm add openai (TypeScript). Run these examples on your server or in a terminal.

Send a request

Start with a short text message. This example waits for the full response. Each request needs a caller-generated UUID in Idempotency-Key and a maximum charge in X-Max-Charge-Credits (5 credits by default; you may choose less). Router reserves up to that maximum and charges from the provider's saved USD rates and accepted provider-reported token usage; those counts are not independently verified. A 100-credit Router monthly cap also applies to the account.

Illustration
Exploded diagram of one chat completion request: three header cards lift away from the request packet, and the JSON body rises above it.POST /chat/completions{"model": "gemma3:1b","messages": [{"role": "user","content": "Hello!"}]}X-Max-Charge-Credits5.000000Idempotency-Key$REQUEST_ID (UUID)AuthorizationBearer $ROUTER_API_KEY
Illustration of the parts of a request. Values are placeholders, not real credentials.
Request
ROUTER_REQUEST_ID="$(uuidgen)" # Reuse this ID if you retry the same request.curl "$ROUTER_BASE_URL/chat/completions" \  -H "Authorization: Bearer $ROUTER_API_KEY" \  -H "Idempotency-Key: $ROUTER_REQUEST_ID" \  -H "X-Max-Charge-Credits: 5.000000" \  -H "Content-Type: application/json" \  -d '{    "model": "gemma3:1b",    "messages": [      { "role": "user", "content": "Hello!" }    ]  }'

Read the response

A successful request returns the model’s message in choices[0].message.content. The values below are illustrative.

json
{  "model": "gemma3:1b",  "choices": [{    "index": 0,    "message": { "role": "assistant", "content": "Hello!" },    "finish_reason": "stop"  }]}

Save the request UUID. If the response is lost or interrupted, read its owner-scoped credit receipt at GET /v1/credits/requests/{request_id} before deciding whether to retry. Retrying the same logical request must reuse the UUID and body.

Keep building

Learn how to stream a response, or explore the full chat completions reference.