| name | sub2api-opencode |
|---|---|
| description | Configure Sub2API as a provider in OpenCode. Use when setting up sub2api proxy, configuring antigravity endpoints, or connecting Claude/Gemini models through sub2api gateway in opencode.json. Handles provider setup, model registration, endpoint routing, and troubleshooting 404 errors. |
Configure Sub2API as an AI provider in OpenCode.
Sub2API is an open-source AI API Gateway (6K+ stars) that converts Antigravity, Claude, OpenAI, and Gemini subscriptions into unified API endpoints. It supports multi-account management, smart scheduling, sticky sessions, token-level billing, and concurrency control.
Official domains: sub2api.org and pincc.ai. Other sites using the Sub2API name may be third-party deployments.
Sub2API exposes different endpoints for different model families and protocols:
| Endpoint Path | Protocol | Model Family | SDK to Use |
|---|---|---|---|
/antigravity/v1/messages |
Anthropic Messages API | Claude (via Antigravity) | @ai-sdk/anthropic |
/antigravity/v1beta/ |
Google Generative AI API | Gemini (via Antigravity) | @ai-sdk/google-generative-ai |
/v1/messages |
Anthropic Messages API | Claude (direct/hybrid) | @ai-sdk/anthropic |
/v1beta/ |
Google Generative AI API | Gemini (direct/hybrid) | @ai-sdk/google-generative-ai |
/v1/chat/completions |
OpenAI Chat Completions | OpenAI models | @ai-sdk/openai-compatible |
NEVER use @ai-sdk/openai-compatible for Claude or Gemini models on Sub2API. It sends requests to /chat/completions which does not exist on the /antigravity/ path, causing 404 page not found.
Correct SDK mapping:
| Model Family | npm Package | Endpoint Called |
|---|---|---|
| Claude | @ai-sdk/anthropic |
/v1/messages |
| Gemini | @ai-sdk/google-generative-ai |
/v1beta/ |
| OpenAI | @ai-sdk/openai-compatible |
/v1/chat/completions |
When hybrid scheduling is enabled in Sub2API admin, the general endpoints /v1/messages and /v1beta/ will also route to Antigravity accounts.
Warning: Anthropic Claude and Antigravity Claude cannot be mixed within the same conversation context. Use groups to isolate them.
{
"$schema": "https://opencode.ai/config.json",
"model": "sub2api-claude/claude-sonnet-4-6",
"provider": {
"sub2api-claude": {
"npm": "@ai-sdk/anthropic",
"name": "Sub2API Claude",
"options": {
"baseURL": "https://<YOUR_SUB2API_DOMAIN>/antigravity/v1",
"apiKey": "<YOUR_SUB2API_API_KEY>"
},
"models": {
"claude-sonnet-4-6": {
"name": "Claude Sonnet 4.6",
"limit": { "context": 200000, "output": 64000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-opus-4-6": {
"name": "Claude Opus 4.6",
"limit": { "context": 200000, "output": 128000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-opus-4-6-thinking": {
"name": "Claude Opus 4.6 (Thinking)",
"limit": { "context": 200000, "output": 128000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5",
"limit": { "context": 200000, "output": 64000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-sonnet-4-5-thinking": {
"name": "Claude Sonnet 4.5 (Thinking)",
"limit": { "context": 200000, "output": 64000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-opus-4-5-thinking": {
"name": "Claude Opus 4.5 (Thinking)",
"limit": { "context": 200000, "output": 128000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
}
}
}
}
}{
"$schema": "https://opencode.ai/config.json",
"model": "sub2api-gemini/gemini-3-flash",
"provider": {
"sub2api-gemini": {
"npm": "@ai-sdk/google-generative-ai",
"name": "Sub2API Gemini",
"options": {
"baseURL": "https://<YOUR_SUB2API_DOMAIN>/antigravity/v1beta",
"apiKey": "<YOUR_SUB2API_API_KEY>"
},
"models": {
"gemini-3-flash": {
"name": "Gemini 3 Flash",
"limit": { "context": 1048576, "output": 65536 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-3-pro-low": {
"name": "Gemini 3 Pro (Low Thinking)",
"limit": { "context": 1048576, "output": 65535 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-3-pro-high": {
"name": "Gemini 3 Pro (High Thinking)",
"limit": { "context": 1048576, "output": 65535 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-3.1-pro-low": {
"name": "Gemini 3.1 Pro (Low)",
"limit": { "context": 1048576, "output": 65535 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-3.1-pro-high": {
"name": "Gemini 3.1 Pro (High)",
"limit": { "context": 1048576, "output": 65535 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-2.5-flash": {
"name": "Gemini 2.5 Flash",
"limit": { "context": 1048576, "output": 65536 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
}
}
}
}
}{
"$schema": "https://opencode.ai/config.json",
"model": "sub2api-claude/claude-sonnet-4-6",
"provider": {
"sub2api-claude": {
"npm": "@ai-sdk/anthropic",
"name": "Sub2API Claude",
"options": {
"baseURL": "https://<YOUR_SUB2API_DOMAIN>/antigravity/v1",
"apiKey": "<YOUR_SUB2API_API_KEY>"
},
"models": {
"claude-sonnet-4-6": {
"name": "Claude Sonnet 4.6",
"limit": { "context": 200000, "output": 64000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-opus-4-6": {
"name": "Claude Opus 4.6",
"limit": { "context": 200000, "output": 128000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-opus-4-6-thinking": {
"name": "Claude Opus 4.6 (Thinking)",
"limit": { "context": 200000, "output": 128000 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
}
}
},
"sub2api-gemini": {
"npm": "@ai-sdk/google-generative-ai",
"name": "Sub2API Gemini",
"options": {
"baseURL": "https://<YOUR_SUB2API_DOMAIN>/antigravity/v1beta",
"apiKey": "<YOUR_SUB2API_API_KEY>"
},
"models": {
"gemini-3-flash": {
"name": "Gemini 3 Flash",
"limit": { "context": 1048576, "output": 65536 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-3-pro-high": {
"name": "Gemini 3 Pro (High Thinking)",
"limit": { "context": 1048576, "output": 65535 },
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
}
}
}
}
}Instead of hardcoding the API key, use OpenCode's {env:VAR_NAME} syntax:
"options": {
"baseURL": "https://your-sub2api-domain/antigravity/v1",
"apiKey": "{env:SUB2API_KEY}"
}Then set the environment variable:
export SUB2API_KEY="sk-your-api-key"Ask the user for:
- Sub2API domain (e.g.,
sub2api.example.com) - API Key (starts with
sk-, get from Sub2API admin panel under "API Keys") - Which models they want to use (Claude, Gemini, or both)
- Endpoint type - Antigravity (
/antigravity/) or direct (/)
Test the API endpoint before configuring:
# Test Claude endpoint (Antigravity)
curl -s "https://<DOMAIN>/antigravity/v1/messages" -X POST \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-4-6", "messages": [{"role": "user", "content": "hi"}], "max_tokens": 10}'
# Test available models
curl -s "https://<DOMAIN>/antigravity/v1/models" \
-H "Authorization: Bearer <API_KEY>"
# Test Gemini endpoint (Antigravity)
curl -s "https://<DOMAIN>/antigravity/v1beta/models" \
-H "Authorization: Bearer <API_KEY>"A successful Claude response returns JSON with "type": "message".
If you get 404 page not found, the endpoint path is wrong.
If you get 503, all upstream accounts are rate-limited or unavailable.
Use the appropriate template from above. Write to:
~/.config/opencode/opencode.jsonfor global config./opencode.jsonfor project-specific config
After saving, restart OpenCode and use /models command to check if Sub2API models appear.
This is the most common error. Check these in order:
| # | Check | Fix |
|---|---|---|
| 1 | Using @ai-sdk/openai-compatible for Claude? |
Change npm to @ai-sdk/anthropic |
| 2 | Using @ai-sdk/openai-compatible for Gemini? |
Change npm to @ai-sdk/google-generative-ai |
| 3 | baseURL ends with /v1 for Gemini? |
Change to /v1beta |
| 4 | baseURL missing /antigravity? |
Add /antigravity/v1 or /antigravity/v1beta |
| 5 | Using wrong model ID? | Check with curl <baseURL>/models |
Sub2API has no available upstream accounts, or all are in cooldown.
Fix: Wait for cooldown, or add more upstream accounts in Sub2API admin.
The provider field must be an object {}, never a string.
// WRONG - causes "expected record, received string"
"provider": "google"
// CORRECT
"provider": {
"sub2api-claude": { ... }
}Also check for unrecognized top-level keys. All provider definitions must be inside the provider object.
Missing modalities in model config. OpenCode defaults to text-only if not specified.
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}Known Sub2API issue: In Claude Code, Plan Mode cannot exit automatically.
Workaround: Press Shift + Tab to manually exit Plan Mode.
OpenCode's model field uses the format <provider-key>/<model-id>:
{
"model": "sub2api-claude/claude-sonnet-4-6",
"provider": {
"sub2api-claude": { ... }
}
}The part before / must match a key inside provider.
If you use Nginx in front of Sub2API, add this to the http block:
underscores_in_headers on;Nginx drops headers with underscores by default (e.g. session_id), breaking sticky session routing.
| Path | Purpose | Protocol |
|---|---|---|
/antigravity/v1/messages |
Claude chat (Antigravity accounts) | Anthropic |
/antigravity/v1/models |
List available models | REST |
/antigravity/v1beta/ |
Gemini chat (Antigravity accounts) | Google AI |
/v1/messages |
Claude chat (direct + hybrid) | Anthropic |
/v1beta/ |
Gemini chat (direct + hybrid) | Google AI |
/v1/chat/completions |
OpenAI chat (if configured) | OpenAI |
For Claude Code CLI (not OpenCode), use:
export ANTHROPIC_BASE_URL="https://<YOUR_DOMAIN>/antigravity"
export ANTHROPIC_AUTH_TOKEN="sk-xxx"claude-sonnet-4-6- Latest, fast and capableclaude-opus-4-6- Latest, most capableclaude-opus-4-6-thinking- With extended thinkingclaude-sonnet-4-5- Previous generationclaude-sonnet-4-5-thinking- Previous gen with thinkingclaude-opus-4-5-thinking- Previous gen, most capable with thinking
gemini-3-flash- Latest fast modelgemini-3-pro-low/gemini-3-pro-high- Pro with thinking levelsgemini-3.1-pro-low/gemini-3.1-pro-high- Latest Progemini-3.1-flash-image- Latest image generationgemini-2.5-flash/gemini-2.5-flash-thinking- Previous generationgemini-2.5-flash-image- Image generation
Note: Actual available models depend on your Sub2API instance. Query the models endpoint to check.
- Sub2API GitHub: https://github.com/Wei-Shaw/sub2api
- Sub2API Demo: https://demo.sub2api.org/
- OpenCode Docs: https://opencode.ai/docs
- OpenCode Provider Config: https://opencode.ai/docs/providers/