# opencode

> A Vikey provider in opencode.jsonc with @ai-sdk/openai-compatible, including small_model for session titles.

opencode calls Vikey through the OpenAI chat completions format.

Tested with opencode 1.19.5 (the latest release) on 13 November 2026.

## Recommended config

1. Keep the API key in an environment variable:

    ```bash
    export VIKEY_API_KEY=YOUR_API_KEY
    ```

2. Add the Vikey provider to `~/.config/opencode/opencode.jsonc` (all projects) or `opencode.jsonc` in the project folder:

    ```jsonc title="~/.config/opencode/opencode.jsonc"
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "vikey": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "Vikey",
          "options": {
            "baseURL": "https://api.vikey.ai/v1",
            "apiKey": "{env:VIKEY_API_KEY}"
          },
          "models": {
            "vikey/agent-gpt": { "name": "Vikey Auto GPT" },
            "vikey/agent-coding": { "name": "Vikey Auto Claude" },
            "anthropic/claude-sonnet-5.5": { "name": "Claude Sonnet 5.5" },
            "openai/gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
            "openai/gpt-6-luna": { "name": "GPT-6 Luna" }
          }
        }
      },
      "model": "vikey/vikey/agent-gpt",
      "small_model": "vikey/openai/gpt-6-luna"
    }
    ```

3. Run `opencode`. Change models with the `/models` command.

### Why each line is there

| Line | Purpose |
| --- | --- |
| `npm` | The adapter for OpenAI-compatible APIs. opencode downloads it automatically on first use. |
| `options.baseURL` | With `/v1`. |
| `options.apiKey` | `{env:VIKEY_API_KEY}` reads the key from the environment, so the key is not in the file. |
| `models` | The models shown in `/models`. Each key must match a Vikey model id exactly. |
| `model` | The default model, written `provider-id/model-id`. Vikey model ids also contain a slash, so it looks like `vikey/vikey/agent-gpt` or `vikey/openai/gpt-6.1-sol`. |
| `small_model` | The model for small tasks such as session titles. Pick a cheap one so these cost almost nothing. |

**The providers format on opencode's site**

opencode's site already shows a newer `providers` format with `package` and `settings`. opencode 1.19.5 ignores that format with `cannot be represented in V1` and then fails with `Model not found`. Use the `provider` format above until an opencode release supports the new one.

## Another way to enter the key

If you would rather not use an environment variable, remove the `apiKey` line from the config, run `opencode`, type `/connect`, choose **Vikey** and paste the API key. opencode keeps it in its own credential store.

## Test the connection

```bash
opencode run "reply with the word ok"
```

On success opencode prints `ok` together with the model it used.

## Common problems

| What you see | Cause | Fix |
| --- | --- | --- |
| `Model not found: vikey/...` | The model is not in `models`, or the unsupported `providers` format is used | Add the model id to `models` and use the `provider` format |
| `401` | `VIKEY_API_KEY` is not exported in this terminal | Export it again, or use `/connect` |
| Session titles use an expensive model | `small_model` is not set | Set `small_model` to a cheap model such as `vikey/openai/gpt-6-luna` |

Source: https://docs.vikey.ai/en/agents/opencode/
