HomeQuick StartOpenCode

This tutorial walks you through connecting OpenCode to OpenAI Hub, setting up a third-party model claude-opus-4-7, and pair programming with AI directly in your terminal.

Install OpenCode

Make sure Node.js 18+ is installed locally, then install OpenCode:

npm install -g opencode-ai

You can also use a one-click script on macOS / Linux:

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

Verify the installation:

opencode -v

Seeing a version number means it’s installed correctly.

Register a Custom Provider

Run in the terminal:

opencode auth login

Then follow the prompts:

  1. In the provider list, select other (scroll to the bottom or search directly)
  2. Enter openaihub as the Provider ID (this name must match exactly in the config file later)
  3. Enter your API Key obtained from OpenAI Hub, formatted like sk-xxxx

Note: The Provider ID can only contain lowercase letters and numbers—no special characters.

Edit the Configuration File

Open the configuration file:

  • macOS / Linux: ~/.config/opencode/opencode.json
  • Windows: C:\Users\YourUserName\.config\opencode\opencode.json

Replace the contents with:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openaihub": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OpenAI Hub",
      "options": {
        "baseURL": "https://api.openai-hub.com/v1",
        "apiKey": "sk-your-api-key"
      },
      "models": {
        "claude-opus-4-7": {
          "name": "Claude Opus 4 (7)",
          "limit": {
            "context": 200000,
            "output": 32768
          }
        }
      }
    }
  },
  "model": "openaihub/claude-opus-4-7"
}

A few common pitfalls:

  • openaihub must exactly match the Provider ID from the previous step—even one character off will break it.
  • baseURL must end with /v1.
  • Replace sk-your-api-key with your own OpenAI Hub API key.
  • The final "model" field sets the default model, formatted as provider-id/model-id.

Start Using

Go to your project directory and start OpenCode:

cd your-project
opencode

After startup, you can type /models to confirm that the model list includes Claude Opus 4 (7). Select it to start chatting.

Note: If you modify the configuration file, you need to exit and restart OpenCode for changes to take effect. If you don’t see the model after startup, first check whether the JSON format is valid (a stray comma is a common mistake).

Want to Add More Models?

Just keep adding under models; a single OpenAI Hub key works for all models:

"models": {
  "claude-opus-4-7": {
    "name": "Claude Opus 4 (7)",
    "limit": {
      "context": 200000,
      "output": 32768
    }
  },
  "gpt-4o": {
    "name": "GPT-4o",
    "limit": {
      "context": 128000,
      "output": 16384
    }
  },
  "claude-sonnet-4-20250514": {
    "name": "Claude Sonnet 4",
    "limit": {
      "context": 200000,
      "output": 16384
    }
  }
}

The model IDs must correspond to the supported model names listed on the OpenAI Hub platform; you can find the full list in the platform documentation.

Contact Us

We usually reply quickly during business hours

Scan WeChat

Support: Hub Assistant

WeChat ID: