---
title: "OpenCode API key and custom provider setup (tested on 2.4.4)"
description: "Add an API key and custom OpenAI-compatible provider in OpenCode 2, debug ignored variables, image input and exact errors. Tested on OpenCode 2.4.4."
url: "https://voracompute.com/blog/opencode-api-key"
lang: "en"
updated: "2026-12-04"
---

[← Back to blog](https://voracompute.com/blog)

Technical guide · OpenCode

# Add an API key and custom provider to OpenCode 2

This guide covers where OpenCode 2 reads API keys, adding a custom provider, why environment variables get ignored, image input and exact error messages. Every step was tested on OpenCode 2.4.4 on 3 December 2026. The examples use Vora Compute's API for Qwen4 35B-A3B (requests using `qwen3.8-27b` route automatically to `qwen4-35b-a3b`) and work for any OpenAI-compatible API by changing three values.

## Where OpenCode 2 takes an API key from

OpenCode 2 reads a provider's API key from three places, in this order when more than one is set: a saved key first, then an environment variable, then the config file. We tested every combination.

**Where OpenCode 2 takes an API key from**

|  | Saved key | Environment variable | Key in the config file |
| --- | --- | --- | --- |
| **Set it with** | `/connect` in the app, or `opencode auth login` | A variable named in the provider's `env` list | `settings.apiKey`: the key itself, `{env:NAME}` or `{file:path}` |
| **Where it lives** | OpenCode's local database, as plain text | The environment of the process that serves the request | The config file, or the file it points to |
| **Works from any terminal** | Yes | Only if that process has the variable | Yes for the key itself and `{file:path}`; `{env:NAME}` behaves like a variable |
| **Order when several are set** | First | Second | Third |
| **Remove it with** | `opencode auth logout` | Unset the variable | Delete the line |

## Add an API key for a provider in OpenCode's list

Inside OpenCode, `/connect` opens a searchable list of providers (`/login` and `/auth` open the same list); choose one and paste your key. From an interactive terminal, run the command below to open the same list.

Terminal

```
opencode auth login
```

Run `opencode auth list` to see what is saved. OpenCode's own models are an exception: choose OpenCode in that list and sign in, with no key to paste.

## Add a custom OpenAI-compatible provider

1. Save this (a minimal config that worked against Vora's live API) as `opencode.json` in your project folder, or `~/.config/opencode/opencode.json` for every project (`opencode.jsonc` works too). For another provider, change three values: the provider id (`vora`), `baseURL` and the model id (`qwen4-35b-a3b`); `name` and `env` are yours to choose.

opencode.json

```
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "vora": {
      "name": "Vora Compute",
      "package": "@opencode/ai/providers/openai-compatible",
      "env": ["VORA_API_KEY"],
      "settings": { "baseURL": "https://api.voracompute.com/v1" },
      "models": { "qwen4-35b-a3b": {} }
    }
  },
  "model": "vora/qwen4-35b-a3b"
}
```

1. Create a Vora API key in the [Vora console](https://inference.voracompute.com/console/keys), then save it. One prompt appears, "Manually enter API Key", and input is masked. In the app, `/connect` lists the provider by its `name` for the same key.

Terminal

```
opencode auth login vora
```

1. Check the setup. The first command should print `Vora Compute Vora Compute stored`, and the second should list `vora/qwen4-35b-a3b`.

Terminal

```
opencode auth list
opencode models
```

1. Run a request. The first output line names the answering model: `> build · qwen4-35b-a3b`.

Terminal

```
opencode run -m "vora/qwen4-35b-a3b" "Say OK."
```

A provider must be defined in the config before its key can be saved: OpenCode 2.4.4 has no free-form entry for unknown providers. The `model` line sets the default, so `opencode` alone starts on it. See [OpenCode's provider docs](https://opencode.ai/docs/providers/) for reference.

## What a minimal config leaves to defaults

Declaring a model as `{}` works, but OpenCode 2.4.4 fills in the defaults below.

**What a minimal config leaves to defaults**

| If you leave out | OpenCode 2.4.4 assumes | Set it when |
| --- | --- | --- |
| `limit` | 200,000 tokens of context and 32,000 of output | The model's real limits differ |
| `capabilities.reasoning.effort` | Levels `low`, `medium` and `high`, with no `none` | You want `none`, or the model takes other levels |
| `capabilities.input` | Text and images | The endpoint takes text only |
| `compatibility.maxTokensField` | The output limit is sent as `max_completion_tokens` | The API only reads `max_tokens` |
| `name` | The ids are shown (`vora`, `qwen4-35b-a3b`) | You want readable names in lists |

For our complete Qwen4 35B-A3B config on Vora (1M context limit, reasoning levels and timeouts), see the [OpenCode pricing and setup guide](https://voracompute.com/blog/opencode-pricing).

## When OpenCode ignores an environment variable

The process serving the request reads the variable. That is OpenCode 2's shared background server when one is running. It keeps the environment it started with. When no server is running, `opencode run` serves the request itself, with your shell's environment.

So the same `export` can work in one terminal and fail in another. If the server started before your `export`, no key is sent: OpenCode says nothing, you see the provider's error (`Missing API key` on Vora), and `opencode auth list` prints `No authenticated integrations`. An unset `{env:NAME}` becomes an empty string with no warning.

Three tested options:

1. Save the key as shown above, which works through the background server.
2. Point `settings.apiKey` at a file (absolute, `~/`, or relative to the config). OpenCode reads the file when needed, so this also works through a background server that never saw the variable.

opencode.json

```
"settings": {
  "baseURL": "https://api.voracompute.com/v1",
  "apiKey": "{file:~/.secrets/vora-key}"
}
```

1. Run `--standalone` for a private server reading your shell, useful in scripts and CI.

Terminal

```
export VORA_API_KEY=vora_sk_...
opencode --standalone
```

For the background server only, `opencode service set env VORA_API_KEY vora_sk_...` stores plain text in `~/.config/opencode/service.json` (`opencode service unset env VORA_API_KEY` removes it).

## Image input with a custom model

Guides for OpenCode 1 tell you to declare image support. OpenCode 2 enables it by default for custom models, so you declare the opposite case instead. With `"input": ["text", "image"]` or nothing declared, a PNG reached Vora and Qwen3.8 27B answered a question about it. If an endpoint accepts text only, set it as below.

opencode.json

```
"models": {
  "my-text-model": {
    "capabilities": { "input": ["text"] }
  }
}
```

In our test, OpenCode then sent the model a short text note in place of the image, and the model answered that it could not see it, with no error.

## A broken config falls back to a free model

In our test, removing one comma made OpenCode 2.4.4 skip the file without a message. With the file skipped, no `model` line was left, and `opencode run` chose one of OpenCode's own free models for the request (`big-pickle` in that test). The same happened with a valid file whose `model` line was missing, or named a provider or model that the config does not define (`seaglass-alpha-free`). No account was connected and outbound traffic was blocked, so nothing was sent. Trailing commas and comments are accepted; unknown config fields are dropped silently.

Two checks: the first output line names the model, and `opencode debug config` lists loaded files (keys as `***`); an unlisted file did not parse. Passing `-m` fails loudly instead of falling back.

## Coming from OpenCode 1

OpenCode 2.4.4 still reads the OpenCode 1 format: it converts it in memory, with no warning, and leaves the file untouched. An unchanged OpenCode 1 config worked in our test with its key. Write new providers in the OpenCode 2 format, and never mix both inside one provider: OpenCode 2 fields such as `compatibility` are dropped there.

**Coming from OpenCode 1**

| OpenCode 1 | OpenCode 2 |
| --- | --- |
| `provider` | `providers` |
| `npm: "@ai-sdk/openai-compatible"` | `package: "@opencode/ai/providers/openai-compatible"` |
| `options.baseURL` | `settings.baseURL` |
| `options.apiKey` | `settings.apiKey` |
| `tool_call`, `modalities` | `capabilities` |
| Keys in `auth.json` | Keys in the local database, imported once |

## Errors and what they mean

The two messages about the API key and the one about a model that does not exist are worded by Vora's API (another provider words its own); the rest come from OpenCode.

### API key errors

**API key errors**

| What you see | Cause | What to do |
| --- | --- | --- |
| `Missing API key. Send the header Authorization: Bearer vora_sk_…` | The request left with no key: the process that served it does not have your variable | Save the key with `opencode auth login vora` |
| `Invalid API key. Create one at https://inference.voracompute.com/console/keys.` | The key is wrong, or an older saved key wins over your variable | Check `opencode auth list`, then log out and save the right key |
| `Integration not found: vora` | `opencode auth login vora` ran where no config defines `vora` | Run it in the project folder, or put the provider in the global config |
| `API key input requires an interactive terminal` | `opencode auth login` ran without a terminal | Use `--standalone` with a variable, or a `{file:path}` key |

### Config file errors

**Config file errors**

| What you see | Cause | What to do |
| --- | --- | --- |
| `Model unavailable: vora/qwen4-35b-a3b` | The provider or model is not in the config that loaded: a typo, or a file with a JSON error | Run `opencode debug config` and check that your file is listed |
| `> build · big-pickle` | No valid `model` line, so OpenCode chose one of its free models | Fix the `model` line, or pass `-m` |
| `Cannot initialize vora/qwen4-35b-a3b: Cannot find package '@opencode/ai'…` | The `package` line is misspelled | Copy the `package` line exactly |
| `Unsupported package for vora/qwen4-35b-a3b` | The `package` line is missing | Add the `package` line |

### Request errors

**Request errors**

| What you see | Cause | What to do |
| --- | --- | --- |
| `Variant unavailable for vora/qwen4-35b-a3b: none` | That reasoning level is not declared for the model | Declare it in `capabilities.reasoning.effort`, or use `low`, `medium` or `high` |
| `Provider request failed with HTTP 404 (POST …/chat/completions)` | `baseURL` does not end in `/v1` | End `baseURL` with `/v1` |
| `The model 'qwen4-35b-a3b-x' does not exist. See GET /v1/models.` | The model id is not one the API serves | Use an id from the provider's model list |

## Frequently asked questions

**Where does OpenCode store API keys?**

In a local SQLite database as plain text. Run `opencode debug paths db` to print its path. OpenCode 1 stored keys in `auth.json`, which OpenCode 2 imports once.

**How do I remove or replace a saved key?**

Run `opencode auth logout vora "Vora Compute"` (the second argument is the label from `opencode auth list`), then save the new key with `opencode auth login vora`. Until removed, a saved key keeps overriding an environment variable.

**Why does the desktop app have no form for a custom provider?**

OpenCode removed the custom provider entry from the connect dialog in version 2.2.0, and on 3 December 2026 the request to restore it was still open. Define custom providers in `opencode.json` as shown above.

**How do I set a default reasoning level?**

A `#level` suffix on the root `model` line is ignored. Set it on an agent (`"agents": { "build": { "model": "vora/qwen4-35b-a3b#medium" } }`), per run with `-m "vora/qwen4-35b-a3b#high"`, or inside the app with `/variants`.

**Where do I get an API key for OpenCode's own models?**

Inside OpenCode, sign in through `/connect` (choose OpenCode). For other tools, create an `oc_sk_` key in the OpenCode Console under Account, Personal API keys. Use base URL `https://opencode.ai/inference`, or `https://opencode.ai/inference/go` for OpenCode Go.

## Related guides

- [OpenCode pricing](https://voracompute.com/blog/opencode-pricing): current limits and costs across the free tier, Console models, Go and custom providers.
- [OpenCode vs Claude Code](https://voracompute.com/blog/opencode-vs-claude-code): how both agents handle models, endpoints and daily coding tasks.
- [Connect coding agents to Vora Compute](https://voracompute.com/blog/for-developers): tested setups for Cline, Continue, Aider, Codex and more.
- [Qwen4 35B-A3B API](https://voracompute.com/blog/qwen-api): model capabilities, 1M context window and zero-retention EU hosting.

## Get a Vora API key for OpenCode.

Flat rate on European GPUs with zero API retention: €9.90/month or €99/year (€8.25/month) for the first year through 31 December 2026 (then €29/month or €288/year, excl. VAT). Up to 4 parallel requests.

[Explore inference](https://voracompute.com/inference#pricing)
