Model Configuration
Configure LLM providers, models, and gateway settings.
The agent connects to the OpenCode Go gateway, which routes requests to available models. The gateway client lives in internal/llm/gateway/client.go and the model catalog is embedded from internal/llm/gateway/models.json.
Architecture
All communication uses SSE (Server-Sent Events) streaming for real-time output.
Configuration
Environment variables control model selection:
# Required
AI_GATEWAY_API_KEY=...
# Optional
AI_GATEWAY_BASE_URL=https://opencode.ai/zen/go/v1
AI_GATEWAY_MODEL=opencode-go/deepseek-v4-proModel resolution order: explicit /model slash-command choice → AI_GATEWAY_MODEL env → models.json default → compile-time defaultModel constant.
The gateway client strips the opencode-go/ prefix before sending the bare model id to the API. For example, opencode-go/deepseek-v4-pro becomes deepseek-v4-pro on the wire.
Model Catalog
The model catalog (models.json) is embedded into the binary at compile time via //go:embed. Available models:
| Model ID | Provider |
|---|---|
opencode-go/deepseek-v4-pro | DeepSeek (default) |
opencode-go/deepseek-v4-flash | DeepSeek |
opencode-go/glm-5.1 | GLM |
opencode-go/glm-5.2 | GLM |
opencode-go/kimi-k2.6 | Moonshot |
opencode-go/kimi-k2.7-code | Moonshot |
opencode-go/mimo-v2.5 | Mimo |
opencode-go/mimo-v2.5-pro | Mimo |
Default: opencode-go/deepseek-v4-pro
Runtime Model Switching
Type /model in the TUI composer to open the interactive model picker:
/modelwith no argument opens the full picker/model <provider>/<model>switches directly/model <provider>lists that provider's models
Switching is live: no restart required. The status bar updates to show the new model name.
Gateway Retry Logic
The gateway HTTP client retries on transient failures with exponential backoff and jitter:
| Attempt | Delay |
|---|---|
| 1st | Immediate |
| 2nd | ~1s + jitter |
| 3rd | ~2s + jitter |
| 4th | ~4s + jitter |
Only transient errors trigger retries: HTTP 429/500/502/503/504, connection resets, refused connections, EOF, broken pipe, DNS failures, and timeouts.
Gateway URL Security
The config loader (internal/config/gateway.go) enforces HTTPS for non-loopback hosts. If AI_GATEWAY_BASE_URL uses http:// for anything other than localhost / 127.x.x.x / ::1, the URL is rewritten to https:// and a warning is emitted. Invalid URLs fall back to the default OpenCode Go endpoint.