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.
| 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.
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
- Save this (a minimal config that worked against Vora's live API) as
opencode.jsonin your project folder, or~/.config/opencode/opencode.jsonfor every project (opencode.jsoncworks too). For another provider, change three values: the provider id (vora),baseURLand the model id (qwen4-35b-a3b);nameandenvare yours to choose.
{
"$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"
}
- Create a Vora API key in the Vora console, then save it. One prompt appears, "Manually enter API Key", and input is masked. In the app,
/connectlists the provider by itsnamefor the same key.
opencode auth login vora
- Check the setup. The first command should print
Vora Compute Vora Compute stored, and the second should listvora/qwen4-35b-a3b.
opencode auth list
opencode models
- Run a request. The first output line names the answering model:
> build · qwen4-35b-a3b.
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 for reference.
What a minimal config leaves to defaults
Declaring a model as {} works, but OpenCode 2.4.4 fills in the defaults below.
| 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.
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:
- Save the key as shown above, which works through the background server.
- Point
settings.apiKeyat 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.
"settings": {
"baseURL": "https://api.voracompute.com/v1",
"apiKey": "{file:~/.secrets/vora-key}"
}
- Run
--standalonefor a private server reading your shell, useful in scripts and CI.
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.
"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.
| 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
| 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
| 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
| 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 dbto print its path. OpenCode 1 stored keys inauth.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 fromopencode auth list), then save the new key withopencode 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.jsonas shown above. - How do I set a default reasoning level?
- A
#levelsuffix on the rootmodelline 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 anoc_sk_key in the OpenCode Console under Account, Personal API keys. Use base URLhttps://opencode.ai/inference, orhttps://opencode.ai/inference/gofor OpenCode Go.
Related guides
- OpenCode pricing: current limits and costs across the free tier, Console models, Go and custom providers.
- OpenCode vs Claude Code: how both agents handle models, endpoints and daily coding tasks.
- Connect coding agents to Vora Compute: tested setups for Cline, Continue, Aider, Codex and more.
- Qwen4 35B-A3B API: model capabilities, 1M context window and zero-retention EU hosting.