OhMyGPT
Coding Tools

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:

~/.config/opencode/opencode.json
{
  "$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"
}
  • baseURL ends 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 models is an OhMyGPT model ID. limit tells opencode when to compact the conversation; Choose a model shows where the numbers come from.
  • model and small_model take the form <provider key>/<model ID>. opencode uses small_model for light tasks such as session titles.

Export the key and start opencode:

export OHMYGPT_API_KEY="sk-..."
opencode

Run /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

SymptomCauseFix
401 with Invalid API keyOHMYGPT_API_KEY is not set in the shell that runs opencode, so {env:...} is emptyExport the variable and restart opencode
404 on every requestbaseURL is missing /v1Set it to https://api.ohmygpt.com/v1
404 saying the model does not existThe key under models is not an OhMyGPT IDCopy the ID from GET /v1/models
The provider is missing from /modelsopencode did not load the file, or the JSON is invalidCheck the path and validate the JSON
402The balance or the key's spending limit is used upTop up at Billing

Every response carries an X-Request-ID header, and Usage shows what each request cost.

On this page