How to Configure OpenCode with HaiHub

May 26, 2026 · 1 min read · 132 Words · -Views -Comments
Opencode AI Tools CLI
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Some AI services don’t have their own CLI tools. For convenience, you can use a unified CLI terminal such as OpenCode.

Configuration Sample

Configuration location: ~/.config/opencode/opencode.json

HaiHub provides an OpenAI-compatible API. Here is the complete configuration for this example.

{
  "$schema": "https://opencode.ai/config.json",
  "model": "haihub/Kimi-K2.5",
  "provider": {
    "haihub": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "HaiHub",
      "options": {
        "baseURL": "https://api.model.haihub.cn/v1",
        "apiKey": "{env:HAIHUB_API_KEY}"
      },
      "models": {
        "Kimi-K2.5": {
          "name": "Kimi K2.5"
        },
        "Qwen3.5-397B-A17B-FP8": {
          "name": "Qwen3.5-397B-A17B-FP8"
        },
        "DeepSeek-V4-Pro": {
          "name": "DeepSeek-V4-Pro"
        }
      }
    }
  }
}
  • haihub is a provider name you choose. Set model to haihub/model-name.
  • The API is OpenAI-compatible, so set npm to @ai-sdk/openai-compatible.
  • Instead of hardcoding the secret key in apiKey, use {env:HAIHUB_API_KEY} to read the HAIHUB_API_KEY environment variable. You can choose any variable name.

Then add your secret key to ~/.zshrc:

export HAIHUB_API_KEY="sk-xxx"
Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover