Skip to content

One Rust binary, every request.

The Kaeso gateway sits between your apps and your providers. It checks every key and limit, translates every format and logs every request.

Follow one request.

Eight steps between your app's request and its reply, and what the app gets when one of them refuses it.

  1. Key

    The API key decides the project and the member or service account it acts for. Keys are stored only as hashes and answered from memory for 30 seconds.

    What the app can get

    • 401UnauthorizedUnauthorizedThe key is missing, unknown, disabled, archived or expired.
    • 403ForbiddenForbiddenThe key has no inference access, or its member lacks the right api.request.
    • 429Rate limitedRate limitedToo many requests with unknown keys came from the same address.

    The gateway reads the key from x-api-key, or else from Authorization: Bearer:

    x-api-key: sk-kso-…Authorization: Bearer sk-kso-…
  2. Decode

    KPP decodes the body from the app's format into Kaeso's canonical format. Anything Kaeso never sends to a provider is refused here.

    What the app can get

    • 413Too largeToo largeThe body is larger than 32 MiB, the default limit.
    • 400Bad requestBad requestKaeso can't read the request, or it asks for something Kaeso never sends, such as more than one choice.
    • 503UnavailableUnavailableRequests being translated already use the memory set aside for them, and this one waited 10 seconds. In the Anthropic format the status is 529.

    Both limits are settings; these are their defaults:

    [body_limits]model_api = "32MiB"in_flight = "512MiB"
  3. Model

    The name resolves in the project's catalogue, where an alias's route chooses the model and its fallbacks, and the request is checked against the model's capabilities before anything is sent.

    What the app can get

    • 404Not foundNot foundThe model isn't in the project's catalogue, or the key may not use it. Both answer alike, so a key can't learn which other models exist.
    • 400Bad requestBad requestSeveral providers serve the id, or the model lacks something the request needs, such as tools or images.

    The same 404 in each format, so every SDK raises its usual error:

    {  "error": {    "message": "The model `gpt-9` does not exist or this key may not use it.",    "type": "invalid_request_error",    "param": "model",    "code": null  }}
  4. Limits

    Every rate and budget of the key, the member and the project is checked at once in Valkey. Over a limit, the app gets 429, and the message names the limit.

    What the app can get

    • 429Rate limitedRate limitedA rate or a hard budget is reached. For a rate, Retry-After says when to try again; for a budget, the message says when it resets.
    • 403ForbiddenForbiddenA spend budget applies, and the request uses something Kaeso can't price, such as a provider-run tool or a model without a price.
    • 200OKOKA soft budget is passed. The request goes on, and the budget only alerts.
    • 503UnavailableUnavailableValkey can't be reached and the request falls under a hard budget, or the project's limits can't be loaded. The OpenAI formats answer 500.

    A rate limit's Retry-After gives the wait in whole seconds, rounded up:

    HTTP/1.1 429 Too Many Requestsretry-after: 13kaeso-request-id: req_…
  5. Provider key

    The project's key for the provider is chosen and decrypted, and kept only in memory for at most 30 seconds.

    What the app can get

    • 400Bad requestBad requestThe project has no provider key for the model's provider.
    • 500Server errorServer errorKaeso can't decrypt the provider key.

    Generate a new master key, write it in front of the old one in master-keys, recreate the gateway, then rewrap moves every stored secret to it:

    new=$(docker compose exec -T gateway kaeso master-key generate) &&  old=$(sudo cat master-keys) &&  printf '%s,%s\n' "$new" "$old" | sudo tee master-keys > /dev/nullunset new olddocker compose up -d --wait --force-recreate gatewaydocker compose exec gateway kaeso master-key rewrap
  6. Encode and send

    KPP encodes the request for the provider's format, and what that format can't express is refused. In a project with the response cache on, a repeated identical request is answered from Valkey instead.

    What the app can get

    • 400Bad requestBad requestThe provider's format can't express what the request asks for.
    • 502Bad gatewayBad gatewayThe provider can't be reached, or it refused the project's provider key.
    • 504Gateway timeoutGateway timeoutThe provider didn't answer in time.

    A provider that refuses the project's key gets your app a 502 that asks for an admin, never the provider's 401:

    {  "type": "error",  "error": {    "type": "api_error",    "message": "The provider refused this project's provider key. Ask an organization admin to check it under Providers."  },  "request_id": "req_…"}
  7. Reply

    The reply is decoded and encoded in the app's format, event by event for a stream, with the kaeso-model and kaeso-provider headers.

    What the app can get

    • 200OKOKThe reply in the app's own format, with the model and provider that served it.
    • 529OverloadedOverloadedThe provider is overloaded: 529 in the Anthropic format, 503 in the OpenAI formats.

    Every answer names the request, and once the model is known, who served it:

    kaeso-request-id: req_…kaeso-provider: anthropickaeso-model: claude-haiku-5-5
  8. Log

    Usage, the cost at the prices in force when the request was made, and the request log are recorded, with the content when both the organization and the project log it, and its images, audio and files only when both keep media.

    What the app can get

    • 200OKOKLogging never holds a request up: the reply goes out first, and log entries wait in memory.
    • 499Client closedClient closedThe app closed the connection. Kaeso stops the provider request at once and charges what was used.

    Log rows wait in memory and go to ClickHouse in batches:

    [logs]buffer_size = "256MiB"flush_interval = "1s"flush_rows = 5000

Inside the gateway.

Keys that stay in the gateway, state in stores you already run, and a service you operate like any other.

01

Keys stay in the gateway

Provider keys never reach your apps, and every action in the console is checked against one right.

Read about provider keys (opens in a new tab)

What your apps holdsk-kso-AbC1…wxyzInference

A Kaeso key, stored only as a hash, with an optional expiry and access to models, the Platform API or the project's tools.

What the gateway holdsOpenAIAnthropic

Provider keys, envelope-encrypted with AES‑256‑GCM under a master key ring you hold. Rotate the master key with kaeso master-key rewrap.

Sign-in
Password with an authenticator app and recovery codes, sign-in links, and single sign‑on through each organization's OIDC provider
Rights
Fine-grained rights with built-in roles and up to 50 custom roles per organization
Audit logs
For the instance, every organization and every project

02

State in stores you know

Gateway instances keep nothing of their own, so you add more behind your load balancer. They share one PostgreSQL and one Valkey, and ClickHouse for request logs, which you can also turn off.

Read the architecture (opens in a new tab)

PostgreSQL
Keys, catalogue, limits, usage and audit logs
ClickHouse
Request logs and their content
Valkey
Rate and budget counters, shared caches

03

Run it like any service

Configure it with environment variables or a TOML file, read every secret from a file, and watch it with the tools you already run.

Read the configuration (opens in a new tab)

1listen = "0.0.0.0:8080"2public_url = "https://kaeso.example.com"3 4[providers.anthropic]5base_url = "https://api.anthropic.com"6 7[upstream]8request_timeout = "600s"9 10[logs]11buffer_size = "256MiB"
Metrics
Prometheus on port 9100, which Caddy doesn't route; keep it private
Health
/healthz while the process runs, and /readyz with the state of PostgreSQL, Valkey and ClickHouse
Logs
Structured JSON, and request logs kept 90 days, content 30 days, by default
Streams
Keepalives after 15 seconds of silence; the provider call is cancelled when the app goes away

One repository, one version.

The gateway, the console, KPP and Kaeso UI ship together, MIT licensed.

Browse the source on GitHub (opens in a new tab)

In front of every app.

One Compose file with Caddy, the gateway, the console, PostgreSQL, ClickHouse and Valkey, on your own servers.