Documentation
The gateway speaks the OpenAI HTTP API, so any OpenAI SDK connects by changing the base URL and the API key.
Connect
Point your OpenAI SDK (or curl) at the base URL below and use one of your API keys as the bearer token.
Get a key from Account → API Keys in your account.
curl https://ai-gateway.talivio.com/v1/chat/completions \
-H "Authorization: Bearer $TALIVIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "talivio/standard", "messages": [{"role": "user", "content": "Hello"}]}'
from openai import OpenAI
client = OpenAI(base_url="https://ai-gateway.talivio.com/v1", api_key="TALIVIO_API_KEY")
response = client.chat.completions.create(
model="talivio/standard",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://ai-gateway.talivio.com/v1", apiKey: "TALIVIO_API_KEY" });
const response = await client.chat.completions.create({
model: "talivio/standard",
messages: [{ role: "user", content: "Hello" }],
});
console.log(response.choices[0].message.content);
Tiers vs raw model IDs
You never have to name a model. Send a virtual tier name in the "model" field (for example "talivio/standard") and the gateway picks the best model for that quality level. If your key allows raw models, "GET /v1/models" also lists provider-specific IDs shaped "provider/model_id", each with its own "pricing" block.
Available tiers:
- talivio/cheap
- talivio/standard
- talivio/smart
- talivio/cheap-eu
- talivio/very-smart
Streaming
Set "stream": true to get an OpenAI-compatible Server-Sent Events stream. The final chunk carries the "usage" block, including the "usage.talivio" details below.
curl https://ai-gateway.talivio.com/v1/chat/completions \
-H "Authorization: Bearer $TALIVIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "talivio/standard", "stream": true, "messages": [{"role": "user", "content": "Hello"}]}'
Tools
Function/tool definitions are passed straight to the model. The gateway never executes a tool call itself — it only forwards the model's intent to call one ("tool_calls" in the response) back to you. Running the tool and sending its result back is your application's job.
The usage.talivio block
Every response (streaming or not) carries a "usage.talivio" object next to the standard token counts, so you always know exactly what handled your request and what it cost.
{
"usage": {
"prompt_tokens": 42,
"completion_tokens": 128,
"total_tokens": 170,
"talivio": {
"request_id": "req_...",
"provider": "openai",
"model": "gpt-5-mini",
"requested_tier": "standard",
"resolved_tier": "standard",
"degraded": false,
"failover_used": false,
"local": false,
"cached_tokens": 0,
"reasoning_tokens": 0,
"cost_eur": 0.00041231,
"fx_stale": false,
"latency_ms": 812
}
}
}
Account endpoints
Three read-only endpoints let you track usage and billing without leaving your own backend.
- • "GET /v1/usage" — usage records for your project.
- • "GET /v1/billing/balance" — your outstanding balance, credit limit and account status.
- • "GET /v1/billing/invoices" — your daily settlements.
Rate limits
Every response carries "X-RateLimit-Limit" and "X-RateLimit-Remaining". When you are throttled you get HTTP 429 with a "Retry-After" header — back off until then before retrying.
Idempotency
Send the same request twice in a row (a retry after a timeout, for example) with the same "X-Talivio-Idempotency-Key" header and the gateway will not bill or run it twice.
X-Talivio-Idempotency-Key: 5f4e...
Errors
Every error uses the OpenAI error shape: {"error": {"type", "code", "message"}}.
| Status | Type | Code | Meaning |
|---|---|---|---|
| 401 | invalid_api_key | invalid_api_key | The API key is missing, unknown or revoked. |
| 402 | insufficient_quota | card_required | No card is linked to the account yet. |
| 402 | insufficient_quota | payment_past_due | The last charge failed; update your card. |
| 402 | insufficient_quota | account_suspended | The account was suspended. |
| 402 | insufficient_quota | account_closed | The account is closed. |
| 402 | insufficient_quota | credit_limit_reached | Outstanding balance reached the account's credit limit. |
| 402 | insufficient_quota | daily_cap_reached | Your own daily spend cap was reached. |
| 400 | model_not_found | model_not_found | The requested tier or raw model does not exist or is not available to your key. |
| 400 | unknown_tier | unknown_tier | The "model" field is not a valid virtual tier name. |
| 403 | policy_violation | policy_violation | A raw model was requested that your account's data policy (e.g. EU-only) does not allow. |
| 403 | scope_denied | scope_denied | Your API key is not scoped for this capability or endpoint. |
| 409 | request_in_progress | request_in_progress | A request with the same idempotency key is still running. |
| 429 | rate_limited | rate_limited | Rate or concurrency limit exceeded; see "Retry-After". |
| 502 | provider_unavailable | provider_unavailable | No upstream AI provider could serve the request right now. |
| 502 | provider_quota_exhausted | provider_quota_exhausted | The upstream provider account has run out of credit; the gateway operator has been alerted. Retrying will not help until credit is added. |