OpenCode

Wire OpenCode up to Gab AI as a custom OpenAI-compatible provider via opencode.json.

Prerequisites

Configuration

OpenCode does not pick up OPENAI_BASE_URL or OPENAI_API_KEY for custom endpoints — you have to declare Gab AI as a provider in opencode.json (project-local) or ~/.config/opencode/opencode.json (global) using the @ai-sdk/openai-compatible package. Fetch a generated config with GET https://gab.ai/v1/agent-setup?client=opencode — it includes auto plus context limits and tool_call flags so OpenCode can compact correctly. Use auto on the agent/main model only. OpenCode stores credentials separately from the config file (in ~/.local/share/opencode/auth.json). After saving the config:

Generate opencode.json from the live catalog

opencode.json

Model ids and aliases

Prefer the generated map from GET /v1/agent-setup?client=opencode so each model includes context limits and tool_call. Request ids also accept aliases such as gpt-5.5 and anthropic/claude-sonnet-4-5. Display names like "Claude Opus 4.7" still return 400 invalid_model.

Discover Compatible Models

Tool/function calling is required for OpenCode's agent loop. GET /v1/models is public (no key required) and includes context_window, function_calling, and recommended_for. GET /v1/agent-setup?client=opencode writes a complete models map with limit.context / limit.output so OpenCode can compact correctly.

List function-calling models

Supported Features

Troubleshooting

Still failing?

Capture the exact request body and response from OpenCode's debug output. Most setup issues come down to (a) a model slug typo, (b) a model without function calling, or (c) the custom-provider-options bug above.

curl -s "https://gab.ai/v1/agent-setup?client=opencode" | jq .config > opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "gab-ai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Gab AI",
      "options": {
        "baseURL": "https://gab.ai/v1"
      },
      "models": {
        "claude-sonnet-4-5": {
          "name": "Claude Sonnet 4.5",
          "limit": { "context": 200000, "output": 16000 },
          "modalities": { "input": ["text", "image"], "output": ["text"] },
          "tool_call": true
        }
      }
    }
  }
}

Model ids and aliases

Prefer the generated map from GET /v1/agent-setup?client=opencode so each model includes context limits and tool_call. Request ids also accept aliases such as gpt-5.5 and anthropic/claude-sonnet-4-5. Display names like "Claude Opus 4.7" still return 400 invalid_model.

curl https://gab.ai/v1/models | jq -r '.data[] | select(.recommended_for[]? == "coding") | .id'

Still failing?

Capture the exact request body and response from OpenCode's debug output. Most setup issues come down to (a) a model slug typo, (b) a model without function calling, or (c) the custom-provider-options bug above.