# AI Gateway Troubleshooting

URL: https://www.elchi.io/docs/ai-gateway/troubleshooting

> Symptom, cause and fix for Elchi AI Gateway problems, from pushes that never reach an edge to 4xx/5xx answers, empty usage and MCP tool calls, with the exact place to check each.

Each section starts from what you see, names the possible causes in the order to check them, and gives the command or UI place that tells them apart. The meaning of every error code is in [Error Codes](https://www.elchi.io/docs/ai-gateway/reference/error-codes).

## Where to look

| Place | What it tells you |
|---|---|
| **Clients → *client* → AI Gateway** (UI, Owner/Admin) | The edge's gateway service state, the configuration version it applied, a **behind: *version*** chip when it missed a deploy, the extproc version, recent logs, and the conf.d files on its disk |
| **Administration → Jobs** | Each AI gateway deploy job (`AI_GATEWAY_DEPLOY`): which edges applied which version, and the edge's own refusal message |
| **AI Gateway → MCP servers** | A warning naming the edges that hold MCP back |
| **AI Gateway → Providers** | Each provider's status from its answers in the last 15 minutes |
| `curl -s 127.0.0.1:9002/configz` (on the edge) | `state`, `config_version`, `restored_last_good`, `extproc.{binary_version, version_string, ready, restarts}`, `render.last_error`, `reload.{failures, last_error}`, the gateways, the providers (credentials redacted) |
| `curl -s -o /dev/null -w '%{http_code}' 127.0.0.1:9002/readyz` | `200` once the extproc runs a configuration |
| `journalctl -u elchi-ai-gateway` | The supervisor's log, including the extproc's lines (prefixed `extproc:`) |
| Elchi OS console | `show ai-gateway` (state, configuration, gateways, providers, sinks, recent configuration events), `show health` (one AI gateway line), `logs ai-gateway [n] [follow] [grep <pattern>]`, `restart ai-gateway`, `system component status` |

`state` in `/configz` is one of `init`, `ensuring-binary`, `rendering`, `starting`, `ready`, `degraded` (no valid configuration to run; extproc not running), `crash-loop` (the extproc keeps exiting), `stopping`.

## A change never reaches an edge

**Check:** the deploy job under **Administration → Jobs**, then the client's **AI Gateway** tab. Compare its applied version with the **behind** chip, or with `desired_version` from `GET /api/v3/ai-gateway/status?project=&client_id=`.

| Symptom | Cause | Fix |
|---|---|---|
| The job's note says `no connected client of the project runs the AI gateway` (or `the client does not run the AI gateway`) | The control plane pushes only to clients whose registration reports `ai_gateway_version`. The client registered before the gateway was installed, or the gateway is not installed. | Install the gateway on the edge ([Installation](https://www.elchi.io/docs/ai-gateway/installation)), then make the agent register again (`systemctl restart elchi-client`). The reconnect queues a deploy for that client. On Elchi OS, a changed gateway binary makes the agent register again on its own. |
| The client's tab says `client not found in this project (or not connected)` | The client belongs to another project (its registration token is `<uuid>--<project>`), or it is not connected | Open the AI Gateway page of the client's own project. Reconnect the client. |
| The edge shows **behind: *version*** | It missed a deploy (it was offline, or the push failed) | **AI Gateway → Sync** (or `POST /api/v3/ai-gateway/sync`). A client that connects again also gets a deploy of its own. |
| The tab says `The client returned no AI gateway status (is elchi-ai-gateway installed on this edge?)` | The agent found no gateway on the edge | Install it. |
| A save answered `"deploy": {"enqueued": false, "error": …}` | The change is saved, but no job was queued | Run **Sync**. |
| MCP works on some projects but this edge got a set without MCP | The edge's gateway is older than `v0.4.0`: it gets the configuration without MCP | Upgrade the gateway on that edge. |

## The edge refuses a push

The agent stages the files and runs `elchi-ai-gateway validate` on them before it replaces anything. A refused push leaves conf.d and the running configuration unchanged. The job shows the edge's message, `ai gateway rejected the config: …`, with the validator's reason.

| Symptom | Cause | Fix |
|---|---|---|
| Job failed with `ai gateway rejected the config: …` | The edge's gateway validates differently from the control plane. Usually the edge's gateway is older than the configuration's schema. | Upgrade the gateway on the edge. Read the reason, then **Sync**. |
| `/configz` `reload.failures` grows and `reload.last_error` is set; `config_version` does not change | The extproc refused the rendered configuration. The previous one keeps serving. A refused set is not retried until conf.d changes. | Fix the reason in the UI and save. The journal line is `config reload failed; last-good keeps serving` with `reason`. |
| `render.last_error` is set | The configuration could not be rendered (`config render failed; keeping last-good`) | The reason names the field. Fix it in the UI. |
| `restored_last_good: true` | conf.d was unusable at start, or the extproc refused it at start. The gateway runs the last accepted configuration from `/var/lib/elchi/ai-gateway/last-good.json`. The journal says `serving the persisted last-good config`. | Fix the configuration, or **Sync**. On Elchi OS, `show health` warns `serving the last accepted configuration: the pushed one was refused (…)`. |
| `state: degraded` and no last-good | Nothing valid to run: the extproc is not running, and AI listeners answer nothing | Push a valid configuration (**Sync**). `show health` says `serving NO configuration: …`. |
| `config_version` is `empty` and `render.last_error` says `empty config directory` | No configuration was pushed yet: the edge is not registered, or its project has no AI gateway | Expected. On Elchi OS `show health` reports this as information, not a fault. |

Run the same check by hand on the edge:

```bash
sudo -u elchi /etc/elchi/bin/elchi-ai-gateway validate /etc/elchi/elchi-ai-gateway/conf.d
# ok: config valid          → exit 0
# <reason>                  → exit 1
```

## The extproc does not start

| Symptom | Cause | Fix |
|---|---|---|
| `state: ensuring-binary`; journal `could not ensure extproc binary; retrying` (every 10 s) | The engine binary is missing and cannot be downloaded: no egress, a wrong `index_url`, or the archive has no build of the pinned version | Online: check `curl -sI https://archive.elchi.io/index.json` from the edge (or your mirror). Offline: place the binary with `--extproc-binary` / `extproc.binary` in config.yaml (plus `sha256`). On Elchi OS: `import extproc <path> <version> [sha256]`, or `system component status`. |
| The journal shows `adopting extproc's version string from mismatch report` | The rendered `version` did not match the binary's own version string (the version gate). The gateway adopts the string the extproc names, renders again and restarts. This happens once per binary and string. | Nothing. It heals itself. To avoid it, set `extproc.version_string` (or `--extproc-version-string`). |
| `extproc still reports version mismatch after adopting its version string; giving up on self-heal` | The adopted string was refused too | Set `--extproc-version-string` / `extproc.version_string` to the binary's version string. Check that the binary is the pinned release. A development build reports `dev`. |
| `state: crash-loop`; journal `extproc exited; will restart` with `consecutive_short_exits` ≥ 5 | The extproc keeps exiting. Each short exit backs off 1 s, 2 s … up to 30 s. | Read the extproc's own lines just before the exit (`journalctl -u elchi-ai-gateway \| grep extproc:`): they name the reason. |
| `extproc unresponsive; restarting` | The extproc's admin `/health` stopped answering | The gateway restarts it. If it repeats, read the extproc's lines before the restart. |
| The unit does not start on Elchi OS | Its firewall guard failed to load: the gateway does not start with port 9064 open | `logs ai-gateway`; `sudo nft list table inet elchi_ai_gateway`. |

## 404: model or host not found

| Answer | Cause | Fix |
|---|---|---|
| `404 gateway_not_found`: `no AI gateway serves this host on listener <l>` | The request's Host is not one of the hosts of a gateway bound to this listener, and the listener has no default gateway | Add the host to the gateway, bind the gateway to the listener, or set a **default** gateway on the listener ([Listeners](https://www.elchi.io/docs/ai-gateway/listeners)). Gateways bound to *another* listener are not reachable through this one. |
| `404 model_not_found`: `the model is not served by gateway <gw>; …` | The model in the body is not in the gateway's model list | `GET /v1/models` on the same host lists what the gateway serves. Add the model to the gateway. |
| `404` with an empty body | The request reached the router without the extproc naming its model (the gateway's unrouted route) | Check the path and body against the endpoints in [Calling the Gateway](https://www.elchi.io/docs/ai-gateway/calling-the-gateway). |
| `404 not_found`: `this route is not served by an AI gateway` | Your own route on an HCM with the AI gateway toggle on | Dedicate listeners to the AI gateway. Other routes on an AI HCM are not served. |
| `503 gateway_not_ready` … `does not serve model … yet` | Envoy already routes the model, but this edge's configuration does not have it yet | Wait for the deploy, or check that the edge did not refuse it (above). The answer carries `retry-after: 5`. |

## 401 and 403 on keyed gateways

| Answer | Cause | Fix |
|---|---|---|
| `401 invalid_api_key` | No key, a wrong key, a revoked or deleted key, or a **disabled** consumer. Also any request (including `/v1/models`) to a keyed gateway without a key. | Send the key as `Authorization: Bearer sk-elchi-…`, `x-api-key` or `api-key`. A key is shown only once: if it is lost, create a new one on the consumer. A new key works on an edge once the deploy has applied there. |
| `403 gateway_not_allowed` | The consumer's gateway allowlist does not include this gateway | Add the gateway to the consumer, or clear its gateway list. |
| `403 model_not_allowed` | The consumer's model or provider allowlist excludes the model. For a pooled model, every provider of it must be allowed. | Edit the consumer's allowlists. |
| `403 model_not_priced` | The consumer has a cost quota and the model has no price at the provider that serves it | Add the price in the price table ([Quotas, Limits and Costs](https://www.elchi.io/docs/ai-gateway/quotas-limits-and-costs)), or remove the cost quota. |
| `403 files_not_allowed` | `/v1/files` on a keyed gateway | Not supported by design: files belong to the provider's account and would be shared by every consumer. |
| `503 gateway_not_ready` … `as one that requires a key yet` | A new keyed gateway is in Envoy but not yet on this edge, or the edge refused the push | Wait for the deploy, or check the job. |
| `401` or `403` with **no** elchi `code` | The provider refused the provider credential | **AI Gateway → Providers**: the provider status shows `auth_error`. Use **Check** on the provider, and enter its key again. |

The edge's journal has one `request denied` line per consumer and code per minute, naming the consumer, gateway, phase and message:

```bash
journalctl -u elchi-ai-gateway --since -10min | grep '"request denied"'
```

## 422 unsupported API schema

The extproc cannot translate this endpoint to the provider type that serves the model. The common case is `/v1/chat/completions` with a native `anthropic` provider: OpenAI-format clients reach Claude through `aws-anthropic` or `gcp-anthropic`, while a native `anthropic` provider serves `/anthropic/v1/messages`. The table is in [Calling the Gateway](https://www.elchi.io/docs/ai-gateway/calling-the-gateway). The configuration's notes at the top of the **AI Gateway** page (and the `warnings` of every save) name each native `anthropic` provider for this reason.

## 429: quotas

| Answer | Cause | Fix |
|---|---|---|
| `429 quota_exceeded`: `consumer <c> used its quota of <limit>; it resets at <time>` | One of the consumer's quotas is used up. `retry-after` is the seconds until the reset. Days and months are UTC. | Raise the quota on the consumer, or wait. **AI Gateway → Consumers → *consumer*** shows its quota use. |
| A consumer gets N times its quota across N edges | The edges have no ClickHouse. Without it each edge counts only what it saw since it started, and a restart resets the count. The journal warns `consumer quotas are edge-local: …` at start. | Configure `usage.clickhouse_dsn` on every edge. The counters re-read the other edges' usage every minute. |
| `429` with **no** elchi `code` | The provider's own rate limit | The provider status shows `rate_limited`. Add a second provider for the model ([Gateways and Models](https://www.elchi.io/docs/ai-gateway/gateways-and-models)). |

## 503 and 413

| Answer | Cause | Fix |
|---|---|---|
| `503 sensitive_scan_busy` / `sensitive_scan_incomplete` (`retry-after: 1`) | The sensitive-data scan had no free slot, or did not finish, within Envoy's 2 s check | Retry. If it persists, the edge is out of CPU for the scan, or the bodies are very large. Lower the policy's `maxScanBytes`, or add CPU. |
| `413 sensitive_scan_too_large` | The body is larger than the policy scans, and the policy blocks a type | Send less, or raise `maxScanBytes` ([Sensitive Data](https://www.elchi.io/docs/ai-gateway/sensitive-data)). |
| `403 sensitive_data` | The body carries a type the policy blocks. The message names the types. | Remove the value, or change the policy's action for that type. **AI Gateway → Sensitive data** lists the decisions. Try a sample with the policy test. |
| `413` from Envoy | The body is over 50 MiB, the most a gateway buffers | Send a smaller request. |
| `503 service_unavailable`: `the AI gateway has no configuration yet` | This edge's gateway has applied nothing | See [The edge refuses a push](#the-edge-refuses-a-push). |
| `500` for every request | The gateway or the extproc is down or restarting. The AI filters are fail-closed. | `/configz` `state`, `journalctl -u elchi-ai-gateway`. |

## Upstream errors and failover

| Symptom | Cause | Fix |
|---|---|---|
| Provider status `unreachable` | No connection: DNS, refused, or TLS | From the edge: `curl -v https://<provider-host>/`. Check the provider's upstream host and port. Behind a proxy on Elchi OS: `set proxy`. |
| Provider status `timeout` | No answer in time. A model route waits 900 s of silence before Envoy cuts it. | Use streaming for long answers. Check the provider. |
| Status `server_error` or `reset` | The provider answered 5xx, or broke the connection mid-answer | For a model several providers serve, set the gateway's failover so Envoy retries the next provider. Retries go to the level's other providers first; a fallback level serves only when the level above has no healthy provider. |
| Failover does not happen | The model has one provider, or the gateway's failover does not cover the failure | See [Gateways and Models](https://www.elchi.io/docs/ai-gateway/gateways-and-models). A failed attempt behind a successful retry is not in the access log. Pool members show their outlier ejection in Envoy's `/clusters`. |
| Provider status `idle` | No answers in the last 15 minutes | Send a request. **Check** on the provider asks its model list without spending tokens. |

## Usage or the request log is empty

| Symptom | Cause | Fix |
|---|---|---|
| Usage, request log, provider status and decisions are all empty | The edge has no ClickHouse DSN (empty disables every table), or an invalid one (journal: `ClickHouse export disabled: invalid DSN`) | Plain Linux: set `usage.clickhouse_dsn` in `/etc/elchi/elchi-ai-gateway/config.yaml` (a re-run of the installer keeps the existing file), then `systemctl restart elchi-ai-gateway`. Elchi OS: `set ai-gateway usage clickhouse <host:port> <db> <user> [tls]`, then `apply`. |
| The edge writes, but the UI shows nothing | The edge writes to a different ClickHouse than the controller reads, or under another project id (`project` in config.yaml) | Point the edge at the controller's ClickHouse database. Check `project`. |
| The usage page answers `clickhouse not configured; …` | The controller has no ClickHouse | Configure it on the controller. |
| The request log is empty but usage is not | `requests.enabled: false`, or the gateway's capture level is `off` | Set the level to `metadata` or `full` on the gateway ([Request Log](https://www.elchi.io/docs/ai-gateway/request-log)). |
| Content is missing on a `full` row | Content is kept for the gateway's `sampleRate` share only. Content of a shredded key is unreadable (`content_error`). | Raise `sampleRate`. Shredded content cannot be recovered. |
| Usage appears late | Usage is scraped every 30 s. While ClickHouse is unreachable, batches wait and are written when it comes back. | Wait. The request log drops what its 4096-row queue cannot hold during a long outage. |
| Older days show no hourly rollup speed | Rollups are never backfilled. The controller reads the raw table for hours before a rollup existed. | Nothing to fix. The numbers are the same. |

## MCP

| Symptom | Cause | Fix |
|---|---|---|
| `/mcp` is not served on any listener of the project | MCP is held back: an edge of the project runs a gateway older than `v0.4.0` | **AI Gateway → MCP servers** names the edges (`GET /api/v3/ai-gateway/mcp-readiness`). Upgrade them. A disconnected client with an old version holds MCP back too. Delete it if it is gone. |
| A tool is missing from `tools/list` | The consumer was not granted the tool or the server, the server's tool selector excludes it, or the gateway does not serve the server | Edit the consumer's MCP grants and the gateway's MCP servers ([Grants and Quotas](https://www.elchi.io/docs/ai-gateway/mcp/grants-and-quotas)). The list is per consumer. |
| `tool_not_allowed` | The tool was called by its full name, `<server>__<tool>`, but it is not granted | Grant it. |
| The server answers `401`/`403` to a user | A server with **personal tokens**: the user's token was not sent, or not from the start | Send `x-elchi-mcp-token: <token>` (or `x-elchi-mcp-token-<server>` per server) on every request, from `initialize` on ([Personal Tokens](https://www.elchi.io/docs/ai-gateway/mcp/personal-tokens)). |
| Calls fail with `500 call to <server> failed …` | The server is unreachable or answered an error, or the edge's MCP egress is closed | Discover the server's tools from the control plane (**Discover**) to tell the server from the edge. On the edge, check the egress next. |
| Elchi OS: every MCP call fails | The egress guard rule for the gateway's cgroup is missing | `sudo nft list table inet elchi_ai_gateway` must show the `socket cgroupv2 … "system.slice/elchi-ai-gateway.service" accept` rule. The guard logs `the MCP egress stays closed (no rule for …)`. `restart ai-gateway` adds it again. |
| Plain Linux: every MCP call fails | Envoy is not running as the user the firewall allows to answer, or Envoy's user did not exist at install (the installer warned) | Re-run the installer with `--envoy-user=<user>`. Check with `sudo nft list table inet elchi_ai_gateway`. |
| A long tool call or SSE stream ends with `503` | The answer took longer than the MCP write timeout (15 minutes by default) | Raise `--mcp-write-timeout` / `ELCHI_AI_GATEWAY_MCP_WRITE_TIMEOUT` on the edge. |
| `413 mcp_request_too_large` | The request is over 4 MiB | Send less per call. |

**AI Gateway → MCP calls** lists every call with its status and class, newest first.

## Getting the facts in one go

On a plain Linux edge:

```bash
systemctl status elchi-ai-gateway --no-pager
curl -s 127.0.0.1:9002/configz | jq '{state, config_version, restored_last_good, extproc, render, reload}'
ls -l /etc/elchi/elchi-ai-gateway/conf.d /run/elchi-ai-gateway
sudo nft list table inet elchi_ai_gateway
journalctl -u elchi-ai-gateway --since -30min --no-pager | tail -100
```

On Elchi OS: `show ai-gateway`, `show health`, `logs ai-gateway 200`.
