How I configured OpenCode with 5 AI providers — getting Claude Opus 4.6, Gemini 3 Pro, and 6 Chinese models all for $0/month.
The Goal
The 5 Providers
| Provider | SDK | Auth | Models | Cost |
|---|---|---|---|---|
| Antigravity (OAuth) | @ai-sdk/google | Google OAuth | Gemini Pro/Flash + Claude | Free (Google Cloud quota) |
| Gemini (API Key) | @ai-sdk/google | API Key | Flash only | Free tier |
| Ark Coding Plan | @ai-sdk/openai-compatible | API Key | 6 Chinese models | Free (Volcengine plan) |
| Claude (Relay) | @ai-sdk/anthropic | API Key | Opus/Sonnet/Haiku | Relay credits |
| LM Studio | OpenAI-compatible | None | Local models | Free (local) |
1. Antigravity — Free Claude Opus via Google OAuth
Bash
opencode auth login google
# Opens browser → Google account → authorize → done
Json
"google": {
"id": "google",
"name": "🪐 Antigravity",
"api": "@ai-sdk/google",
"models": {
"antigravity-gemini-3-pro": {
"name": "💎 Gemini 3 Pro (AG)"
},
"antigravity-gemini-3-flash": {
"name": "⚡ Gemini 3 Flash (AG)"
},
"antigravity-claude-opus-4-6-thinking": {
"name": "🟣 Claude Opus 4.6 (AG)"
}
},
"whitelist": [
"antigravity-gemini-3-pro",
"antigravity-gemini-3-flash",
"antigravity-claude-opus-4-6-thinking"
]
}
2. Gemini API Key — Free Flash Models
Trap: Google Student Pro / Google One AI Premium gives you unlimited Gemini access in the web app — but provides zero free API quota for Pro models. Only Flash has free API access.Since Antigravity already handles Pro, I set up a separate gemini provider just for Flash as a fallback:
Json
"gemini": {
"id": "gemini",
"name": "💎 Gemini",
"api": "@ai-sdk/google",
"apiKey": "AIzaSy...",
"models": {
"gemini-2.5-flash": { "name": "⚡ Gemini 2.5 Flash" },
"gemini-3-flash-preview": { "name": "⚡ Gemini 3 Flash Preview" }
}
}
3. Ark Coding Plan — Free Chinese Models
| Regular Ark | Coding Plan | |
|---|---|---|
| SDK | @ai-sdk/openai | @ai-sdk/openai-compatible |
| Endpoint | /api/v3 | /api/coding/v3 |
| API Key | Regular key | Coding Plan key |
Json
"ark-coding": {
"id": "ark-coding",
"name": "🌋 Ark Coding Plan",
"api": "@ai-sdk/openai-compatible",
"baseURL": "https://ark.cn-beijing.volces.com/api/coding/v3",
"apiKey": "your-coding-plan-key",
"models": {
"ark-code-latest": { "name": "🤖 Auto Router" },
"doubao-seed-code": { "name": "🫘 Doubao Seed Code" },
"kimi-k2.5": { "name": "🌙 Kimi K2.5" },
"deepseek-v3.2": { "name": "🐋 DeepSeek V3.2" },
"kimi-k2-thinking": { "name": "🌙 Kimi K2 Thinking" }
}
}
4. The Whitelist Problem
Json
"google": {
"whitelist": [
"antigravity-gemini-3-pro",
"antigravity-gemini-3-flash",
"antigravity-claude-opus-4-6-thinking"
],
"models": { ... }
}
Bash
rm ~/.cache/opencode/models.json
5. Gemini + MCP Schema Incompatibility
- anyOf / oneOf
- $ref / $defs
- const
- Resolving $ref → inline definitions
- Flattening anyOf/oneOf → first non-null option
- Converting const → enum: [value]
6. Server Management & Shell Aliases
Bash
# Attach to server (start if needed)
alias o='...' # polls curl -sf http://127.0.0.1:4096
# Restart via LaunchAgent
function orestart() {
ostop
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/ai.opencode.server.plist
# Wait for port ready (up to 10s)
for i in $(seq 1 20); do
curl -sf http://127.0.0.1:4096 >/dev/null 2>&1 && break
sleep 0.5
done
}
Final Result
Text
🔮 Antigravity → Claude Opus 4.6, Gemini 3 Pro/Flash (free via OAuth)
💎 Gemini API → Gemini Flash (free tier)
🌋 Ark Coding → DeepSeek, Kimi, Doubao, GLM (free plan)
🟣 Claude Relay → Full Claude lineup (relay credits)
🖥️ LM Studio → Qwen, Codestral, etc. (local)
我把 OpenCode 配了 5 个 AI Provider——Claude Opus 4.6、Gemini 3 Pro、6 个国产模型,月费 $0。
目标
五个 Provider 一览
| Provider | SDK | 认证方式 | 模型 | 费用 |
|---|---|---|---|---|
| Antigravity (OAuth) | @ai-sdk/google | Google OAuth | Gemini Pro/Flash + Claude | 免费 |
| Gemini (API Key) | @ai-sdk/google | API Key | 仅 Flash | 免费额度 |
| Ark Coding Plan | @ai-sdk/openai-compatible | API Key | 6 个国产模型 | 免费计划 |
| Claude (Relay) | @ai-sdk/anthropic | API Key | Opus/Sonnet/Haiku | Relay 积分 |
| LM Studio | OpenAI 兼容 | 无需认证 | 本地模型 | 免费 |
1. Antigravity——OAuth 白嫖 Claude Opus
Bash
opencode auth login google
# 弹浏览器 → 选 Google 账号 → 授权 → 完事
2. Gemini API Key——免费 Flash
大坑:就算你开了 Google One AI Premium 或 Google Student Pro 订阅,那也只是 网页版 无限用——API 的 Pro 模型没有免费额度。只有 Flash 有。既然 Antigravity 已经搞定了 Pro,我就单独建了一个 gemini provider 只跑 Flash 做备用:
Json
"gemini": {
"id": "gemini",
"name": "💎 Gemini (API Key Free)",
"api": "@ai-sdk/google",
"apiKey": "AIzaSy...",
"models": {
"gemini-2.5-flash": { "name": "⚡ Gemini 2.5 Flash" },
"gemini-3-flash-preview": { "name": "⚡ Gemini 3 Flash Preview" }
}
}
3. Ark Coding Plan——免费国产模型
| 普通 Ark | Coding Plan | |
|---|---|---|
| SDK | @ai-sdk/openai | @ai-sdk/openai-compatible |
| Endpoint | /api/v3 | /api/coding/v3 |
| API Key | 普通 key | Coding Plan key |
Json
"ark-coding": {
"id": "ark-coding",
"name": "🌋 Ark Coding Plan",
"api": "@ai-sdk/openai-compatible",
"baseURL": "https://ark.cn-beijing.volces.com/api/coding/v3",
"apiKey": "your-coding-plan-key",
"models": {
"ark-code-latest": { "name": "🤖 Auto Router" },
"doubao-seed-code": { "name": "🫘 Doubao Seed Code" },
"kimi-k2.5": { "name": "🌙 Kimi K2.5" },
"deepseek-v3.2": { "name": "🐋 DeepSeek V3.2" }
}
}
4. Whitelist——解决模型列表爆炸
Json
"google": {
"whitelist": [
"antigravity-gemini-3-pro",
"antigravity-gemini-3-flash",
"antigravity-claude-opus-4-6-thinking"
]
}
Bash
rm ~/.cache/opencode/models.json
5. Gemini + MCP Schema 不兼容
- anyOf / oneOf
- $ref / $defs
- const
- 解析 $ref → 内联展开
- anyOf/oneOf → 取第一个非 null 选项
- const → 转成 enum: [value]
6. Server 管理和 Shell Alias
Bash
# 等端口就绪(最多 10 秒)
for i in $(seq 1 20); do
curl -sf http://127.0.0.1:4096 >/dev/null 2>&1 && break
sleep 0.5
done
最终效果
Text
🔮 Antigravity → Claude Opus 4.6, Gemini 3 Pro/Flash (OAuth 白嫖)
💎 Gemini API → Gemini Flash (免费额度)
🌋 Ark Coding → DeepSeek, Kimi, Doubao, GLM (免费计划)
🟣 Claude Relay → 全系列 Claude (relay 积分)
🖥️ LM Studio → Qwen, Codestral 等 (本地)