pi-opencode-go-provider
v1.1.22
Published
Opencode Go provider extension for pi - Fast, efficient GLM, Kimi, and MiniMax models through the opencode.ai API
Maintainers
Readme
🟢 pi-opencode-go-provider
Fast GLM, Kimi & MiniMax via opencode-go
Go-optimized endpoints for lower latency — 14+ models for pi.
Pi 1.0 compatibility
Tested with Pi 1.0.0. Host-provided packages remain wildcard peers; development uses exact SDK pins.
Run bun run test:pi for offline manifest, catalog, lifecycle and streaming checks. To test an installed host, set PI1_HOST_PACKAGE to its package directory; add PI1_HOST_ENTRY=bundle for its bundled CLI runtime. The probe stubs all network requests and never uses a live provider endpoint.
Features
- 14+ Optimized AI Models - DeepSeek, GLM, Kimi, MiMo, MiniMax, and Qwen
- Multi-API Support — uses the correct API protocol per model (Anthropic, OpenAI Completions)
- Fast & Efficient - Go-optimized endpoints for lower latency
- Cost Tracking with per-model pricing for budget management
- Reasoning Models with thinking level maps for proper effort control
- Prompt-cache session affinity — sends
x-opencode-sessionandx-opencode-clientso OpenCode Go can pin a session to the same cache node - Quiet live model sync — Models refresh from the OpenCode Go API in the background, at most hourly and by one pi process at a time (details)
- Usage widget — shows how much of the OpenCode Go 5h / 7d / 30d budgets you have spent, below the editor (footer status line outside the TUI). Each account carries its own budgets, so when pi-multiprovider 0.8.0+ pools several
opencode-goaccounts the widget bills the session's active one and repaints on every switch or resume.
Installation
Option 1: Using pi install (Recommended)
Install directly from GitHub:
pi install https://github.com/monotykamary/pi-opencode-go-providerThen set your API key and run pi:
# Recommended: add to auth.json
# See Authentication section below
# Or set as environment variable
export OPENCODE_API_KEY=your-api-key-here
piOption 2: Manual Clone
Clone this repository:
git clone https://github.com/monotykamary/pi-opencode-go-provider.git cd pi-opencode-go-providerSet your opencode API key:
# Recommended: add to auth.json # See Authentication section below # Or set as environment variable export OPENCODE_API_KEY=your-api-key-hereRun pi with the extension:
pi -e /path/to/pi-opencode-go-provider
Available Models
| Model | API | Type | Context | Max Tokens | Input Cost | Output Cost | |-------|-----|------|---------|------------|------------|-------------| | Claude Haiku 5.5 | Anthropic | Text + Image | 1.0M | 128K | $0.10 | $0.50 | | DeepSeek V4 Flash | Completions | Text | 1.0M | 384K | $0.15 | $0.60 | | DeepSeek V4 Flash Vision Exp | Completions | Text + Image | 1.0M | 384K | $0.15 | $0.60 | | DeepSeek V4 Pro (New) | Completions | Text | 1.0M | 384K | $0.66 | $1.98 | | DeepSeek V4.1 Flash | Completions | Text + Image | 1.0M | 384K | $0.15 | $0.60 | | GLM-5.2 | Completions | Text | 1.0M | 131K | $1.40 | $4.40 | | GLM-5.3 | Completions | Text | 1.0M | 131K | $1.40 | $4.40 | | GLM-5.3-Flash | Completions | Text + Image | 1.0M | 131K | $0.15 | $0.50 | | GPT-5.6 Luna | Responses | Text + Image | 1.1M | 128K | $0.20 | $1.20 | | GPT-6 Luna | Completions | Text + Image | 1.1M | 128K | $0.10 | $0.50 | | Grok 4.6 | Completions | Text + Image | 500K | 500K | $2.00 | $6.00 | | Grok 4.7 | Completions | Text + Image | 500K | 500K | $2.00 | $6.00 | | Hy3 | Completions | Text | 256K | 128K | $0.14 | $0.58 | | Hy4 preview | Completions | Text | 1.0M | 64K | $0.83 | $2.50 | | Kimi K2.7 Code | Completions | Text + Image | 262K | 262K | $0.95 | $4.00 | | Kimi K3 (2x usage) | Completions | Text + Image | 1.0M | 131K | $3.00 | $15.00 | | LongCat 2.5 Preview Free | Completions | Text + Image | 1.0M | 131K | — | — | | LongCat-2.0 | Completions | Text | 1.0M | 131K | $0.30 | $1.20 | | MiMo V2.5 | Completions | Text + Image | 1.0M | 128K | $0.14 | $0.28 | | MiMo V2.5 Pro | Completions | Text | 1.0M | 128K | $0.43 | $0.87 | | MiMo-V2.6-Flash | Completions | Text + Image | 1.0M | 131K | $0.14 | $0.28 | | MiMo-V2.6-Pro | Completions | Text + Image | 1.0M | 131K | $0.43 | $0.87 | | MiniMax-M2.7 | Completions | Text | 205K | 131K | $0.30 | $1.20 | | MiniMax-M3 | Anthropic | Text + Image | 1.0M | 131K | $0.30 | $1.20 | | Muse Spark 1.2 Contributor | Responses | Text + Image | 1.0M | 131K | $0.10 | $0.20 | | Muse Spark 1.3 Contributor | Responses | Text + Image | 1.0M | 131K | $0.10 | $0.20 | | Qwen3.7 Plus | Anthropic | Text + Image | 1.0M | 66K | $0.40 | $1.60 | | Qwen3.8 Flash | Anthropic | Text + Image | 1.0M | 131K | $0.15 | $0.47 | | Qwen3.8 Max | Anthropic | Text + Image | 1.0M | 131K | $2.00 | $6.00 | | Space Bunny | Completions | Text + Image | 1.0M | 524K | $0.15 | $0.60 | | Step 5 Preview Free | Completions | Text + Image | 1.0M | 66K | — | — | Costs are per million tokens. Prices subject to change - check opencode.ai for current pricing.
Usage
After loading the extension, use the /model command in pi to select your preferred model:
/modelThen select "opencode-go" as the provider and choose from the available models.
The default model for this provider is kimi-k2.6 (matching pi core's built-in default); use /model to pick another.
Usage Widget
OpenCode Go meters the plan with three dollar budgets — a rolling 5-hour window,
a weekly window and a monthly window. The extension polls
GET https://opencode.ai/zen/go/v1/usage with your API key and shows how much of
each budget is left, below the editor. Outside the TUI (e.g. RPC mode) the
same line goes to the footer status bar instead. Sessions without a UI at all
(print/JSON mode, fan-out child agents) never poll, and neither does a session
without an API key. Background polls are shared across pi processes: one process
polls at most every 30 seconds and writes the snapshot to
~/.pi/agent/cache/opencode-go-usage.json (key fingerprint only, never the key),
and the others render that file. /opencode-go-usage always re-reads the API.
Usage: 5h: 63% · 7d: 41% · 30d: 12% · 5h ↺ 2h14m · 7d ↺ 3d20h · 30d ↺ 20d0hThe line matches the pi-better-openai usage line: the remaining percentages come
first, then a countdown per window. Countdowns only — three windows with three
wall-clock reset times run past the terminal width, and /opencode-go-usage
lists the exact local reset time for each. Colours track what is left — green,
amber at 30% or less, red at 10% or less or when a window reports
rate-limited — and the widget only appears while an opencode-go model is
selected. The Go API publishes no banked reset credits,
so that trailing segment appears only if a response ever carries a
bankedResets count.
/opencode-go-usage # refresh and show the full breakdown
/opencode-go-usage refresh # same, but always re-reads the API
/opencode-go-usage off # hide the widget (persisted)
/opencode-go-usage on # show it again
/opencode-go-usage debug # config, last fetch/error, endpoint
/opencode-go-usage glyphs auto|unicode|ascii # footer glyph set (persisted)Polling runs every 60 seconds, plus after every turn and whenever the selected
model changes. Settings are read from ~/.pi/agent/opencode-go-provider.json:
{
"usage": {
"enabled": true,
"refreshIntervalMs": 60000,
"showOnlyOnProvider": true,
"showResetTimes": true,
"placement": "belowEditor",
"glyphs": "auto"
}
}placement accepts belowEditor (default) or aboveEditor. Every key is
optional; /opencode-go-usage on|off writes only enabled.
glyphs accepts auto (default), unicode, or ascii. Older mintty/Cygwin builds measure ambiguous-width codepoints (the · separators, the ↺ reset marker) with their own cell-width tables, which can shift the row and desync pi’s renderer. auto switches the widget to ASCII equivalents on those terminals and the widget never paints the terminal’s last column; an explicit unicode is clamped to ASCII for widget content there (the status line is not row-budgeted and keeps the choice).
Pooled accounts
When pi-multiprovider
0.8.0+ pools several opencode-go accounts, usage reads bill the session's
active account instead of Pi's default credential: every account has its own
5h / 7d / 30d budgets. The widget also repaints when the account changes,
including when a resumed session restores the account last chosen with
/switch-account, rather than showing the previous account until the next
poll. Without pi-multiprovider nothing changes: the widget bills the key from
the resolution order above.
Authentication
The opencode-go API key can be configured in multiple ways. Credentials are resolved in this order:
- CLI flag —
--api-key(highest priority, runtime override) auth.json(recommended) — Add to~/.pi/agent/auth.json:
The{ "opencode-go": { "type": "api_key", "key": "your-api-key" } }keyfield supports literals,$ENV_VAR/${ENV_VAR}interpolation, and!commandexecution. See pi's providers docs for details.- Environment variable —
OPENCODE_API_KEY
Environment Variables
| Variable | Required | Description |
|----------|----------|-------------|
| OPENCODE_API_KEY | No | Your opencode.ai API key (fallback if not in auth.json). Also used for usage requests |
| OPENCODE_GO_USAGE | No | Set to off/false/0 to disable the usage widget without editing the config file |
| OPENCODE_GO_USAGE_INTERVAL_MS | No | Override the usage poll interval (clamped to 15s–10m) |
| PI_PROVIDER_SYNC_TTL_MS | No | Model sync freshness window in ms (default 3600000; 0 = revalidate every session start) |
Configuration
Add to your pi configuration for automatic loading:
{
"extensions": [
"/path/to/pi-opencode-go-provider"
]
}Model sync
Startup never waits on the network. pi starts with the cached catalog (~/.pi/agent/cache/opencode-go-models.json,
falling back to the bundled models.json) and revalidates against /v1/models in the background — only when:
- an OpenCode Go API key is configured (no key, no request),
- the cache is older than 1 hour, missing, or was fetched with a different API key, and
- no other pi process is already refreshing it (an
opencode-go-models.lockfile next to the cache).
So /new, /reload, pi -p and fan-out child agents share one cache instead of each calling the API; a
session that skips the fetch still picks up a cache another process refreshed. A failed refresh is retried after
5 minutes at the earliest. PI_PROVIDER_SYNC_TTL_MS changes the window (0 revalidates on every session start).
Only a hash fingerprint of the key is stored (opencode-go-models.sync.json), never the key itself. The usage
widget shares its polls the same way (see Usage Widget).
License
MIT
