OpenCode 配置 XSI Router(Responses 优先 + Chat)

Posted January 10, 2026 by XAI 技术团队 ‐ 2 min read

opencode

OpenCode(opencode)可以通过 XSI Router 统一接入不同模型。对于 gpt-6-astra,使用 OpenCode 内置 openai provider 的 Responses 请求,由 XSI Router 转发到 OpenAI 官方 API;对于普通 OpenAI 兼容模型,则继续走标准兼容 API。本文只保留两套最常用、最可靠的配置:

  1. gpt-6-astra(Responses API)
  2. MiniMax-M2.5(Chat API)

先决条件

  1. 已在 m.xsirouter.com 创建 API Key。
  2. 本地已安装 opencode。

配置文件位置

  1. Linux/macOS:~/.config/opencode/opencode.jsonc
  2. Windows:%USERPROFILE%\.config\opencode\opencode.jsonc

同一时间只保留一套配置。切换方案时,直接覆盖 opencode.jsonc。


重要说明

  1. 本文使用的是 OpenCode 的 openai provider,并把 baseURL 指向 https://api.xsirouter.com/v1。
  2. gpt-6-astra 走 OpenAI Responses API,不需要额外的请求头。
  3. 如果你启用了 OpenCode 自带的 Codex OAuth 插件,它默认会直连 chatgpt.com/backend-api/codex/responses,不会经过 XSI Router;想走 XSI Router,就使用本文这套 openai provider 配置。

方案 A:gpt-6-astra(Responses 优先路径)

Linux/macOS

export XAI_API_KEY="sk-xxx"
mkdir -p ~/.config/opencode
cat > ~/.config/opencode/opencode.jsonc << 'JSON'
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-6-astra",
  "small_model": "openai/gpt-6-astra",
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://api.xsirouter.com/v1",
        "apiKey": "{env:XAI_API_KEY}"
      },
      "models": {
        "gpt-6-astra": {}
      }
    }
  }
}
JSON

opencode debug config
opencode run "你好"

Windows(PowerShell)

$env:XAI_API_KEY="sk-xxx"
New-Item -ItemType Directory -Path "$env:USERPROFILE\.config\opencode" -Force | Out-Null
@'
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-6-astra",
  "small_model": "openai/gpt-6-astra",
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://api.xsirouter.com/v1",
        "apiKey": "{env:XAI_API_KEY}"
      },
      "models": {
        "gpt-6-astra": {}
      }
    }
  }
}
'@ | Set-Content -Path "$env:USERPROFILE\.config\opencode\opencode.jsonc" -Encoding utf8

opencode debug config
opencode run "你好"

方案 B:MiniMax-M2.5(Chat API)

Linux/macOS

export XAI_API_KEY="sk-xxx"
mkdir -p ~/.config/opencode
cat > ~/.config/opencode/opencode.jsonc << 'JSON'
{
  "$schema": "https://opencode.ai/config.json",
  "model": "xai-chat/MiniMax-M2.5",
  "small_model": "xai-chat/MiniMax-M2.5",
  "provider": {
    "xai-chat": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.xsirouter.com/v1",
        "apiKey": "{env:XAI_API_KEY}"
      },
      "models": {
        "MiniMax-M2.5": {}
      }
    }
  }
}
JSON

opencode debug config
opencode run "你好"

Windows(PowerShell)

$env:XAI_API_KEY="sk-xxx"
New-Item -ItemType Directory -Path "$env:USERPROFILE\.config\opencode" -Force | Out-Null
@'
{
  "$schema": "https://opencode.ai/config.json",
  "model": "xai-chat/MiniMax-M2.5",
  "small_model": "xai-chat/MiniMax-M2.5",
  "provider": {
    "xai-chat": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.xsirouter.com/v1",
        "apiKey": "{env:XAI_API_KEY}"
      },
      "models": {
        "MiniMax-M2.5": {}
      }
    }
  }
}
'@ | Set-Content -Path "$env:USERPROFILE\.config\opencode\opencode.jsonc" -Encoding utf8

opencode debug config
opencode run "你好"

快速判断用哪套

  1. 你要用 gpt-6-astra:选方案 A。
  2. 你要用 MiniMax-M2.5:选方案 B。
  3. 只保留一个 opencode.jsonc,不要同时混用两套配置。