opencode
Add OhMyGPT to opencode and use every model in the catalog with one key.
opencode takes OhMyGPT as a provider through its standard OpenAI-compatible package. One block in opencode.json gives opencode Claude, GPT, GLM and the rest of the catalog on your OhMyGPT key, and you can test the setup for free with ohmygpt/mock.
Configure
Add the provider to ~/.config/opencode/opencode.json for all projects, or to opencode.json in a project root for that project only:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ohmygpt": {
"npm": "@ai-sdk/openai-compatible",
"name": "OhMyGPT",
"options": {
"baseURL": "https://api.ohmygpt.com/v1",
"apiKey": "{env:OHMYGPT_API_KEY}"
},
"models": {
"anthropic/claude-sonnet-5-5": {
"limit": { "context": 1000000, "output": 128000 }
},
"anthropic/claude-haiku-5-5": {
"limit": { "context": 1000000, "output": 128000 }
}
}
}
},
"model": "ohmygpt/anthropic/claude-sonnet-5-5",
"small_model": "ohmygpt/anthropic/claude-haiku-5-5"
}baseURLends in/v1. The package appends/chat/completions.{env:OHMYGPT_API_KEY}reads your key from the environment, so the file holds no secret.- Each key under
modelsis an OhMyGPT model ID.limittells opencode when to compact the conversation; Choose a model shows where the numbers come from. modelandsmall_modeltake the form<provider key>/<model ID>. opencode usessmall_modelfor light tasks such as session titles.
Export the key and start opencode:
export OHMYGPT_API_KEY="sk-..."
opencodeRun /models to switch between the models you listed.
Check the connection
opencode sends Chat Completions requests. Send one to the free test model ohmygpt/mock:
curl https://api.ohmygpt.com/v1/chat/completions \
-H "Authorization: Bearer $OHMYGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "ohmygpt/mock", "messages": [{"role": "user", "content": "ping"}]}'{
"id": "chatcmpl-ohmygpt-mock",
"object": "chat.completion",
"model": "mock",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This is a mock reply from OhMyGPT. Your integration works; switch to a real model when ready."
},
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 15, "completion_tokens": 17, "total_tokens": 32 }
}To try opencode itself at no cost, add "ohmygpt/mock": {} under models and select it with /models. The mock calls the first tool opencode declares, then answers with text once it gets the result. The mock is available once your account has been topped up.
Choose a model
Every chat model works with opencode. List them with the context and output sizes to put in limit:
curl -s https://api.ohmygpt.com/v1/models \
| jq -r '.data[] | select(.available and any(.protocols[]?; .id == "openai-completions"))
| "\(.id)\tcontext=\(.context_length)\toutput=\(.limits.max_completion_tokens)"'anthropic/claude-sonnet-5-5 context=1000000 output=128000
openai/gpt-5.5 context=1050000 output=128000
zhipu/glm-5.3 context=1048576 output=131072
...Prices for each are on the Models page.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
401 with Invalid API key | OHMYGPT_API_KEY is not set in the shell that runs opencode, so {env:...} is empty | Export the variable and restart opencode |
404 on every request | baseURL is missing /v1 | Set it to https://api.ohmygpt.com/v1 |
404 saying the model does not exist | The key under models is not an OhMyGPT ID | Copy the ID from GET /v1/models |
The provider is missing from /models | opencode did not load the file, or the JSON is invalid | Check the path and validate the JSON |
402 | The balance or the key's spending limit is used up | Top up at Billing |
Every response carries an X-Request-ID header, and Usage shows what each request cost.