OpenCode API key setup
OpenCode API Key Setup: Base URL, Provider & Models
OpenCode with a third-party API needs three things: an API key, a base_url, and a provider config.
Pay as you go for Claude, Kimi, GLM, and more: get an API key, set base_url and provider in opencode.json, then confirm with a test message.
{
"$schema": "https://opencode.ai/config.json",
"model": "aicodewith-anthropic/claude-opus-5-5",
"provider": {
"aicodewith-anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "AI Code With Anthropic",
"options": {
"baseURL": "https://api.aicodewith.ai",
"apiKey": "{env:AICODEWITH_API_KEY}"
},
"models": {
"claude-opus-5-5": {
"name": "Claude Opus 5.5"
}
}
}
}
}OpenCode not installed?
This page configures the OpenCode terminal CLI. If opencode --version already prints a version, skip ahead to the quick setup.
Basic install command
curl -fsSL https://opencode.ai/install | bashOr install globally with npm (this exact command is commonly searched)
npm install -g opencode-ai@latestInstallation succeeds when opencode --version prints a version number.
Secure quick setup
Pick a model, copy the config, save the file, and verify the connection in about 3 minutes.
- Claude Opus 5.5 (claude-opus-5-5)
- Claude Sonnet 5.5 (claude-sonnet-5-5)
- DeepSeek V4.1 Flash (deepseek-flash)
- GLM-5.3 (glm-5.3)
- Kimi K2.7 Code (kimi-k2.7-code)
- GPT-6 Astra (gpt-6-astra)
- Claude Fable 5.1 (claude-fable-5-1)
- Fable 5 (claude-fable-5)
- Haiku 4.5 (claude-haiku-4-5-20251001)
- Opus 4.6 (claude-opus-4-6)
- Opus 4.7 (claude-opus-4-7)
- Opus 4.8 (claude-opus-4-8)
- Opus 5 (claude-opus-5)
- Sonnet 4.6 (claude-sonnet-4-6)
- Sonnet 4.6 (claude-4.6-sonnet-medium)
- Sonnet 5 (claude-sonnet-5)
- DeepSeek V4 Flash (deepseek-v4-flash)
- DeepSeek V4 Pro (deepseek-v4-pro)
- 2.5 Pro (gemini-2.5-pro)
- 3 Pro Preview (gemini-3-pro-preview)
- 3.1 Pro Preview (gemini-3.1-pro-preview)
- Gemini 3 Flash Preview (gemini-3.5-flash)
- Gemini 3.6 Flash (gemini-3.6-flash)
- Gemini 3.7 Flash (gemini-3.7-flash)
- Gemini 3.8 Flash (gemini-3.8-flash)
- GLM 5.1 (glm-5.1)
- GLM 5.2 (glm-5.2)
- Grok 4.5 (grok-4.5)
- Grok 4.6 (grok-4.6)
- Grok 4.7 (grok-4.7)
- Grok 4.7 Build Fast (grok-4.7-build-fast)
- Kimi K2.6 (kimi-k2.6)
- Kimi K3 (kimi-k3)
- GPT-5.5 (gpt-5.5)
- GPT-5.6 Sol (gpt-5.6-sol)
- GPT-5.6 Terra (gpt-5.6-terra)
- GPT-6 Sol (gpt-6-sol)
- Claude Haiku 5.5 (claude-haiku-5-5)
- Gemini 3 Flash Preview (gemini-3-flash-preview)
- GPT-6.1 Sol (gpt-6.1-sol)
- Jev 1.13 (jev-1.13.0)
- Jev Latest (jev-latest)
- Grok 4.5 (grok-4.5)
- Grok 4.6 (grok-4.6)
- Grok 4.7 (grok-4.7)
- Grok 4.7 Build Fast (grok-4.7-build-fast)
1. Choose a model
The current catalog contains 46 models.
2. Copy the config
- Provider
aicodewith-anthropic- npm adapter
@ai-sdk/anthropic- Base URL
https://api.aicodewith.ai- Model ID
claude-opus-5-5
{
"$schema": "https://opencode.ai/config.json",
"model": "aicodewith-anthropic/claude-opus-5-5",
"provider": {
"aicodewith-anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "AI Code With Anthropic",
"options": {
"baseURL": "https://api.aicodewith.ai",
"apiKey": "{env:AICODEWITH_API_KEY}"
},
"models": {
"claude-opus-5-5": {
"name": "Claude Opus 5.5"
}
}
}
}
}3. Save opencode.json and set the API key
Back up an existing opencode.json, then merge both model and provider from the generated content. Keep other Providers and store the real key only in a local environment variable.
Open the API key pageSave the config file
- 1. Open your system terminal
2. Run the command below to open the config file (created automatically if missing):
notepad "$env:USERPROFILE\.config\opencode\opencode.json"
- 3. Paste the config copied in step 2 and save it
Press Ctrl+S on Windows/Linux, Cmd+S on macOS.
Set the API key (replace your-key with your real key)
Temporary (only valid in the current terminal session)
$env:AICODEWITH_API_KEY = "your-key"
Lost when the terminal closes; good for a quick test.
Persistent (written to user config; new terminals pick it up)
setx AICODEWITH_API_KEY "your-key"
Open a new terminal or reload your shell config, then restart OpenCode.
4. Restart and verify
- Run in your system terminal
opencode - Type inside OpenCode
/modelsconfirm the Provider and Model ID match the page selection - Send in the chat
Reply with exactly: connection successful - confirm OpenCode displays a reply and match its time and model in AI Code With usage records
Usage records confirm that a request reached AI Code With. Determine success from the status, response content, and the reply actually shown in OpenCode.
How does OpenCode connect to a third-party API?
OpenCode uses a custom Provider to send requests to the API service you choose: the Provider is the namespace that tells OpenCode which service to call, the API key handles authentication, the Base URL is the third-party API endpoint, and the Model ID selects the actual model.
Once saved, requests flow along OpenCode → Provider → Base URL → model API. After a /models check and a short test message, you can match the request against your usage records by time and model.
If setup fails, check these 4 things first
Each item links to a dedicated troubleshooting article with detailed steps.
401 Unauthorized
View detailed troubleshooting →Usually the API key is invalid, mistyped, or not read correctly. Check that AICODEWITH_API_KEY is set without extra spaces and that OpenCode starts from the same terminal.
Model Not Found
View detailed troubleshooting →The Model ID does not match the Provider config, or the channel does not support the model. Compare the generated Model ID and Provider pair character by character.
Base URL / 404
View detailed troubleshooting →Usually the Base URL is wrong. Copy the value generated on this page and do not append /v1, /v1beta, or invent an endpoint path.
Config not applied / Provider missing
View detailed troubleshooting →Check the config file path, that the JSON is valid, and that OpenCode reloaded the file. Reopen OpenCode after saving, then run /models.
Frequently asked questions
What should the Base URL be?
Copy the Base URL generated by the quick setup above. Do not append /v1 or /v1beta manually.
Where is the OpenCode config file?
This page generates ~/.config/opencode/opencode.json. Paths can vary by install method and version, so compare it with the current OpenCode docs.
How do I confirm the setup works?
Run /models to select the model, send a short message, then match the request by time and model in AI Code With usage records.
Which models are supported?
Claude, GPT, Gemini, DeepSeek, GLM, Kimi, and Grok, among others. Click "View all models" to browse the full catalog.
Need full installation or troubleshooting docs?
See the OpenCode setup docs for full installation guides, every config parameter, the complete model list, and troubleshooting.
Open the OpenCode setup docs