Asia/Shanghai
February 10, 2026

OpenCode Antigravity Auth: 5 Pitfalls That Wasted My Weekend

OpenCode Antigravity 认证踩坑:浪费我一整个周末的 5 个坑

Mingjian Shao
OpenCode Antigravity Auth: 5 Pitfalls That Wasted My Weekend
Antigravity gives you free Claude and Gemini Pro in OpenCode — but the setup has hidden traps. Here's every pitfall I hit and how to fix them.
Antigravity is an OpenCode plugin that routes AI requests through Google Cloud's Code Assist API using OAuth. The result? Free access to Gemini Pro, Gemini Flash, and even Claude — all covered by Google Cloud's code assistance quota.If you haven't set it up yet, check out my provider setup guide. This post focuses on the auth-specific pitfalls I ran into after the basics were working.
The problem: Once Antigravity is installed, it intercepts every request that goes through the @ai-sdk/google SDK — including requests that use your own API key.The symptom: You've configured a Gemini API key. You select a Flash model. The request silently routes through OAuth instead of your key, and you get unexpected errors or rate limits.The fix: Create two separate providers with different IDs:
Json
// Provider 1: Antigravity OAuth (free Pro + Claude)
"google": {
  "id": "google",
  "api": "@ai-sdk/google",
  "models": {
    "antigravity-gemini-3-pro": { "name": "Gemini 3 Pro (AG)" },
    "antigravity-gemini-3-flash": { "name": "Gemini 3 Flash (AG)" }
  }
}

// Provider 2: Your API key (isolated from Antigravity)
"gemini": {
  "id": "gemini",
  "api": "@ai-sdk/google",
  "apiKey": "AIzaSy...",
  "models": {
    "gemini-2.5-flash": { "name": "Gemini 2.5 Flash" }
  }
}
The google provider goes through Antigravity. The gemini provider uses your API key directly. Different provider IDs = no hijacking.
The problem: If you have Google One AI Premium or Google Student Pro, you might assume you can call Pro models via the API for free. You can't.The symptom: You call gemini-2.5-pro or gemini-3-pro-preview with your API key and get 429 Too Many Requests — even though you're a paying subscriber.The reality:
ModelFree API QuotaPaid API (Billing enabled)
Flash series✅ Yes
Pro series❌ No
Google's subscription gives you access to the Gemini web app and mobile apps. It does not give you free API calls to Pro models — that requires enabling Billing on a GCP project.The workaround: Route Pro models through Antigravity OAuth (free). Use your API key only for Flash models (which have a free tier).
The problem: Gemini's API doesn't support several JSON Schema features that MCP tools commonly use: anyOf, oneOf, const, $ref, and $defs. OpenCode's built-in sanitizeGemini() function didn't handle all of these.The symptom: When using Gemini (via Antigravity or API key) to call MCP tools with complex schemas, you get schema validation errors.What's affected:
MCP ServerBroken SchemasRoot Cause
Notion66anyOf/oneOf + $ref/$defs
Memory4oneOf (tags field accepts array or string)
Lark-MCPManyComplex API schemas
What's fine: Obsidian, Filesystem, Bitwarden — anything with simple schemas.The fix: I submitted PR #12911 to OpenCode that inlines $ref resolution, merges anyOf branches, and converts const to enum. Until it's merged, use Claude (via Relay or another provider) for MCP-heavy tasks instead of Gemini.
The problem: OpenCode's model list is built by deep-merging remote data from models.dev with your opencode.json config. Without a whitelist, you'll see dozens of models you never configured.The symptom: You define 5 models. The UI shows 26.The fix — three steps:
  • Prefix Antigravity models with antigravity- to avoid ID collisions with API key models
  • Add a whitelist to every custom provider:
Json
"google": {
  "whitelist": [
    "antigravity-gemini-3-pro",
    "antigravity-gemini-3-flash",
    "antigravity-claude-opus-4-6-thinking"
  ],
  "models": { ... }
}
  • Clear the model cache after any config change:
