# Troubleshooting

Missing trajectories usually mean an unset API key, a process that exits before sending, or code running outside `observe`. The SDK reports each problem once on stderr and never stops your agent.

### Python

### Troubleshooting

**Nothing arrives.**

- `zhanla: production tracing is off: set ZHANLA_API_KEY…` on stderr: the key is not in the environment of the process that called `init`.
- `zhanla: could not send trajectories (the export failed)` on stderr, usually after an OpenTelemetry line such as `Failed to export spans batch code: 401, reason: Unauthorized`: the key is wrong, revoked, or rotated more than a day ago. Copy a current key from Settings → API Keys. A 400 means the agent id is not an agent of the key's organization. The SDK says this once per reason and never stops your agent.
- The process was killed before the background send ran. A process that calls `os._exit`, or is killed, loses what was waiting. A server that stops on a signal should call `zhanla.flush()` first.
- A streamed reply that is never read to the end keeps its request open, so that request is never sent.
- `zhanla.init was called twice` raises: call it once per process.

**Spans with no root.** If your model calls arrive but there is no request around them, your code is not running inside an `observe`d function. Each model call then becomes its own trajectory: there is no user message, no reply, and nothing that ties the calls of one request together. Put `@zhanla.observe` on the function that handles the request, and call the model from inside it.

**A streamed reply recorded raw.** If the reply shows as the raw body (for example `{"token": "Hi"}` lines) instead of its text, your stream is in a format the SDK does not read. Use server-sent events with one of the fields listed in [Streaming replies](https://zhanla.vercel.app/docs/sdk/python#streaming-replies) (for example `data: {"delta": "Hi"}`), or have the `observe`d function return the finished text. A list of JSON objects means the stream yields objects: yield text or bytes instead.

### TypeScript

### Troubleshooting

**Nothing arrives.**

- `zhanla: production tracing is off: set ZHANLA_API_KEY…` on stderr: the key is not in the environment of the process that called `init`.
- `zhanla: could not send trajectories (Unauthorized)` on stderr: the key is wrong, revoked, or rotated more than a day ago. Copy a current key from Settings → API Keys. `(Bad Request)` means the agent id is not an agent of the key's organization. The SDK says this once per reason and never stops your agent.
- The process was cut short before the background send ran. A process that calls `process.exit`, or is killed, loses what was waiting. A server that stops on a signal should `await flush()` first.
- A streamed reply that is never read to the end keeps its request open, so that request is never sent.
- In a bundle, nothing is traced except what you name in `instrument` (see below).
- `zhanla.init was called twice` throws: call it once per process.

**Spans with no root.** If your model calls arrive but there is no request around them, your code is not running inside an `observe`d function. Each model call then becomes its own trajectory: there is no user message, no reply, and nothing that ties the calls of one request together. Wrap the function that handles the request in `observe`, and call the model from inside it.

**A streamed reply recorded raw.** If the reply shows as the raw body (for example `{"token":"Hi"}` lines) instead of its text, your stream is in a format the SDK does not read. Use server-sent events with one of the fields listed in [Streaming replies](https://zhanla.vercel.app/docs/sdk/typescript#streaming-replies) (for example `data: {"delta":"Hi"}`), or have the `observe`d function return the finished text. A list of JSON objects means the stream yields objects: yield strings or bytes instead.

---

Source: https://zhanla.vercel.app/docs/sdk/troubleshooting
Updated 2026-11-24. Checked against release candidate b60cdc94.
