OpenCode
Connect OpenCode, the terminal-native coding agent, to GreenPT Code via its OpenAI-compatible endpoint.
OpenCode is an open-source, terminal-native coding agent
that supports any OpenAI-compatible endpoint through the
@ai-sdk/openai-compatible package. This guide connects OpenCode to GreenPT and
glm-5.2.
Prerequisites
- OpenCode installed (opencode.ai/docs)
- A GreenPT API key from your GreenPT dashboard
1. Set your API key
Store your key as an environment variable rather than hardcoding it in config:
# zsh
echo 'export GREENPT_API_KEY="your-greenpt-key"' >> ~/.zshrc
source ~/.zshrc
# bash
echo 'export GREENPT_API_KEY="your-greenpt-key"' >> ~/.bashrc
source ~/.bashrc2. Add the GreenPT provider
Add a provider block to your OpenCode config. Use the global config at
~/.config/opencode/opencode.json for a user-wide setup, or a project
opencode.json in your repo root if you only want GreenPT available for a
specific project (project config takes precedence over global).
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"greenpt": {
"npm": "@ai-sdk/openai-compatible",
"name": "GreenPT",
"options": {
"baseURL": "https://api.greenpt.ai/v1",
"apiKey": "{env:GREENPT_API_KEY}"
},
"models": {
"glm-5.2": {
"name": "GLM-5.2",
"limit": {
"context": 1000000,
"output": 131072
}
},
"minimax-m2.5": {
"name": "MiniMax M2.5"
},
"kimi-k2.6": {
"name": "Kimi K2.6"
}
}
}
},
"model": "greenpt/glm-5.2"
}limit requires both context and output
If you include a limit object at all, OpenCode's config schema requires both
context and output — a limit with only context set fails validation
with limit.output: Missing key, and OpenCode won't load any sessions until
it's fixed. For that reason limit is only set for glm-5.2 above; the other
models omit it and fall back to OpenCode's defaults. Confirm each model ID
matches exactly what GreenPT's /v1/models endpoint returns before publishing.
Available models
| Model ID | Provider | Category | Input (€/1M) | Output (€/1M) | Context |
|---|---|---|---|---|---|
glm-5.2 | z.ai | Coding | €1.32 | €4.62 | 1M |
minimax-m2.5 | MiniMax | Coding | €0.17 | €0.99 | 200k |
kimi-k2.6 | Moonshot AI | Coding | €0.83 | €3.85 | 256k |
Notes on the config:
npm— always@ai-sdk/openai-compatiblefor a/v1/chat/completions-style endpoint. Only use@ai-sdk/openaiif GreenPT exposes a/v1/responses-style endpoint instead.baseURL— must point to the versioned root (ending in/v1), not the full completions path.- Model IDs are passed through unchanged. Whatever key you use under
models(e.g.glm-5.2) must exactly match the model ID GreenPT's API expects — case and formatting matter. limitis optional but recommended — it tells OpenCode how much context budget it has left during a session.
One provider block can serve multiple model families, as shown above — no need
for a separate provider entry per model.
3. Select the model
Restart OpenCode, then run:
/modelsGreenPT should appear as a provider with GLM-5.2 listed underneath. Select
it, or set it as the default via the "model": "greenpt/glm-5.2" line shown
above.
4. Verify the connection
Quick sanity check outside of OpenCode:
curl https://api.greenpt.ai/v1/models \
-H "Authorization: Bearer $GREENPT_API_KEY"You should get back a list including your glm-5.2 model ID. If this fails, fix
the API key or endpoint before troubleshooting inside OpenCode.
One-command alternative
Instead of hand-editing the config, you can offer a connector script (following the pattern used by other GreenPT-style gateways) that writes the provider block and stores the credential automatically:
export GREENPT_API_KEY="your-greenpt-key"
npx -y @greenpt/connect --opencodeAdd --project to write a project-local config instead of the global one. This
is optional polish — worth building only once the manual path above is
documented and stable.
Troubleshooting
| Symptom | Fix |
|---|---|
"Failed to load sessions for [project]" + limit.output: Missing key | You set limit.context on a model without also setting limit.output. Either add both, or remove limit entirely for that model |
Provider doesn't show up in /models | Restart OpenCode after editing config; confirm the file is valid JSON/JSONC |
| "Model not found" | Model ID in config must exactly match the ID GreenPT's /v1/models endpoint returns |
| Authentication failed | Confirm GREENPT_API_KEY is set in the shell OpenCode launches from; test with the curl command above |
| Config changes not applying | Check for a competing opencode.json — project config overrides global config, and both override remote org defaults |
Config precedence (for reference)
OpenCode merges config from multiple sources, in this order (later overrides earlier on conflicting keys only):
- Remote org config (
.well-known/opencode) - Global config (
~/.config/opencode/opencode.json) - Custom config (
OPENCODE_CONFIGenv var) - Project config (
opencode.jsonin repo root) — highest precedence
If you're rolling GreenPT out org-wide, the remote .well-known/opencode config
is the place to pre-populate the provider block so individual developers don't
have to.