# Set up OpenCode with InferSpeed: OpenCode API key and provider config

Add an `inferspeed` provider to `opencode.json`, put your key in the `INFERSPEED_API_KEY` environment variable, then pick `inferspeed/glm-5.3`. OpenCode uses the OpenAI Chat Completions endpoint, and you pay per token.

The config blocks match developers.md (checked 2026-10-19).

## Setup

1. Create a key at https://inferspeed.ai/keys and put it in an environment variable (in `~/.zshrc` or `~/.bashrc`, not in a project file):

```bash
export INFERSPEED_API_KEY="sk-****"
```

2. Write this into `opencode.json` at the project root, or merge it into `~/.config/opencode/opencode.json`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "inferspeed": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "InferSpeed",
      "options": {
        "baseURL": "https://api.inferspeed.ai/v1",
        "apiKey": "{env:INFERSPEED_API_KEY}"
      },
      "models": {
        "glm-5.3": {
          "name": "glm-5.3"
        }
      }
    }
  }
}
```

`"apiKey": "{env:INFERSPEED_API_KEY}"` makes OpenCode read the key from the environment, so the key never appears in the config file.

## Check it works

```bash
opencode run -m inferspeed/glm-5.3 "reply with the word ok"
```

## Common errors

| Error | Cause | Fix |
|---|---|---|
| 400 `model_not_available` | The model name could not be routed (strict mode `X-Model-Strict: 1`, or no live routing target; see Model routing in developers.md) | `available_models` in the response lists the models this key can call; use one of them |
| 403 `INSUFFICIENT_BALANCE` | The balance is used up | Top up, then retry |

## Prices (USD per 1M tokens)

| Model | Input | Output | Cache read | Official price (input / output) |
|---|---|---|---|---|
| glm-5.3 | $0.84 | $2.64 | $0.156 | $1.40 / $4.40 |

All models and live prices: https://inferspeed.ai/model-plaza

## FAQ

**Can I use Kimi?**
One key calls every live model (`GET /v1/models` lists the models your key can call); use the model ID `kimi-k3`. This page only gives the config for `glm-5.3`.

**What are the default limits?**
30 requests per minute and 5 concurrent requests for new accounts, across all keys of the account.
