File size: 5,734 Bytes
8baf122 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | ---
title: "Opencode"
description: "Use Opencode with Bifrost to access any AI provider through a terminal-based coding assistant with virtual keys and observability."
icon: "codepen"
---
[Opencode](https://github.com/sst/opencode) is an AI-powered coding application that supports OpenAI-compatible APIs. By pointing it at Bifrost, you get access to any provider/model in your Bifrost configuration, plus governance features like virtual keys, built-in observability, and per-model options for reasoning effort, thinking budget, and more.

<Note>
If your Allowed Headers are already set to `*`, you can skip this note. If not and you face issues integrating Bifrost with OpenCode, try switching to `*` or adding the specific headers required by your client. By default, Bifrost whitelists: `Content-Type`, `Authorization`, `X-Requested-With`, `X-Stainless-Timeout`, and `X-Api-Key`.
</Note>
## Setup
### 1. Configure OpenCode to work with Bifrost
OpenCode uses a JSON config file (`opencode.json`) to configure providers. Point your provider's `baseURL` to Bifrost.
### Using OpenAI-compatible endpoint
Route OpenAI and other providers through Bifrost's OpenAI endpoint:
```jsonc
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"name": "Bifrost",
"options": {
"baseURL": "http://localhost:8080/openai",
"apiKey": "your-bifrost-key"
},
"models": {
"openai/gpt-5": {},
"anthropic/claude-sonnet-4-5-20250929": {},
"gemini/gemini-2.5-pro": {}
}
}
},
"model": "openai/gpt-5"
}
```
### Using Anthropic endpoint
Route Anthropic models through Bifrost's Anthropic endpoint:
```jsonc
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"name": "Bifrost",
"options": {
"baseURL": "http://localhost:8080/anthropic/v1",
"apiKey": "your-bifrost-key"
},
"models": {
"anthropic/claude-sonnet-4-5-20250929": {}
}
}
},
"model": "anthropic/claude-sonnet-4-5-20250929"
}
```
<Tip>
You can also use the `/connect` command in the OpenCode TUI to configure credentials interactively, then update the `baseURL` in your config file.
</Tip>
## Virtual Keys
When Bifrost has [virtual key authentication](/features/governance/virtual-keys) enabled, set `apiKey` in your provider options to your virtual key:
```jsonc
"options": {
"baseURL": "http://localhost:8080/openai",
"apiKey": "bf-your-virtual-key-here"
}
```
This lets you enforce usage limits, budgets, and access control per user or environment. For team deployments, create a separate virtual key for each team — each key can have its own rate limits, budgets, and provider access rules configured in the Bifrost dashboard.
## Model Selection
Set your default models in `opencode.json`:
```jsonc
{
"model": "openai/gpt-5",
"small_model": "anthropic/claude-haiku-4-5"
}
```
Switch models in the TUI with <key>ctrl</key>+<key>p</key>

- Use powerful models like `openai/gpt-5` or `anthropic/claude-sonnet-4-5-20250929` for complex coding tasks
- Use fast models like `groq/llama-3.3-70b-versatile` for quick completions
- Set `small_model` to a lighter model for faster, lower-cost operations
## Using Multiple Providers
Bifrost routes requests to the correct provider based on the model name. Use the `provider/model-name` format to access any configured provider through the single OpenAI endpoint:
```
anthropic/claude-sonnet-4-5-20250929
openai/gpt-5
gemini/gemini-2.5-pro
mistral/mistral-large-latest
```
You can configure models from different providers with per-model options:
```jsonc
{
"$schema": "https://opencode.ai/config.json",
"theme": "opencode",
"autoupdate": true,
"provider": {
"openai": {
"name": "Bifrost",
"options": {
"baseURL": "http://localhost:8080/openai",
"apiKey": "your-bifrost-key"
},
"models": {
"openai/gpt-5": {
"options": {
"reasoningEffort": "high",
"textVerbosity": "low",
"reasoningSummary": "auto",
"include": [
"reasoning.encrypted_content"
]
}
},
"anthropic/claude-sonnet-4-5-20250929": {
"options": {
"thinking": {
"type": "enabled",
"budgetTokens": 16000
}
}
}
}
}
}
}
```
### Supported Providers
Bifrost supports the following providers with the `provider/model-name` format:
`openai`, `azure`, `gemini`, `vertex`, `bedrock`, `mistral`, `groq`, `cerebras`, `cohere`, `perplexity`, `xai`, `ollama`, `openrouter`, `huggingface`, `nebius`, `parasail`, `replicate`, `vllm`, `sgl`
<Warning>
Non-native models **must support tool use** for OpenCode to work properly. OpenCode relies on tool calling for file operations, terminal commands, and code editing. Models without tool use support will fail on most operations.
</Warning>
<Note>
OpenCode connects to Bifrost via a single endpoint. Bifrost handles routing to the correct provider based on the model name — no per-provider configuration needed.
</Note>
## Observability
All OpenCode traffic through Bifrost is logged. Monitor it at `http://localhost:8080/logs` — filter by provider, model, or search through conversation content to track usage.
## Next Steps
- [Provider Configuration](/quickstart/gateway/provider-configuration) — Configure AI providers in Bifrost
- [Virtual Keys](/features/governance/virtual-keys) — Set up usage limits and access control
|