OhMyGPT
Code CLI

OpenCode

Configure OpenCode CLI to use OhMyGPT as the API provider.

OpenCode is an open-source AI coding agent available as a terminal interface, desktop app, or IDE extension. This guide connects it to OhMyGPT using the OpenAI-compatible provider.

Installation

curl -fsSL https://opencode.ai/install | bash

Configuration

OpenCode uses a global JSON config file. Create or edit the file at:

PlatformPath
Linux / macOS~/.config/opencode/opencode.json
Windows%APPDATA%\opencode\opencode.json

OpenCode relies on the Vercel AI SDK for provider compatibility. Use the @ai-sdk/openai-compatible package to connect to OhMyGPT.

Claude Models via OhMyGPT

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ohmygpt": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OhMyGPT",
      "options": {
        "apiKey": "<your-ohmygpt-api-key>",
        "baseURL": "https://apic1.ohmycdn.com/api/v1/ai/openai/cc-omg/v1"
      },
      "models": {
        "claude-sonnet-4-5": {
          "name": "Claude Sonnet 4.5",
          "limit": {
            "context": 200000,
            "output": 64000
          }
        },
        "claude-haiku-4-5": {
          "name": "Claude Haiku 4.5",
          "limit": {
            "context": 200000,
            "output": 64000
          }
        }
      }
    }
  }
}

OpenAI Models via OhMyGPT

GPT-5.2 Codex currently has parameter compatibility issues with OpenCode. See anomalyco/opencode#5421 for status.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ohmygpt-openai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OhMyGPT (OpenAI)",
      "options": {
        "apiKey": "<your-ohmygpt-api-key>",
        "baseURL": "https://apic1.ohmycdn.com/v1"
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "GPT-5.2 Codex",
          "limit": {
            "context": 400000,
            "output": 128000
          }
        }
      }
    }
  }
}

Combined Configuration

You can define multiple providers in a single config to switch between models:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ohmygpt-claude": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OhMyGPT Claude",
      "options": {
        "apiKey": "<your-ohmygpt-api-key>",
        "baseURL": "https://apic1.ohmycdn.com/api/v1/ai/openai/cc-omg/v1"
      },
      "models": {
        "claude-sonnet-4-5": {
          "name": "Claude Sonnet 4.5",
          "limit": {
            "context": 200000,
            "output": 64000
          }
        },
        "claude-haiku-4-5": {
          "name": "Claude Haiku 4.5",
          "limit": {
            "context": 200000,
            "output": 64000
          }
        }
      }
    },
    "ohmygpt-openai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OhMyGPT OpenAI",
      "options": {
        "apiKey": "<your-ohmygpt-api-key>",
        "baseURL": "https://apic1.ohmycdn.com/v1"
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "GPT-5.2 Codex",
          "limit": {
            "context": 400000,
            "output": 128000
          }
        }
      }
    }
  }
}

Configuration Reference

FieldDescription
npmAI SDK package to use. Use @ai-sdk/openai-compatible for OhMyGPT
nameDisplay name shown in OpenCode UI
options.apiKeyYour OhMyGPT API key (can also use {env:VAR_NAME} syntax)
options.baseURLOhMyGPT endpoint URL
models.<id>.nameDisplay name for the model
models.<id>.limit.contextMaximum context window (tokens)
models.<id>.limit.outputMaximum output length (tokens)

Using Environment Variables

Instead of hardcoding your API key, reference an environment variable:

{
  "options": {
    "apiKey": "{env:OHMYGPT_API_KEY}",
    "baseURL": "https://apic1.ohmycdn.com/api/v1/ai/openai/cc-omg/v1"
  }
}

Then set the environment variable in your shell profile:

export OHMYGPT_API_KEY="<your-ohmygpt-api-key>"

Verification

Start OpenCode in your project directory:

cd /path/to/project
opencode

Run /init to initialize OpenCode for the project, then use /model to select your configured OhMyGPT model.

Troubleshooting

SymptomCauseSolution
Provider not listedConfig file not foundVerify config path matches your platform
"Invalid API key"Key not set or incorrectCheck apiKey value or environment variable
Model parameter errorsSDK compatibility issueCheck OpenCode issues for model-specific bugs
JSON parse errorSyntax error in configValidate JSON format (no trailing commas, proper quoting)

How is this guide?

Last updated on

On this page