Authentication
All gateway endpoints accept your API key as a Bearer token in the Authorization header. Create keys in the dashboard; keys are scoped to a workspace and can carry guardrails.
Authorization: Bearer sk-lkr-your-keyEvery LokaRouter gateway endpoint — OpenAI-compatible request and response shapes.
All gateway endpoints accept your API key as a Bearer token in the Authorization header. Create keys in the dashboard; keys are scoped to a workspace and can carry guardrails.
Authorization: Bearer sk-lkr-your-keyPOST /v1/chat/completions with any OpenAI-compatible payload. Unknown fields (temperature, tools, response_format, …) are forwarded to the upstream provider untouched. Set "stream": true for server-sent events.
curl https://api.lokarouter.id/v1/chat/completions \ -H "Authorization: Bearer sk-lkr-your-key" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-5-mini", "messages": [{ "role": "user", "content": "Hello" }], "stream": false }'Response
{ "id": "lkr_…", "object": "chat.completion", "model": "openai/gpt-5-mini", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "Hi!" }, "finish_reason": "stop" }], "usage": { "prompt_tokens": 9, "completion_tokens": 2, "total_tokens": 11 }}Every response carries x-request-id (per-request lookup) and x-lokarouter-latency-ms (end-to-end gateway latency).
Set "model": "lokarouter/auto" and the gateway classifies your request heuristically (code, translation, long context, reasoning, latency-sensitive) and routes it to the best catalog model. Costs nothing extra and adds no latency.
{ "model": "lokarouter/auto", "messages": [{ "role": "user", "content": "Refactor this function…" }]}The chosen model is what gets recorded in usage logs. Allow-list lokarouter/auto in a key's guardrails to permit every concrete model through auto.
Store small files (up to 5 MB) for reuse — e.g. fine-tune or batch inputs. Purposes: batch, fine-tune, vision, assistants, user_data.
curl https://api.lokarouter.id/v1/files \ -H "Authorization: Bearer sk-lkr-your-key" \ -F "file=@training.jsonl" \ -F "purpose=fine-tune"Listing files
curl https://api.lokarouter.id/v1/files \ -H "Authorization: Bearer sk-lkr-your-key"Keys allow 60 requests per minute by default. When the limit is hit the gateway returns 429 with a retry-after header plus x-ratelimit-limit and x-ratelimit-remaining so SDKs can back off correctly.
Errors use the OpenAI shape — an error object with message, type, and code. Common codes:
{ "error": { "message": "Key budget exhausted: $5.00 spent of $5.00 budget.", "type": "insufficient_quota", "code": "budget_exhausted" }}| HTTP | Code | Meaning |
|---|---|---|
| 400 | invalid_json / missing_required_parameter | Malformed request — bad JSON or missing model/messages. |
| 401 | invalid_api_key | Missing or invalid API key. |
| 402 | budget_exhausted / workspace_budget_exhausted | Key or workspace budget exhausted. |
| 403 | model_not_allowed / tool_not_allowed | Model or tool blocked by the key's guardrails. |
| 404 | model_not_found / file_not_found | Unknown model id or file id. |
| 429 | rate_limit_exceeded | Rate limit exceeded — retry after the hinted delay. |
| 502 | provider_failed / upstream_unavailable | All upstream providers failed or none are configured. |