Loading...

Docs · Integrations

opencode with TopxAI: a custom provider in opencode.json

Declare TopxAI in opencode.json with @ai-sdk/openai-compatible, the base URL and the model ids, then pick them with /models.

opencode takes custom providers in opencode.json (in the project or in ~/.config/opencode/). One block with the @ai-sdk/openai-compatible package covers every TopxAI text model; a second with @ai-sdk/anthropic keeps Claude on the Messages API.

opencode.json

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "topxai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "TopxAI",
      "options": {
        "baseURL": "https://ai.topxea.com/v1",
        "apiKey": "{env:TOPXAI_API_KEY}"
      },
      "models": {
        "claude-sonnet-5-5": {
          "name": "Claude Sonnet 5.5",
          "limit": { "context": 1000000, "output": 128000 }
        },
        "gpt-6.1-sol": {
          "name": "GPT-6.1 Sol",
          "limit": { "context": 1000000, "output": 128000 }
        },
        "grok-4.7": {
          "name": "Grok 4.7",
          "limit": { "context": 500000, "output": 128000 }
        },
        "kimi-k3.1-pro": {
          "name": "Kimi K3.1 Pro",
          "limit": { "context": 1048576, "output": 131072 }
        }
      }
    },
    "topxai-claude": {
      "npm": "@ai-sdk/anthropic",
      "name": "TopxAI (Anthropic API)",
      "options": {
        "baseURL": "https://ai.topxea.com/v1",
        "apiKey": "{env:TOPXAI_API_KEY}"
      },
      "models": {
        "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" },
        "claude-opus-5-5": { "name": "Claude Opus 5.5" }
      }
    }
  }
}

Then:

export TOPXAI_API_KEY=sk-...
opencode

and choose a model with /models; the provider names appear as headings.

Notes

If it fails

Models: claude-sonnet-5-5, gpt-6.1-sol · Models & pricing

Related

Previous: Aider with TopxAI: OPENAI_API_BASE and the model name · Next: Open WebUI with TopxAI: one OpenAI connection, every model

Other languages: 简体中文