OpenCode
Connect OpenCode AI coding assistant to Token101 to use any supported model
OpenCode
OpenCode is an open-source, terminal-based AI coding assistant. It runs in your terminal, understands your codebase, and can write, edit, and debug code across files.
OpenCode uses the OpenAI-compatible Chat Completions API, making it a straightforward integration with Token101.
Prerequisites
- A Token101 API key — subscription users can create one directly; free users need to complete API activation first at token.ppthub.shop/settings/apikeys
- Node.js 18 or later
- A terminal
Step 1 — Install OpenCode
npm install -g opencode-aiChina users can use a mirror registry for faster downloads:
npm install -g opencode-ai --registry=https://registry.npmmirror.comVerify the installation:
opencode --versionStep 2 — Configure Token101 as the Provider
OpenCode is configured through a opencode.json file in your project directory or home directory.
Option A — Project-level config (recommended)
Create opencode.json in your project root:
{
"provider": {
"openai": {
"name": "Token101",
"apiKey": "YOUR_TOKEN101_API_KEY",
"baseURL": "https://token.ppthub.shop/api/v1"
}
},
"model": "openai/gpt-5.2"
}Replace YOUR_TOKEN101_API_KEY with your actual key.
Option B — Environment variables
export OPENAI_API_KEY="your-token101-api-key"
export OPENAI_API_BASE="https://token.ppthub.shop/api/v1"To persist these, add them to your shell profile (~/.bashrc, ~/.zshrc, etc.).
Never commit opencode.json with your API key to version control. Add it to .gitignore, or use environment variables instead.
Step 3 — Verify the Connection
Run a quick test from your terminal:
opencode "Reply with exactly: TOKEN101_OK"You should see TOKEN101_OK in the response. If you do, OpenCode is connected to Token101.
Usage
Start an interactive session
opencodeOpenCode will open an interactive chat in your terminal. It automatically reads your project's files and can reference them in conversation.
Ask a one-shot question
opencode "Explain what this function does"Reference specific files
opencode "Review src/lib/billing.ts for potential bugs"Generate code
opencode "Add input validation to the createUser function in src/handlers/users.ts"Available Models
You can use any Token101-supported model by updating the model field in your config:
| Model | Config value |
|---|---|
| GPT-5.2 (default) | openai/gpt-5.2 |
| GPT-5.3 Codex | openai/gpt-5.3-codex |
| Claude Sonnet 4.5 | openai/claude-sonnet-4-5 |
| Claude Opus 4.6 | openai/claude-opus-4-6 |
See Supported Models for the full list.
How It Works
OpenCode sends requests to the OpenAI Chat Completions endpoint (/v1/chat/completions). Token101 receives these requests, validates your API key, routes to the appropriate model provider, and returns the response.
OpenCode → POST /api/v1/chat/completions → Token101 → Model Provider → ResponseToken101's Chat Completions API is fully OpenAI-compatible, so OpenCode works without any special configuration beyond pointing it at the Token101 base URL.
Troubleshooting
Error: 401 Unauthorized
Your API key is invalid or not set. Verify:
# If using environment variables
echo $OPENAI_API_KEY
# Should print your key, not emptyDouble-check the key in your opencode.json matches what's shown in Settings → API Keys.
Error: 404 Not Found
The base URL is incorrect. Make sure it's exactly:
https://token.ppthub.shop/api/v1Not https://token.ppthub.shop/api (missing /v1).
Model not found
Make sure the model name in your config matches a model from the Supported Models page. Model names are case-sensitive.
Slow responses
For long code tasks, responses can take 30–60 seconds. This is normal. If you're consistently seeing timeouts, try:
- Using a lighter model like
claude-haiku-4-5-20251001for quick tasks - Breaking large tasks into smaller requests
Next Steps
- Supported Models — see all available models
- Streaming — learn how streaming works
- Claude Code — alternative CLI tool using Anthropic Messages API
- API Reference — full endpoint documentation