
# Troubleshooting

Find what is wrong with a running gateway from its status and its start-up log.

Read both before you change anything: most failures name their cause there, and each section below goes from that cause to its fix.

**Kubernetes**

```bash
kubectl -n tokedex get pods -l app.kubernetes.io/instance=tokedex,app.kubernetes.io/component=gateway
kubectl -n tokedex logs deployment/tokedex
kubectl -n tokedex port-forward svc/tokedex 4000:4000 &
curl -sS http://127.0.0.1:4000/readyz
```

**Docker**

```bash
docker compose ps -a
docker compose logs gateway
curl -sS http://127.0.0.1:4000/readyz
```

```json
{"ok":true,"release":{"environment":"local"},"service":"tokedex"}
```

**Kubernetes**

You need: `kubectl` access to the release, here `tokedex` in the namespace `tokedex`. For an error a request returns, see [Errors, limits and request IDs](/gateway/errors-and-limits).

**Docker**

Run these commands from the clone you used in the [Gateway quickstart](/gateway/quickstart). For an error a request returns, see [Errors, limits and request IDs](/gateway/errors-and-limits).

## The gateway is not ready

**Kubernetes**

The Pods are `Running` but not ready, and `/readyz` answers `503` with what the gateway cannot reach:

```json
{"ok":false,"release":{"environment":"local"},"service":"tokedex","unavailable":["redis"]}
```

| `unavailable` lists | Fix |
| --- | --- |
| `postgres` or `redis` | Check that the store is up and reachable from the cluster. Redis needs persistence on and the `noeviction` memory policy. |
| `catalogue_out_of_sync` | This replica cannot load the catalogue another stored, usually because it runs an earlier release. Finish the [upgrade](/gateway/upgrades). |

It becomes ready once the store answers, without a restart, so fix the store rather than restarting Pods. A Pod not ready within five minutes of starting is restarted.

**Docker**

`docker compose ps` shows `(health: starting)` or `(unhealthy)`. A gateway on its own volume is ready as soon as it listens, so read the start-up log, as in [The gateway keeps restarting](#the-gateway-keeps-restarting).

## The gateway keeps restarting

**Kubernetes**

The Pod shows `Error` or `CrashLoopBackOff`. Read the run that failed with `kubectl -n tokedex logs <pod-name> --previous`, before you delete the Pod: a replacement Pod's log no longer holds the failure.

**Docker**

`docker compose ps -a` shows the gateway as `Restarting`, or `Exited` once Docker has given up after three restarts. Read `docker compose logs gateway`.

The log ends with `gateway: startup failed` and the reason:

| Reason in the log | Fix |
| --- | --- |
| A database connection error, such as `password authentication failed` | Correct the connection string and restart: the gateway reads secrets only at start. |
| `the database schema is behind this gateway: pending migration(s) …` | Apply the migrations, as in [Upgrades and migrations](/gateway/upgrades#database-migrations). |
| `a running gateway owns this store` | Another gateway runs on the same state. Stop every replica, then start them together. |
| The master key, the password pepper, `Failed to open the stored credential`, or `invalid configuration document` | Follow [Recover dashboard access](/gateway/recover-access). |
| `the unwritten spend in … could not be written to the spend ledger` | Check the database connection, and keep the files in `state/spend-unwritten`: they hold spend not yet counted. |

Stop every replica before you run a gateway command on the same state: a command that changes state refuses while a gateway runs on it. [Recover dashboard access](/gateway/recover-access#run-a-gateway-command-while-the-gateway-is-stopped) shows how to run one.

## The dashboard will not open

Check first that the gateway is ready. Then:

- **You are on another computer.** The gateway answers other computers only at its public URL, through the ingress (Docker: The quickstart's gateway answers only on the machine that runs it). To serve other computers, [deploy it](/gateway/deploy) and serve it over [HTTPS](/gateway/https).
- **The browser shows "This gateway does not answer to that address" (HTTP 421).** Set the public URL to the address you open; see [The dashboard refuses the address](/gateway/recover-access#the-dashboard-refuses-the-address).
- **The page opens but sign-in fails.** See [A person cannot sign in](/gateway/recover-access#a-person-cannot-sign-in), or [Single sign-on](/gateway/single-sign-on) for an identity provider.

## No models appear

**Playground** and `GET /v1/models` list only models the API key can call.

1. Open **Providers**. A provider that reads **Not configured** needs a credential; see [Provider credentials](/gateway/provider-credentials).
2. Open the model in **Models & Routing**. **Routing by API format** must list your client API, with **Accept requests** and **Show in model list** selected.
3. Check that the key and its workspace may call the model; see [Model access and limits](/gateway/model-access-and-limits).
4. In **Playground**, choose **Refresh models** after you change the key or a credential.

## Traces or prompt text are missing

- **A request is not in Observability.** Check first that recording reports `ok`, as [Check that recording works](/gateway/recording-and-retention#check-that-recording-works) shows, then the time range and the workspace chosen in the sidebar. A request sent with `x-tokedex-trace: false` is not recorded.
- **The page reads "Observability store disabled".** Choose **Enable observability**, then restart the gateway.
- **A trace reads "Text not captured".** Text capture is off on the gateway, or the request did not opt in; see [What the gateway records](/gateway/recording-and-retention).

## A restored or upgraded gateway will not start

Keep clients away, read the reason in the start-up log and save a copy, since a catalogue fix needs the command it prints. Then check that:

- The gateway runs the release that took the backup. Restore first, then upgrade.
- Every part of the backup is back, with the secrets the gateway had.
- No migration is pending, and the stored catalogue is in sync; see [Recover a failed upgrade](/gateway/upgrades#recover-a-failed-upgrade).

Never delete the claim (Docker: volume) to get past an error: it holds keys nothing else can rebuild.

## Report a problem

[Open an issue on GitHub](https://github.com/ArtificialAnalysis/tokedex/issues/new) to report a bug, request a feature or point out a problem in these docs. In the dashboard, **Open an issue on GitHub** under **Help** in the sidebar starts one with the release and browser details filled in. Tokedex does not accept pull requests, so an issue is also the way to suggest a change; [Contributing](https://github.com/ArtificialAnalysis/tokedex/blob/main/CONTRIBUTING.md) has the full guidelines.

Include the image tag (Docker: commit of your clone), the client API, a minimal request, the HTTP status, the error body, the `x-request-id` response header and the start-up log. Remove keys, provider credentials and sensitive text first: issues are public, and the start-up log can print the master key. Report a security problem privately, as [SECURITY.md](https://github.com/ArtificialAnalysis/tokedex/blob/main/SECURITY.md) describes.

Next: [Recover dashboard access](/gateway/recover-access), [Errors, limits and request IDs](/gateway/errors-and-limits) or [Upgrades and migrations](/gateway/upgrades).
