---
title: How a request travels
description: "The Kaeso gateway sits between your apps and your providers. It checks every key and limit, translates every format and logs every request."
url: https://kaeso.app/gateway
markdown: https://kaeso.app/gateway.md
language: en
alternates:
  de: https://kaeso.app/de/gateway.md
  zh-CN: https://kaeso.app/zh-CN/gateway.md
updated: 2026-11-21
kaeso_version: 0.7.0
index: https://kaeso.app/llms.txt
---

# How a request travels

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

> Every page, article and docs page of Kaeso is listed in https://kaeso.app/llms.txt.

**Every request answers to you.**

[Install Kaeso](https://docs.kaeso.app/self-hosting/installation) · [Read the request flow](https://docs.kaeso.app/concepts/request-flow)

- Steps per request: 8
- Formats apps speak: 5
- Providers built in: 50
- Rust process: 1

## Keep your SDK

Apps keep the official OpenAI, Anthropic, Google Gen AI and ElevenLabs SDKs, Claude Code and Codex, and change two settings: the base URL and the key.

- Responses: OpenAI SDK, Responses
- Chat Completions: OpenAI SDK, Chat Completions
- Messages: Anthropic SDK
- Gemini API: Google Gen AI SDK
- ElevenLabs: ElevenLabs SDK

[Call your first model](https://docs.kaeso.app/get-started/calling-models)

## One request, eight steps

Every request passes the same checks in the same order. A step that refuses answers in the app's own format, and a model is tried again only where the project or its route says so.

[Follow a request through the gateway](https://docs.kaeso.app/concepts/request-flow)

**Same checks. Same order. Every request.**

### 1. Key

Step 1 · Can refuse with 401, 403, 429.

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.

> The key checkout-web decides the project, Checkout assistant, and the member it acts for, Ada Okafor.

What the app can get:

- `401`: The key is missing, unknown, disabled, archived or expired.
- `403`: The key has no inference access, or its member lacks the right `api.request`.
- `429`: Too many requests with unknown keys came from the same address.

The gateway reads the key from `x-api-key`, `x-goog-api-key`, `xi-api-key` or `Authorization: Bearer`:

```http
x-api-key: sk-kso-…
x-goog-api-key: sk-kso-…
xi-api-key: sk-kso-…
Authorization: Bearer sk-kso-…
```

### 2. Decode

Step 2 · Can refuse with 400, 413, 503.

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

> KPP decodes the Chat Completions body, one message with text and a photo, into its canonical format.

What the app can get:

- `413`: The body is larger than 32 MiB, the default limit.
- `400`: Kaeso can't read the request, or it asks for something Kaeso never sends, such as more than one choice.
- `503`: Requests 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:

```toml
[body_limits]
model_api = "32MiB"
in_flight = "512MiB"
```

### 3. Model

Step 3 · Can refuse with 400, 404.

The name resolves in the project's catalogue, where an alias's route chooses the model and its fallbacks while skipping steps held in Valkey across instances, and the request is checked against the model's capabilities before anything is sent. Then the project's guardrails, if it uses any, may let a chat request through, rewrite its text or block it.

> The alias fast-smart sends prompts under 100,000 tokens to Claude Sonnet 5.5. This one had 1,840.

What the app can get:

- `404`: The 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.
- `400`: Several 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:

OpenAI:

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

Anthropic:

```json
{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "The model `gpt-9` does not exist or this key may not use it."
  },
  "request_id": "req_…"
}
```

#### Routes you can read

An alias names the models behind it: a fallback when one fails, conditions on headers, formats and tokens, weighted splits. Apps keep sending the same name.

[Read about alias routes](https://docs.kaeso.app/concepts/alias-routes)

### 4. Limits

Step 4 · Can refuse with 403, 429, 503.

Every rate and budget of the key, the member, the service account and the project is checked at once in Valkey, reserving the request's worst-case cost in exact decimal amounts before calling the provider. Over a limit, the app gets 429, and the message names the limit.

> Every rate and budget of the key, the member and the project is checked at once: 46 of 600 requests this minute.

What the app can get:

- `429`: A 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.
- `403`: A spend budget applies, and the request uses something Kaeso can't price, such as a provider-run tool or a model without a price.
- `200`: A soft budget is passed. The request goes on, and the budget only alerts.
- `503`: Valkey 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
HTTP/1.1 429 Too Many Requests
retry-after: 13
kaeso-request-id: req_…
```

#### Budgets that hold

Spend, token and request limits per project, member, service account or key, hard or soft. A hard budget refuses before the provider is called.

[Set limits and budgets](https://docs.kaeso.app/console/limits-and-budgets)

### 5. Provider key

Step 5 · Can refuse with 500, 502.

One of the project's keys for the provider is chosen, by weight where it has several, decrypted and kept only in memory, read again at least every 30 seconds.

> Northwind's Anthropic key is decrypted with the master key and kept in memory for at most 30 seconds.

What the app can get:

- `502`: The project has no provider key for the model's provider.
- `500`: Kaeso 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:

```bash
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/null
unset new old
docker compose up -d --wait --force-recreate gateway
docker compose exec gateway kaeso master-key rewrap
```

### 6. Encode and send

Step 6 · Can refuse with 400, 502, 504.

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.

> KPP encodes the request as Anthropic Messages and sends it once.

What the app can get:

- `400`: The provider's format can't express what the request asks for.
- `502`: The provider can't be reached, or it refused the project's provider key.
- `504`: The 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:

```json
{
  "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_…"
}
```

#### Each provider in its own format

Kaeso calls each of the 41 chat providers in its own format, and ElevenLabs in its own API. Where a provider takes several, a model uses the first unless its “Sends as” names another.

- Chat Completions: OpenAI, Amazon Bedrock, Azure, Baidu Qianfan, Baseten, Cerebras, Cloudflare AI Gateway, Cohere, DeepInfra, DeepSeek, Fireworks AI, Gemini Enterprise Agent Platform, Groq, Hugging Face, IONOS AI Model Hub, Mistral, Moonshot, Nebius Token Factory, Novita AI, NVIDIA, Ollama Cloud, OpenRouter, OVHcloud AI Endpoints, Perplexity, QwenCloud, SambaNova, Scaleway, SiliconFlow, SpaceX, Standard Compute, StepFun, Tencent TokenHub, Together AI, Upstage, Venice, Vercel and Volcengine Ark
- Messages: Anthropic, Amazon Bedrock, Cloudflare AI Gateway, Fireworks AI, Gemini Enterprise Agent Platform, MiniMax, SambaNova, Vercel and Z.ai
- Responses: OpenAI, Azure, Cloudflare AI Gateway, SpaceX and Vercel
- Gemini API: Gemini Enterprise Agent Platform and Google AI Studio
- ElevenLabs: ElevenLabs
- Converse: Amazon Bedrock
- AssemblyAI: AssemblyAI
- Cartesia: Cartesia
- Cohere Rerank: Cohere
- Deepgram: Deepgram
- fal: fal
- Jina Rerank: Jina AI
- Embeddings: Jina AI and Voyage AI
- Replicate: Replicate
- System One: TypeSafe
- Voyage Rerank: Voyage AI

[See every provider](https://kaeso.app/providers.md)

### 7. Reply

Step 7 · Can refuse with 529.

The reply is decoded and encoded in the app's format, event by event for a stream, with `kaeso-request-id`, `kaeso-model`, `kaeso-provider` and `server-timing` headers, and `kaeso-route` when an alias answered. Guardrails that check replies see the reply first.

> The stream comes back as Chat Completions chunks; the first byte after 702 ms.

What the app can get:

- `200`: The reply in the app's own format, with the model, provider, route trace and Kaeso's own overhead.
- `529`: The provider is overloaded, and Kaeso passes it on: 529 in the Anthropic format, 503 in the OpenAI and Gemini formats.

Every answer names the request, who served it and Kaeso's own time, and an alias's answer the route it took:

```http
kaeso-request-id: req_…
kaeso-provider: anthropic
kaeso-model: claude-haiku-5-5
kaeso-route: "route";model="anthropic/claude-haiku-5-5";status=200
server-timing: upload;dur=0.2, kaeso;dur=0.4, upstream;dur=701.4
```

### 8. Log

Step 8 · Never holds the reply up.

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.

> Status, tokens, cost and timing go to the request logs after the reply has gone.

What the app can get:

- `200`: Logging never holds a request up: the reply goes out first, and log entries wait in memory.
- `499`: Only in the log: the app closed the connection, so Kaeso stops the provider request at once and charges what was used.

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

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

**The master key stays with you.**

## Keys stay in the gateway

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

- What your apps hold: 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 holds: Provider keys, envelope-encrypted with AES-256-GCM under a master key ring you hold. To rotate the master key, put a new one first in the master key file and run `kaeso master-key rewrap`.
- Sign-in: Password or sign-in link, with optional two-factor through an authenticator app and recovery codes, 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
- Agent MCP: An MCP server at /mcp lets Claude Code, Codex or Cursor inspect and operate the install within the rights a person grants

[Read about provider keys](https://docs.kaeso.app/console/provider-keys)

## 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.

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

[Read the architecture](https://docs.kaeso.app/development/architecture/gateway)

## 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.

TOML, in kaeso.toml:

```toml
listen = "0.0.0.0:8080"
public_url = "https://kaeso.example.com"

[providers.anthropic]
base_url = "https://api.anthropic.com"

[upstream]
request_timeout = "600s"

[logs]
buffer_size = "256MiB"
```

Environment, in compose.override.yaml:

```yaml
services:
  gateway:
    environment:
      KAESO_LISTEN: 0.0.0.0:8080
      KAESO_PUBLIC_URL: https://kaeso.example.com
      KAESO_PROVIDERS_ANTHROPIC_BASE_URL: https://api.anthropic.com
      KAESO_UPSTREAM_REQUEST_TIMEOUT: 600s
      KAESO_LOGS_BUFFER_SIZE: 256MiB
      KAESO_MASTER_KEYS_FILE: /run/secrets/master_keys
```

Health, in Terminal:

```bash
docker compose exec console wget -qO- http://gateway:8080/healthz
docker compose exec console wget -qO- http://gateway:8080/readyz
```

- 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

[Read the configuration](https://docs.kaeso.app/self-hosting/configuration)

## One repository, one version

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

- [Gateway](https://docs.kaeso.app/development/architecture/gateway) (`ghcr.io/logicplanes/kaeso-gateway`): The kaeso binary: the Model API, the Platform API, migrations and admin commands.
- [Console](https://docs.kaeso.app/development/architecture/console) (`ghcr.io/logicplanes/kaeso-console`): The web console, built with React 19 and only Kaeso UI.
- [KPP](https://docs.kaeso.app/development/kpp) (`kaeso-kpp, kaeso-codecs`): The Kaeso Provider Protocol and its codecs, on crates.io.
- [Kaeso UI](https://ui.kaeso.app) (`@logicplanes/kaeso-ui`): The component library every Kaeso screen and this site are built from.

[Browse the source on GitHub](https://github.com/logicplanes/kaeso)

## In front of every app

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

[Install Kaeso](https://docs.kaeso.app/self-hosting/installation) · [Open the live demo](https://demo.kaeso.app)
