mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
## Description Updates documentation to use the new `/api/v2/ai-gateway/` URLs and `/ai-gateway/` UI paths, following the backend rename in #26475 and frontend route rename in #26569. ## Changes - Update URL references across documentation files from `/api/v2/aibridge/` to `/api/v2/ai-gateway/` - Update UI path reference from `/aibridge/sessions` to `/ai-gateway/sessions` - Update route path references in client setup guides - Covers client setup guides, authentication, monitoring, proxy setup, and provider configuration Addresses https://github.com/coder/coder/pull/26475#issuecomment-4768351217 Refs https://linear.app/codercom/issue/AIGOV-226 > Generated with the assistance of Coder Agents (@ssncferreira)
91 lines
2.2 KiB
Markdown
91 lines
2.2 KiB
Markdown
# OpenCode
|
|
|
|
> [!NOTE]
|
|
> AI Gateway requires the [AI Governance Add-On](../../ai-governance.md).
|
|
> As of Coder v2.32, deployments without the add-on will not be able to
|
|
> access AI Gateway.
|
|
|
|
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/ai-gateway/anthropic/v1"
|
|
}
|
|
},
|
|
"openai": {
|
|
"options": {
|
|
"baseURL": "https://coder.example.com/api/v2/ai-gateway/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/ai-gateway/anthropic/v1",
|
|
"headers": {
|
|
"X-Coder-AI-Governance-Token": "<your-coder-api-token>"
|
|
}
|
|
}
|
|
},
|
|
"openai": {
|
|
"options": {
|
|
"baseURL": "https://coder.example.com/api/v2/ai-gateway/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)
|