Bash
rm ~/.cache/opencode/models.json
This is easy to forget and will make you think your config changes aren't taking effect.
When auth breaks, before you do anything else:
Bash
opencode auth debug google
This shows your OAuth token status, expiration time, and linked account. 90% of the time, the answer is right there.
When Antigravity auth fails, check these in order:
  • opencode auth debug google — read the actual error
  • Can you reach Google? (Proxy needed in China)
  • Are you assuming Student Pro gives API quota? (It doesn't)
  • Is your API key request being hijacked by Antigravity? (Check dual-provider config)
  • Does your MCP tool use anyOf/oneOf in its schema? (Gemini can't handle it)
  • Is the model cache stale? (rm ~/.cache/opencode/models.json)
This is a companion to my OpenCode provider setup guide. That post covers the full multi-provider configuration; this one digs into the auth-specific gotchas.
Antigravity 能让你在 OpenCode 里免费用 Claude 和 Gemini Pro——但配置过程暗坑不少。这篇记录我踩过的每一个坑和解法。
Antigravity 是 OpenCode 的一个插件,通过 Google Cloud Code Assist API 的 OAuth 通道转发 AI 请求。效果就是:Gemini ProGemini Flash、甚至 Claude 都能免费用——走的是 Google Cloud 的代码辅助配额。如果你还没配过基础环境,可以先看我的 Provider 配置指南。这篇专门讲配好之后在认证环节遇到的各种坑。
问题:装了 Antigravity 之后,它会拦截所有@ai-sdk/google SDK 的请求——包括你明确用 API key 调的。表现:你配了 Gemini API key,选了 Flash 模型,请求却悄悄走了 OAuth 通道,然后报错或触发限速。解法:建两个独立的 provider,用不同的 ID 隔离:
Json
// Provider 1: Antigravity OAuth(免费 Pro + Claude)
"google": {
  "id": "google",
  "api": "@ai-sdk/google",
  "models": {
    "antigravity-gemini-3-pro": { "name": "Gemini 3 Pro (AG)" },
    "antigravity-gemini-3-flash": { "name": "Gemini 3 Flash (AG)" }
  }
}

// Provider 2: API Key(独立通道,不过 Antigravity)
"gemini": {
  "id": "gemini",
  "api": "@ai-sdk/google",
  "apiKey": "AIzaSy...",
  "models": {
    "gemini-2.5-flash": { "name": "Gemini 2.5 Flash" }
  }
}
google 走 Antigravity,gemini 走 API key。ID 不同 = 互不干扰。
问题:有 Google One AI Premium 或 Student Pro 订阅?你可能以为能免费调 Pro 模型的 API。不能。表现:用 API key 调 gemini-2.5-progemini-3-pro-preview,直接返回 429 Too Many Requests——即使你是付费用户。真相
模型免费 API 配额付费 API(需开 Billing)
Flash 系列✅ 有
Pro 系列❌ 没有
Google 订阅给的是网页版和手机 App 的使用权,不包含 API 调用 Pro 模型的免费额度——那需要在 GCP 项目里开 Billing。绕过:Pro 模型走 Antigravity OAuth(免费),Flash 模型走 API key(有免费额度)。
问题:Gemini API 不支持 JSON Schema 里的 anyOfoneOfconst$ref$defs。OpenCode 内置的 sanitizeGemini() 没完全处理这些。表现:用 Gemini 调含复杂 schema 的 MCP 工具时,直接报 schema 校验错误。受影响的 MCP
MCP 服务问题数原因
Notion66anyOf/oneOf + $ref/$defs
Memory4oneOf(tags 字段支持数组或字符串)
Lark-MCP多个复杂 API schema
没问题的:Obsidian、Filesystem、Bitwarden——schema 简单的都没事。修复:我提了 PR #12911,在 sanitizeGemini() 里内联解析 $ref、合并 anyOf、把 const 转成 enum。在合并之前,MCP 重度操作建议用 Claude。
问题:OpenCode 的模型列表 = models.dev 远程数据 深度合并 opencode.json 用户配置。不加限制的话,UI 里会冒出来一堆你没配过的模型。表现:你只定义了 5 个模型,UI 里却显示 26 个。解法——三步走:
  • Antigravity 模型必须加 antigravity- 前缀,避免跟 API key provider 的模型 ID 冲突
  • 每个自定义 provider 都加 whitelist
Json
"google": {
  "whitelist": [
    "antigravity-gemini-3-pro",
    "antigravity-gemini-3-flash",
    "antigravity-claude-opus-4-6-thinking"
  ],
  "models": { ... }
}
  • 改完配置必须清模型缓存
Bash
rm ~/.cache/opencode/models.json
这一步特别容易忘,然后你会以为改配置没生效。
认证出问题时,别急着改配置,先跑:
Bash
opencode auth debug google
能看到 OAuth token 状态、过期时间、关联账号。90% 的情况答案就在输出里。
Antigravity 认证失败时,按这个顺序查:
  • opencode auth debug google——看具体错误
  • 能不能访问 Google?(国内需要代理)
  • 是不是 Student Pro 订阅误以为有 Pro API 配额?(没有)
  • API key 请求是不是被 Antigravity 劫持了?(检查双 provider 配置)
  • MCP 工具的 schema 是不是用了 anyOf/oneOf?(Gemini 不兼容)
  • 模型缓存是不是过期了?(rm ~/.cache/opencode/models.json
这篇是我 OpenCode Provider 配置指南的姊妹篇。那篇讲完整的多 Provider 配置,这篇专挖认证环节的坑。
Share this post:
Enjoy this post? Subscribe via RSS: English | 中文