Models Hub
Agent Tools

OpenCode

An open-source terminal AI coding agent compatible with a wide range of model service providers.

Edit this page

Overview

OpenCode is an open-source terminal AI coding agent that runs in both TUI and CLI modes and is compatible with 75+ AI service providers. Through its built-in @ai-sdk/anthropic and @ai-sdk/openai-compatible adapters, it can seamlessly connect to the Anthropic-protocol models and OpenAI-compatible models provided by Models Hub.

📦 Before You Start

What you need

  • OpenCode installed
  • A working Models Hub Base URL (must end with /v1)
  • A working Models Hub API Key (generate it in the console)
  • The model name you want to use (such as claude-sonnet-4-6, claude-haiku-4-5, deepseek-v4-pro, gpt-5.5, etc., which must match the model ID in the Models Hub console exactly)

Add Models Hub directly through the menu in the OpenCode TUI:

  1. Launch the OpenCode TUI
  2. Enter the /connect command
  3. Select "Other" (custom endpoint) from the provider list
  4. Fill in as prompted:
    • Base URL: https://modelsok.com/v1
    • API Key: your Models Hub API Key
  5. After saving, enter /models to switch to the newly added model

Suitable for scenarios where you want to lock in multiple models and reuse them across projects.

1. Edit the OpenCode Configuration

Configuration file locations:

  • Global: ~/.config/opencode/opencode.json
  • Project-level (higher priority): opencode.json in the project root
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "modelsok-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "Models Hub (Anthropic)",
      "options": {
        "baseURL": "https://modelsok.com/v1",
        "apiKey": "sk-123"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6",
          "limit": { "context": 200000, "output": 8192 }
        },
        "haiku": {
          "id": "claude-haiku-4-5",
          "name": "Claude Haiku 4.5 (fast)",
          "limit": { "context": 200000, "output": 8192 }
        }
      }
    },
    "modelsok": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Models Hub",
      "options": {
        "baseURL": "https://modelsok.com/v1",
        "apiKey": "sk-123"
      },
      "models": {
        "deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash",
          "limit": { "context": 131072, "output": 16384 }
        },
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": { "context": 131072, "output": 16384 }
        },
        "gpt-5.5": {
          "name": "GPT-5.5",
          "limit": { "context": 128000, "output": 32768 }
        },
        "gpt-5.4": {
          "name": "GPT-5.4",
          "limit": { "context": 128000, "output": 32768 }
        },
        "gpt-5.4-mini": {
          "name": "GPT-5.4 Mini",
          "limit": { "context": 128000, "output": 16384 }
        }
      }
    }
  },
  "model": "modelsok-anthropic/claude-sonnet-4-6",
  "autoshare": false
}

Key field notes

  • The example declares two providers:
    • modelsok-anthropic: npm must be @ai-sdk/anthropic, used to connect to Anthropic-protocol models such as Claude
    • modelsok: npm must be @ai-sdk/openai-compatible, used to connect to OpenAI-compatible models such as DeepSeek and GPT
  • The baseURL of both providers is https://modelsok.com/v1
  • The apiKey field is written directly in the configuration file; replace it with your own Models Hub API Key (the sk-123 in the example is only a placeholder)
  • The model IDs in models must match the model names actually exposed in the Models Hub console exactly; if you want a custom shorthand, you can use the id field to point to the real model (such as haikuclaude-haiku-4-5 in the example)
  • The top-level model field specifies the default model, in the format <provider>/<model>
  • The project-level opencode.json takes priority over the global configuration

2. Configure the API Key

The example above already embeds the API Key directly in opencode.json via options.apiKey. Just replace sk-123 with your own key—no extra steps required.

Optional: Manage Keys with auth.json

If you prefer not to write the API Key into opencode.json, you can remove the apiKey field from the config and instead edit ~/.local/share/opencode/auth.json:

{
  "modelsok-anthropic": {
    "type": "api",
    "key": "sk-your-modelsok-key"
  },
  "modelsok": {
    "type": "api",
    "key": "sk-your-modelsok-key"
  }
}

Or log in via the command line:

opencode auth login

Follow the prompts to enter the API Key for modelsok-anthropic and modelsok respectively.

✅ Step 3: Verify the Connection

After starting OpenCode, enter /models and check whether models such as modelsok-anthropic/claude-sonnet-4-6 and modelsok/deepseek-v4-pro appear. Select the target model, send a test message, and if you receive a normal response, the configuration was successful.

❓ FAQ

IssueSolution
/models does not show models under Models HubCheck whether provider.modelsok-anthropic.models or provider.modelsok.models in the config file has content
Model does not exist errorConfirm that the model ID matches the Models Hub console exactly
Invalid API KeyCheck that apiKey in opencode.json or auth.json is correct; you can also rerun opencode auth login
Protocol error when calling Claude modelsConfirm you are using the modelsok-anthropic provider (@ai-sdk/anthropic), not modelsok (@ai-sdk/openai-compatible)
Configuration changes have no effectRestart OpenCode; project-level config takes priority over global

On this page