> ## Documentation Index
> Fetch the complete documentation index at: https://www.hedra.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Run coding agents on open-weight models

> Run Claude Code, Codex CLI, OpenCode and Pi on GLM-5.3, Kimi K3 and DeepSeek V4 through Hedra, paid per token from your API wallet.

Run Claude Code, Codex CLI, OpenCode or Pi on GLM-5.3, Kimi K3 and DeepSeek V4 with one Hedra API key. Every model has a context length of 1,048,576 tokens, and you pay per token from the same API wallet as your other inference requests. Claude Code connects to `POST /v3/anthropic/v1/messages`, Codex connects to `POST /v3/responses`, and OpenCode and Pi connect to `POST /v3/chat/completions`, each with a few lines of configuration.

## Before you start

* **A key with the `chat:write` scope and a funded API wallet.** See [Before you start](https://www.hedra.com/docs/pages/developer/v3/chat-completions.md#before-you-start) in the chat completions guide.
* **The key in the `HEDRA_API_KEY` environment variable** of the terminal that starts the agent:

```bash theme={null}
export HEDRA_API_KEY="<key_id>:<secret>"
```

## Choose a model

| Model | Input | Time of one OpenCode run |
| - | - | - |
| `glm-5.3` | text and images | 79 s |
| `glm-5.3-flash` | text and images | 35 s |
| `kimi-k3` | text and images | 83 s |
| `deepseek-v4-pro-0813` | text | 141 s |
| `deepseek-v4.1-flash` | text and images | 27 s |

On 2026-09-30 we had OpenCode, on each model, write unit tests for one module of a large Python repository and run them until they passed. Every model finished in 8 to 14 requests. `GET /v3/models` returns each model's current per-token prices.

## Connect an agent

> [tab] Claude Code
>
> The steps below use Claude Code 2.1.288.
>
> **1. Install Claude Code**
>
> ```bash theme={null}
> curl -fsSL https://claude.ai/install.sh | bash
> ```
>
> **2. Add a configuration directory for Hedra**
>
> Save this as `~/.claude-hedra/settings.json`:
>
> ```json theme={null}
> {
>   "apiKeyHelper": "echo $HEDRA_API_KEY",
>   "env": {
>     "ANTHROPIC_BASE_URL": "https://api.hedra.com/v3/anthropic",
>     "ANTHROPIC_MODEL": "glm-5.3[1m]",
>     "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.3[1m]",
>     "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.3[1m]",
>     "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.3-flash",
>     "CLAUDE_CODE_AUTO_MODE_SERVER": "0"
>   }
> }
> ```
>
> * Claude Code runs the `apiKeyHelper` command and sends its output as your key, so the file contains no secret.
> * `ANTHROPIC_MODEL` names the model. The `[1m]` suffix tells Claude Code that the model's context length is 1,000,000 tokens; without it, Claude Code assumes 200,000 for a model it does not know and compacts the conversation as it nears that. Claude Code sends the id without the suffix.
> * `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL` and `ANTHROPIC_DEFAULT_HAIKU_MODEL` name the model Claude Code picks for each tier. In auto mode, Claude Code checks tool calls with the Sonnet tier's model, and it runs background tasks such as session titles on the Haiku tier's model.
> * `CLAUDE_CODE_AUTO_MODE_SERVER` set to `0` tells Claude Code that Hedra doesn't run Anthropic's auto mode checks, so Claude Code runs its own.
>
> **3. Start Claude Code**
>
> ```bash theme={null}
> CLAUDE_CONFIG_DIR=~/.claude-hedra claude
> ```
>
> Claude Code reads its settings from the directory in `CLAUDE_CONFIG_DIR`, so only the sessions you start this way use Hedra. In those sessions, Claude Code loads none of your MCP servers or plugins, which keeps their tool definitions out of every request. `/status` shows the base URL and the credential in use.
>
> `CLAUDE_CONFIG_DIR=~/.claude-hedra claude --model 'kimi-k3[1m]'` switches models for one session. Claude Code's `/effort` levels become the model's `reasoning_effort`, and the model's reasoning appears as thinking. In print mode (`claude -p`), Claude Code writes `[claude-code:unrecognized_model]` to stderr for a Hedra model id, and the session runs normally.
>
> Claude Code's cost figures, in `/cost` and in the `total_cost_usd` of `claude -p --output-format json`, don't match Hedra's charges. Hedra's charge for each request is in the response's `usage.cost`, on the [Jobs tab](https://www.hedra.com/develop/jobs) of the developer console, and in `GET /v3/jobs/{job_id}`.

> [tab] Codex CLI
>
> The steps below use Codex CLI 0.159.2.
>
> **1. Install Codex**
>
> ```bash theme={null}
> npm install -g @openai/codex
> ```
>
> **2. Add a Codex profile**
>
> Save this as `~/.codex/hedra.config.toml`:
>
> ```toml theme={null}
> model = "glm-5.3"
> model_provider = "hedra"
>
> [features]
> apps = false
>
> [model_providers.hedra]
> name = "Hedra"
> base_url = "https://api.hedra.com/v3"
> env_key = "HEDRA_API_KEY"
> ```
>
> Codex sends the tool definitions of your ChatGPT apps, such as GitHub and Slack, with every request, which can add tens of thousands of tokens. `apps = false` leaves them out of Hedra sessions.
>
> **3. Start Codex**
>
> ```bash theme={null}
> codex --profile hedra
> ```
>
> `codex --profile hedra --model kimi-k3` switches models. Hedra maps Codex's `model_reasoning_effort` values onto the models' own: `minimal` to `low`, `medium` to the model's default effort, and `xhigh` to `max`.

> [tab] OpenCode
>
> The steps below use OpenCode 1.18.33.
>
> **1. Install OpenCode**
>
> ```bash theme={null}
> curl -fsSL https://opencode.ai/install | bash
> ```
>
> **2. Add Hedra as a provider**
>
> Save this as `~/.config/opencode/opencode.json`, or add the `hedra` entry to the `provider` object in your existing file:
>
> ```json theme={null}
> {
>   "$schema": "https://opencode.ai/config.json",
>   "provider": {
>     "hedra": {
>       "npm": "@ai-sdk/openai-compatible",
>       "name": "Hedra",
>       "options": {
>         "baseURL": "https://api.hedra.com/v3",
>         "apiKey": "{env:HEDRA_API_KEY}"
>       },
>       "models": {
>         "glm-5.3": { "name": "GLM-5.3" },
>         "glm-5.3-flash": { "name": "GLM-5.3 Flash" },
>         "kimi-k3": { "name": "Kimi K3" },
>         "deepseek-v4-pro-0813": { "name": "DeepSeek V4 Pro 0813" },
>         "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash" }
>       }
>     }
>   }
> }
> ```
>
> **3. Start OpenCode**
>
> ```bash theme={null}
> opencode --model hedra/glm-5.3
> ```

> [tab] Pi
>
> The steps below use Pi 0.99.2, which needs Node.js 22.19 or later.
>
> **1. Install Pi**
>
> ```bash theme={null}
> npm install -g --ignore-scripts @earendil-works/pi-coding-agent
> ```
>
> **2. Add Hedra as a provider**
>
> Save this as `~/.pi/agent/models.json`. With `"$HEDRA_API_KEY"`, Pi reads the key from the `HEDRA_API_KEY` environment variable.
>
> ```json theme={null}
> {
>   "providers": {
>     "hedra": {
>       "baseUrl": "https://api.hedra.com/v3",
>       "api": "openai-completions",
>       "apiKey": "$HEDRA_API_KEY",
>       "models": [
>         { "id": "glm-5.3", "contextWindow": 1048576 },
>         { "id": "glm-5.3-flash", "contextWindow": 1048576 },
>         { "id": "kimi-k3", "contextWindow": 1048576 },
>         { "id": "deepseek-v4-pro-0813", "contextWindow": 1048576 },
>         { "id": "deepseek-v4.1-flash", "contextWindow": 1048576 }
>       ]
>     }
>   }
> }
> ```
>
> `contextWindow` sets each model's context length in Pi. Without it, Pi sets the context length to 128,000 tokens and compacts the conversation as it approaches that length.
>
> **3. Start Pi**
>
> ```bash theme={null}
> pi --provider hedra --model glm-5.3
> ```

## Keep sessions inexpensive

An agent sends its instructions, its tool definitions and the conversation so far with every request, and Hedra bills each request's tokens at the model's prices. A shorter prompt lowers the price of every request in the session:

* **Turn off the MCP servers a session does not need.** Each MCP server adds its tool definitions to every request. In Codex, `codex mcp list` prints your servers' names, and `-c mcp_servers.<name>.enabled=false` turns one off for the session:

  ```bash theme={null}
  codex --profile hedra -c mcp_servers.linear.enabled=false
  ```

  In OpenCode, set `"mcp": { "linear": { "enabled": false } }` in `opencode.json`. By default, Pi adds no MCP tool definitions to the prompt.
* **Keep `CLAUDE.md` and `AGENTS.md` focused.** Claude Code sends the repository's `CLAUDE.md` with every request, and Codex, OpenCode and Pi send its `AGENTS.md`. Claude Code also sends the name and description of every skill it has loaded.
* **Leave Claude Code's files out of OpenCode.** OpenCode also reads Claude Code's instructions and skills from `~/.claude` into its prompt. Set `OPENCODE_DISABLE_CLAUDE_CODE=1` to leave them out.

`GET /v3/usage` reports your spend on each model since `start`, with a key that has the `usage:read` scope:

```bash theme={null}
curl "https://api.hedra.com/v3/usage?start=2026-09-30T21:00:00Z&group_by=model" \
  -H "Authorization: Key $HEDRA_API_KEY"
```

## Troubleshooting

* **Codex prints `Model metadata for glm-5.3 not found`.** Codex has no metadata for Hedra's models, and the session runs normally without it.
* **Claude Code's WebSearch tool fails.** WebSearch runs on Anthropic's web search server tool, which Hedra answers with `400`. WebFetch reads pages itself and works.
* **A missing key, or a `401` response.** When `HEDRA_API_KEY` is unset, Codex prints `Missing environment variable: HEDRA_API_KEY`, OpenCode prints `Missing credentials` and Pi prints `No API key found for hedra`. Set `HEDRA_API_KEY` in the terminal that starts the agent, and restart the agent.
* **A `402` response.** Your API wallet's balance cannot cover the request. [Add funds](https://www.hedra.com/develop/billing) and send the message again.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.