> Keiro Labs API documentation - OpenCode Setup
> Page: https://docs.keirolabs.ai/opencode.html
> Markdown: https://docs.keirolabs.ai/opencode.md
> Agent index: https://docs.keirolabs.ai/llms.txt
> API base URL: https://api.keirolabs.ai/v1
> Auth: send "Authorization: Bearer <api-key>" with a key created in the
> Keiro console (https://console.keirolabs.ai/api-keys). Use credentials saved by
> `keiro setup`, or resolve the key from a secret manager or an owner-only
> secret file and pass it to the client explicitly. Never read another
> provider's variable, and never put raw key material in environment
> variables, code, docs, or logs.

# Use eb1 with OpenCode

OpenCode is an open-source terminal coding agent with configurable model
providers. Register Keiro as an OpenAI-compatible provider in OpenCode's own
configuration, then select an enabled public eb1 model.

## Before you configure

1. Open [API keys](https://console.keirolabs.ai/api-keys).
2. Create a dedicated key for this OpenCode installation.
3. Keep the newly revealed secret available in your password manager until
   setup is complete.

A dedicated key lets you inspect and revoke OpenCode traffic independently from
production application traffic.

## Install and configure

Install OpenCode with the `opencode-ai` package, or run it through `npx`:

```bash
npm install --global opencode-ai@latest
# or
npx --yes opencode-ai@latest --help
```

OpenCode reads provider settings from `opencode.json`. Add a Keiro entry that
uses the OpenAI-compatible provider package and the public Keiro API base URL:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "keiro/eb1-preview",
  "small_model": "keiro/eb1-preview",
  "provider": {
    "keiro": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Keiro",
      "options": {
        "baseURL": "https://api.keirolabs.ai/v1",
        "apiKey": "{env:KEIRO_API_KEY}",
        "timeout": 120000,
        "headerTimeout": 60000,
        "chunkTimeout": 60000
      },
      "models": {
        "eb1-preview": {
          "name": "eb1-preview",
          "limit": { "context": 400000, "output": 32000 }
        },
        "eb1-frontier-preview": {
          "name": "eb1-frontier-preview",
          "limit": { "context": 400000, "output": 32000 }
        },
        "eb1-fast-preview": {
          "name": "eb1-fast-preview",
          "limit": { "context": 240000, "output": 32000 }
        },
        "eb1-efficient-preview": {
          "name": "eb1-efficient-preview",
          "limit": { "context": 400000, "output": 32000 }
        }
      }
    }
  }
}
```

Set `KEIRO_API_KEY` only for the OpenCode process, or source it from your
approved local secret manager. Do not place raw secret bytes in a shared project
file or commit them to a repository. Avoid `opencode debug config` with a real
key unless the output is fully controlled; it can print resolved secrets.

The `limit.context` values mirror each model's published `context_window` in
[`/v1/models`](api-reference.md). `limit.output` is the generation cap OpenCode
requests per turn; raise or lower it to match your plan's output-token budget.

## Models

Start with `eb1-preview`. Switch models when the task has a clear quality,
latency, or cost requirement:

- `eb1-preview`
- `eb1-frontier-preview`
- `eb1-fast-preview`
- `eb1-efficient-preview`

See [Models](models.md) for what each model is for.

## Authentication

The key is sent as `Authorization: Bearer`, the same credential form as every
other public endpoint. See [API auth](api-auth.md). A `401` means the configured
key is missing, invalid, or revoked.

Requests from OpenCode appear in Keiro Usage and Logs like other API traffic.
For local validation, prefer `opencode run --format json` or a sanitized session
export for token totals. `opencode stats` can remain zero for custom model
entries unless cost metadata is configured.

## Rotate the OpenCode key

1. Create a replacement dedicated key in the console.
2. Update the key in OpenCode's secret store or local configuration.
3. Start OpenCode and verify a harmless request.
4. Delete the old key in the console.

## Related pages

- [API keys](api-keys.md)
- [API auth](api-auth.md)
- [Models](models.md)
- [Responses](responses.md)
- [Usage and billing](usage-billing.md)
- [OpenCode provider documentation](https://opencode.ai/docs/providers/)
