# OpenCode

> Configure OpenCode to route Chat Completions or Responses calls through HeyEly.

OpenCode connects to OpenAI-compatible gateways via `@ai-sdk/openai-compatible` over Chat Completions at `https://heyely.si/v1`. The snippet below follows OpenCode's 1.x config schema.

## Set up

1. Create an API key in [Developers](https://heyely.si/keys) and export it as `HEYELY_API_KEY` in the shell launching OpenCode.
2. Add HeyEly to a project-level `opencode.json`, or configure it globally in `~/.config/opencode/opencode.json` (on Windows, `%USERPROFILE%\.config\opencode\opencode.jsonc`).

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "heyely": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "HeyEly",
      "options": {
        "baseURL": "https://heyely.si/v1",
        "apiKey": "{env:HEYELY_API_KEY}"
      },
      "models": {
        "anthropic/claude-sonnet-5.5": {
          "name": "Claude Sonnet 5.5",
          "limit": { "context": 1000000, "output": 128000 }
        }
      }
    }
  },
  "model": "heyely/anthropic/claude-sonnet-5.5"
}
```

3. Launch `opencode`.

Prefer storing your key inside OpenCode instead of exporting an env var? Run `/connect`, select **Other**, type `heyely` as the provider ID, and paste your key. OpenCode saves it to `~/.local/share/opencode/auth.json`.

## Verify

1. Run `opencode models heyely` to verify your configured entries show up.
2. Send a quick one-off verification prompt:

```bash
opencode run -m heyely/anthropic/claude-sonnet-5.5 \
  "Reply with exactly: gateway-ok"
```

3. Open [Credit and usage](https://heyely.si/usage) to confirm the call appears at the top of **Spend** under your selected model.

Note that `opencode auth list` only displays keys saved through `/connect`, not keys resolved dynamically from `{env:HEYELY_API_KEY}`.

## Pick a model

* Add every model you want under `models` keyed by its exact HeyEly catalog ID, then select it with `-m heyely/<id>`, the `model` field, or `/models`.
* OpenCode splits `provider/model` on the very first slash, so catalog IDs containing slashes work seamlessly after `heyely/`.
* Always specify `limit.context` and `limit.output` on custom provider entries; OpenCode only auto-populates limits for its built-in registry providers.
* For models that run over `POST /v1/responses`, switch the `npm` package to `@ai-sdk/openai` (which can also be set per model).
* OpenCode 2 introduces renamed config keys; stick to one schema version per file and consult OpenCode's upgrade notes when moving to 2.x.

## Troubleshooting

| You see                          | Cause                                                          | Fix                                                |
| -------------------------------- | -------------------------------------------------------------- | -------------------------------------------------- |
| `ProviderModelNotFoundError`     | Missing `provider/model` prefix or model omitted from `models` | Run `opencode models` and copy the exact reference |
| Model missing from picker        | Not declared under `models`                                    | Add an entry keyed by the exact catalog ID         |
| `401 missing_api_key`            | `HEYELY_API_KEY` not exported in OpenCode's shell              | Export `HEYELY_API_KEY` before starting OpenCode   |
| Config file ignored              | JSON syntax error                                              | Validate quotes and trailing commas                |
| `AI_APICallError` after updating | Stale cached provider package                                  | Remove `~/.cache/opencode` and relaunch            |
| `404 model_not_found`            | Key under `models` does not match HeyEly's catalog             | Copy the exact ID from the Models page             |
