mirror of
https://github.com/coder/coder.git
synced 2026-11-08 05:32:55 +08:00
## Summary Follows up on https://github.com/coder/coder/pull/24032 Renames "Coder session token" to "Coder API token" in AI Gateway client documentation pages. Also renames the `CODER_SESSION_TOKEN` env var to `CODER_API_TOKEN` in Codex CLI examples and Copilot proxy configuration. Note: "Coder session token" is still used in some parts of the documentation where it make sense. --------- Co-authored-by: Susana Ferreira <susana@coder.com>
86 lines
2.1 KiB
Markdown
86 lines
2.1 KiB
Markdown
# OpenCode
|
|
|
|
OpenCode supports both OpenAI and Anthropic models and can be configured to use AI Gateway by setting custom base URLs for each provider.
|
|
|
|
## Centralized API Key
|
|
|
|
You can configure OpenCode to connect to AI Gateway by setting the following configuration options in your OpenCode configuration file (e.g., `~/.config/opencode/opencode.json`):
|
|
|
|
```json
|
|
{
|
|
"$schema": "https://opencode.ai/config.json",
|
|
"provider": {
|
|
"anthropic": {
|
|
"options": {
|
|
"baseURL": "https://coder.example.com/api/v2/aibridge/anthropic/v1"
|
|
}
|
|
},
|
|
"openai": {
|
|
"options": {
|
|
"baseURL": "https://coder.example.com/api/v2/aibridge/openai/v1"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
To authenticate with AI Gateway, get your **[Coder API token](../../../admin/users/sessions-tokens.md#generate-a-long-lived-api-token-on-behalf-of-yourself)** and replace `<your-coder-api-token>` in `~/.local/share/opencode/auth.json`
|
|
|
|
```json
|
|
{
|
|
"anthropic": {
|
|
"type": "api",
|
|
"key": "<your-coder-api-token>"
|
|
},
|
|
"openai": {
|
|
"type": "api",
|
|
"key": "<your-coder-api-token>"
|
|
}
|
|
}
|
|
```
|
|
|
|
## BYOK (Personal API Key)
|
|
|
|
Set the following in `~/.config/opencode/opencode.json`, including the `X-Coder-AI-Governance-Token` header with your Coder API token:
|
|
|
|
```json
|
|
{
|
|
"$schema": "https://opencode.ai/config.json",
|
|
"provider": {
|
|
"anthropic": {
|
|
"options": {
|
|
"baseURL": "https://coder.example.com/api/v2/aibridge/anthropic/v1",
|
|
"headers": {
|
|
"X-Coder-AI-Governance-Token": "<your-coder-api-token>"
|
|
}
|
|
}
|
|
},
|
|
"openai": {
|
|
"options": {
|
|
"baseURL": "https://coder.example.com/api/v2/aibridge/openai/v1",
|
|
"headers": {
|
|
"X-Coder-AI-Governance-Token": "<your-coder-api-token>"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
Set your personal API keys in `~/.local/share/opencode/auth.json`:
|
|
|
|
```json
|
|
{
|
|
"anthropic": {
|
|
"type": "api",
|
|
"key": "<your-anthropic-api-key>"
|
|
},
|
|
"openai": {
|
|
"type": "api",
|
|
"key": "<your-openai-api-key>"
|
|
}
|
|
}
|
|
```
|
|
|
|
**References:** [OpenCode Documentation](https://opencode.ai/docs/providers/#config)
|