This guide explains how to configure different agent models with OpenCode.
The default model that comes pre-configured with OpenCode.
docker run -it --rm \
-v $(pwd):/workspace \
-w /workspace \
opencodeai/opencodeTo use other OpenAI-compatible models, set the API endpoint and key:
docker run -it --rm \
-e OPENAI_API_KEY="your-api-key" \
-e OPENAI_API_BASE="https://api.openai.com/v1" \
-v $(pwd):/workspace \
-w /workspace \
opencodeai/opencodedocker run -it --rm \
-e ANTHROPIC_API_KEY="your-anthropic-key" \
-v $(pwd):/workspace \
-w /workspace \
opencodeai/opencode --model claude-3-sonnetCreate a .env file in your project:
# .env
OPENAI_API_KEY=sk-your-key-here
OPENAI_API_BASE=https://api.openai.com/v1
OPENCODE_MODEL=gpt-4Then run:
docker run -it --rm \
--env-file .env \
-v $(pwd):/workspace \
-w /workspace \
opencodeai/opencodeAdd this to your ~/.bashrc or ~/.zshrc for quick access:
alias opencode='docker run -it --rm \
-v $(pwd):/workspace \
-w /workspace \
-e OPENAI_API_KEY \
opencodeai/opencode'Then reload your shell:
source ~/.bashrc # or source ~/.zshrcNow just type opencode from any directory!
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your API key | Yes (for OpenAI) |
OPENAI_API_BASE |
API base URL | No |
OPENCODE_MODEL |
Model to use | No |
ANTHROPIC_API_KEY |
Anthropic API key | Yes (for Claude) |
If you get permission errors with mounted volumes:
docker run -it --rm \
-v $(pwd):/workspace \
-w /workspace \
--user $(id -u):$(id -g) \
opencodeai/opencodeMake sure environment variables are properly set. Check with:
echo $OPENAI_API_KEY