Let an AI agent do it
Already use an AI coding agent (any one: Codex, OpenCode, Cursor, another assistant)? Copy this prompt, paste it into that agent and press Enter. It installs OpenCode, writes the settings, saves your key and tests everything. It will ask you for your API key.
See what the prompt says
# Task: connect OpenCode to AllModelAPI
You are a coding agent on my computer. Set up **OpenCode** so it uses **AllModelAPI** as its model provider. Work step by step, tell me briefly what you are doing, and ask me before doing anything not listed here.
## Facts
- Service: AllModelAPI, an API gateway for DeepSeek, Qwen, GLM, Kimi and MiniMax models.
- OpenCode talks to it with the Chat Completions API.
- Base URL: `https://api.allmodelapi.com/v1`
- Main model: `deepseek-v4-pro` (DeepSeek V4 Pro, 1000K context). Fast background model: `deepseek-flash`.
- Model IDs are case-sensitive. Full list: https://api.allmodelapi.com/v1/models
- API key: not included. **Ask me to paste my AllModelAPI API key** (I can create one at https://allmodelapi.com/customer/api-keys).
- Human guide: https://allmodelapi.com/documentation/opencode
## Steps
1. Detect my operating system (macOS, Linux or Windows) and shell.
2. Check whether OpenCode is installed: `opencode --version`. If it is not, install it with the official command:
- macOS: `curl -fsSL https://opencode.ai/install | bash`
- Linux: `curl -fsSL https://opencode.ai/install | bash`
- Windows (PowerShell): `winget install OpenJS.NodeJS.LTS ; npm install -g opencode-ai`
3. Settings file location:
- macOS / Linux: `~/.config/opencode/opencode.json`
- Windows: `%USERPROFILE%\.config\opencode\opencode.json`
4. If the file exists, copy it to `<file>.bak` first. If it contains other settings, **merge**: keep everything unrelated and only add or replace the keys shown below. If it does not exist, create it with exactly this content:
```json
{
"$schema": "https://opencode.ai/config.json",
"model": "allmodelapi/deepseek-v4-pro",
"small_model": "allmodelapi/deepseek-flash",
"provider": {
"allmodelapi": {
"npm": "@ai-sdk/openai-compatible",
"name": "AllModelAPI",
"options": {
"baseURL": "https://api.allmodelapi.com/v1",
"apiKey": "{env:ALLMODELAPI_API_KEY}"
},
"models": {
"deepseek-v4-pro": {
"name": "DeepSeek V4 Pro",
"limit": {
"context": 1000000,
"output": 131072
}
},
"qwen4-max": {
"name": "Qwen 4 Max",
"limit": {
"context": 991808,
"output": 131072
}
},
"glm-5.3": {
"name": "GLM 5.3",
"limit": {
"context": 1000000,
"output": 128000
}
},
"kimi-k3.1-pro": {
"name": "Kimi K3.1 Pro",
"limit": {
"context": 1048576,
"output": 131072
}
},
"deepseek-flash": {
"name": "DeepSeek V4.1 Flash",
"limit": {
"context": 1000000,
"output": 131072
}
},
"qwen3.7-plus": {
"name": "Qwen 3.7 Plus",
"limit": {
"context": 1000000,
"output": 128000
}
},
"qwen3.8-flash": {
"name": "Qwen 3.8 Flash",
"limit": {
"context": 1000000,
"output": 128000
}
},
"glm-5.3-flash": {
"name": "GLM 5.3 Flash",
"limit": {
"context": 1000000,
"output": 128000
}
},
"kimi-k3": {
"name": "Kimi K3",
"limit": {
"context": 1048576,
"output": 131072
}
},
"MiniMax-M3.1-Flash": {
"name": "MiniMax M3.1 Flash",
"limit": {
"context": 1000000,
"output": 131072
}
}
}
}
}
}
```
5. API key: Save it as a persistent user environment variable named `ALLMODELAPI_API_KEY`: append `export ALLMODELAPI_API_KEY="<key>"` to ~/.zshrc (macOS) or ~/.bashrc (Linux), or on Windows run `[Environment]::SetEnvironmentVariable("ALLMODELAPI_API_KEY", "<key>", "User")`. Replace an existing line instead of duplicating it.
6. Verify. Run:
```
opencode --version
opencode run "Reply with just: OK"
```
A short reply such as "OK" means it works. On 401 re-check the key; on 400 "unknown model" re-check the model ID; on 402 I need more credit.
7. Report: what you changed, where the backup is, and how I start OpenCode.
## Rules
- Only touch the files named above. Do not remove other providers, models or settings.
- Never print my full API key in your replies or logs, and never put it in a git repository or project file.
- Use JSON that parses: no comments in JSON, no trailing commas.