Telegram 支持群 Telegram Support
联系支持 Support
配置报错、支付问题、工具接入卡住时,优先走支持入口。 If setup, payment, or tool integration gets stuck, start with the support channel. https://t.me/+iqkmKQHncagzYmNl
充值说明 Recharge Notice
模型按官方价格计费,页面上的重点是帮你快速把工具接起来。 Model usage follows official pricing, and this page is designed to get your tools working fast. 当前可参考:充值 10 RMB 可获得 10 USD 余额,实际请以控制台最新展示为准。 Current reference: 10 RMB recharge grants 10 USD balance. Please treat the latest console display as the source of truth.
搜索承接型文档首页 Search-oriented Docs Landing Page

Claude Code、Codex、OpenCode、OpenClaw 国内怎么接?这里直接给你可复制配置 How do you connect Claude Code, Codex, OpenCode, or OpenClaw? This page gives you copy-ready configuration blocks.

这个页面不是抽象介绍页,而是为了接住这些真实搜索需求: Claude API 国内怎么用、Codex base_url 怎么改、OpenAI API 怎么充值、Claude Code / Codex / OpenCode / OpenClaw 怎么接中转站。 统一 gateway 是 https://api.xai-router.com,统一环境变量是 XX_API_KEY This is not an abstract product page. It is built to capture practical search intent: how to use Claude API domestically, how to replace Codex base_url, how to recharge for OpenAI API usage, and how to connect Claude Code, Codex, OpenCode, or OpenClaw to a gateway. The shared gateway is https://api.xai-router.com, and the shared environment variable is XX_API_KEY.

先解决实际问题。 你最可能是为了让工具跑起来,而不是为了研究 API 平台抽象概念。 Start with the real task. Most people arrive here because they want a tool to run, not because they want platform theory.

文档负责接搜索流量。 所以这里优先给你 gateway、key、base_url、代码片段和常见报错说明。 Docs are here to capture search traffic. That means this page should prioritize gateway, key, base_url, config snippets, and common error handling.

如果你还没注册或充值。 看完配置以后,直接回主站开通,然后再回来复制代码即可。 If you have not registered or recharged yet. Finish reading the setup, open an account on the main site, and then come back for the exact snippets you need.

当前公开模型说明: 公网当前以 OpenAI GPT 模型 为主。 Claude 系列能力仍处于内部稳定性验证阶段,尚未全面开放。Claude Code 仍可通过兼容变量映射到 GPT 链路。 Current public model availability: public traffic is currently focused on OpenAI GPT models. Claude-family capabilities are still under internal validation. Claude Code can still be mapped onto GPT routes through compatible environment variables.

三步快速上手 Three-step Quick Start

1. 注册并充值 1. Register and recharge

先去主站创建账号并充值。这个文档页负责配置说明,真正的开户、余额和计费展示都在控制台。 Create your account and recharge on the main site first. This docs page focuses on setup, while account opening, balance, and billing live in the main console.

2. 复制 gateway 和 API key 2. Copy the gateway and API key

统一 gateway:https://api.xai-router.com,统一环境变量:XX_API_KEY Use the shared gateway https://api.xai-router.com and the shared environment variable XX_API_KEY.

3. 对照工具复制配置 3. Copy the exact tool config

你不需要理解所有术语,只需要找到你要用的工具,复制对应配置片段,然后启动它。 You do not need to understand every abstraction. Just find your tool, copy the right snippet, and launch it.

常见搜索词 Common search terms

Claude Code 国内怎么用、Codex base_url 怎么改、OpenAI API 支付宝充值、Cursor / OpenCode / OpenClaw 怎么接中转站。 How to use Claude Code domestically, how to replace Codex base_url, how to recharge for OpenAI API, and how to connect Cursor, OpenCode, or OpenClaw.

统一前置条件 Shared Prerequisites

本页所有示例都基于同一条接入链路和同一个 key 变量名: Every example on this page uses the same gateway and the same API key variable:

注意: 变量名只是告诉工具去哪里读 key。你仍然需要先在 shell 配置、系统环境变量或客户端配置里保存真实的 key 值。 Note: the variable name only tells the client where to read the key from. You still need to persist the real key value in your shell profile, OS environment, or client configuration first.

Codex CLI / Codex App

Codex 最常见的搜索问题是“base_url 怎么换、wire_api 该写什么、环境变量怎么放”。这里直接给你能跑的配置。 The most common Codex questions are how to replace base_url, what wire_api should be, and where the environment variable belongs. The snippet below is the direct working configuration.

配置文件路径:Linux / macOS 用 ~/.codex/config.toml,Windows 用 %USERPROFILE%\.codex\config.toml Config file path: use ~/.codex/config.toml on Linux / macOS and %USERPROFILE%\.codex\config.toml on Windows.

写入 ~/.codex/config.toml Put this in ~/.codex/config.toml
model_provider = "xai"
model = "gpt-5.5"
model_reasoning_effort = "xhigh"
plan_mode_reasoning_effort = "xhigh"
model_reasoning_summary = "none"
model_verbosity = "medium"
approval_policy = "never"
sandbox_mode = "danger-full-access"

[model_providers.xai]
name = "OpenAI"
base_url = "https://api.xai-router.com"
wire_api = "responses"
requires_openai_auth = false
env_key = "XX_API_KEY"
Linux
echo 'export XX_API_KEY="sk-..."' >> ~/.bashrc
source ~/.bashrc

codex
macOS
echo 'export XX_API_KEY="sk-..."' >> ~/.zshrc
source ~/.zshrc

codex
Windows CMD
setx XX_API_KEY "sk-..."

:: Reopen CMD, then run
codex
Windows PowerShell
[Environment]::SetEnvironmentVariable("XX_API_KEY", "sk-...", "User")

# Reopen PowerShell, then run
codex
一些较老的 macOS 终端、IDE 或继承 bash 登录环境的会话,可能在你只改了 ~/.zshrc 后仍读不到 XX_API_KEY。 如果 Codex 启动后还报缺少 key,把导出语句同步写进 ~/.bash_profile~/.bashrc Some older macOS terminals, IDE sessions, or bash-inherited login environments may still miss XX_API_KEY after you only update ~/.zshrc. If Codex still cannot read the key, mirror the export into ~/.bash_profile and ~/.bashrc.

Claude Code

Claude Code 在这个站点上的核心思路是:继续使用它熟悉的 Anthropic 兼容变量名,但把请求映射到 XAI Router 的 GPT 链路上。 For Claude Code, the practical pattern is to keep using Anthropic-compatible environment variables while routing traffic to the XAI Router GPT stack underneath.

顺序上,先设置环境变量,再运行 claude Set the environment variables first, then launch claude.

Linux / macOS
export XX_API_KEY="sk-..."
export ANTHROPIC_AUTH_TOKEN="$XX_API_KEY"
export ANTHROPIC_BASE_URL="https://api.xai-router.com"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"

claude
Windows CMD
set XX_API_KEY=sk-...
set ANTHROPIC_AUTH_TOKEN=%XX_API_KEY%
set ANTHROPIC_BASE_URL=https://api.xai-router.com
set ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-6
set ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
set ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5

claude
Windows PowerShell
$env:XX_API_KEY="sk-..."
$env:ANTHROPIC_AUTH_TOKEN=$env:XX_API_KEY
$env:ANTHROPIC_BASE_URL="https://api.xai-router.com"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"

claude
公网当前还是以 GPT 路线为主。这里保留 Claude Code 的变量形式,是为了尽量不打断你的使用习惯,而不是说明 Claude 模型本身已经全面公开。 Public traffic is still primarily GPT-oriented. The Anthropic-style variables are kept here to preserve the Claude Code workflow, not to imply that Claude models are already broadly public.

OpenCode

OpenCode 更适合“我就想把工具跑起来”的用户,所以这里给你两套配置: Responses API 推荐配置Chat API 兼容兜底配置 OpenCode is often used by people who simply want the tool to run, so this page gives you both a recommended Responses API profile and a Chat API-compatible fallback profile.

全局配置文件路径:Linux / macOS 用 ~/.config/opencode/opencode.jsonc,Windows 用 %USERPROFILE%\.config\opencode\opencode.jsonc Global config file path: use ~/.config/opencode/opencode.jsonc on Linux / macOS and %USERPROFILE%\.config\opencode\opencode.jsonc on Windows.

方案 A:Responses API Profile A: Responses API

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-5.5",
  "small_model": "openai/gpt-5.4-mini",
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://api.xai-router.com/v1",
        "apiKey": "{env:XX_API_KEY}"
      }
    }
  }
}

方案 B:Chat API 兼容兜底 Profile B: Chat API-compatible fallback

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "xai-router-chat/gpt-5.4-mini",
  "small_model": "xai-router-chat/gpt-5.4-mini",
  "provider": {
    "xai-router-chat": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.xai-router.com/v1",
        "apiKey": "{env:XX_API_KEY}"
      },
      "models": {
        "gpt-5.4-mini": {}
      }
    }
  }
}
Linux / macOS
export XX_API_KEY="sk-..."
opencode debug config
opencode run "hello"
Windows CMD
set XX_API_KEY=sk-...
opencode debug config
opencode run "hello"
Windows PowerShell
$env:XX_API_KEY="sk-..."
opencode debug config
opencode run "hello"

OpenClaw

OpenClaw 支持走 Responses API 或 Chat API。推荐优先用 api = "openai-responses",如果你需要兼容路径,再退到 Chat API。 OpenClaw can be configured against either the OpenAI Responses API or the OpenAI Chat API. Prefer api = "openai-responses" first, and only fall back to Chat compatibility when needed.

配置文件路径:Linux / macOS 用 ~/.openclaw/openclaw.json,Windows 用 %USERPROFILE%\.openclaw\openclaw.json Config file path: use ~/.openclaw/openclaw.json on Linux / macOS and %USERPROFILE%\.openclaw\openclaw.json on Windows.

模式 1:Responses API(推荐) Mode 1: Responses API compatible (recommended)

openclaw.json
{
  "agents": {
    "defaults": {
      "model": { "primary": "xai-router/gpt-5.5" }
    }
  },
  "models": {
    "mode": "merge",
    "providers": {
      "xai-router": {
        "baseUrl": "https://api.xai-router.com/v1",
        "apiKey": "${XX_API_KEY}",
        "api": "openai-responses",
        "models": [{ "id": "gpt-5.5", "name": "gpt-5.5" }]
      }
    }
  }
}

模式 2:Chat API 兼容 Mode 2: OpenAI Chat API compatible

openclaw.json
{
  "agents": {
    "defaults": {
      "model": { "primary": "xai-router/gpt-5.4-mini" }
    }
  },
  "models": {
    "mode": "merge",
    "providers": {
      "xai-router": {
        "baseUrl": "https://api.xai-router.com/v1",
        "apiKey": "${XX_API_KEY}",
        "api": "openai-completions",
        "models": [{ "id": "gpt-5.4-mini", "name": "gpt-5.4-mini" }]
      }
    }
  }
}
Linux / macOS
export XX_API_KEY="sk-..."
openclaw models status
Windows CMD
set XX_API_KEY=sk-...
openclaw models status
Windows PowerShell
$env:XX_API_KEY="sk-..."
openclaw models status
这里故意不放 Claude API 兼容示例,因为公网尚未把 Claude 模型能力作为常规公开流量开放。 A Claude API-compatible example is intentionally omitted here because public Claude traffic is not yet exposed as a general public route.

常见问题与避坑 FAQ and Common Pitfalls

我到底该改哪里:官网地址、gateway 还是 base_url? What do I actually change: website address, gateway, or base_url?

真正要改的是客户端配置里的 API 访问入口,也就是 base_url 或客户端对应的 provider/gateway 配置,不是浏览器里打开的官网地址。 What you need to change is the API access endpoint inside the client configuration, usually base_url or the client’s provider/gateway entry, not the website you open in a browser.

为什么工具还是报缺少 key? Why does the tool still say the key is missing?

最常见原因是变量没有写进当前 shell 会读取的配置文件,或者你改完后没有重开终端。先确认 XX_API_KEY 在当前会话里确实存在。 The usual cause is that the variable was not written to the shell profile actually used by the current session, or the terminal was not reopened after editing it.

为什么文档页和首页要分开? Why separate the docs page from the homepage?

因为首页负责转化和建立信任,文档页负责承接搜索流量并快速回答配置问题。这两个页面解决的是不同阶段的问题。 Because the homepage is for conversion and trust building, while the docs page is for search capture and practical configuration answers. They solve different stages of the user journey.

如果我还没注册、充值或者想问企业接入怎么办? What if I still need to register, recharge, or ask about enterprise access?

直接回主站开户,或者走支持群。企业问题优先描述你的场景、用量、权限要求和付款方式,这样响应会更快。 Go back to the main site to open the account, or use the support channel. For enterprise requests, describe your use case, expected usage, permission needs, and payment flow to get a faster answer.

下一步去哪里 Where to go next

还没开户 No account yet

先去主站注册、充值并复制 key,再回来对照本页配置即可。 Create your account, recharge, and copy the key from the main site first, then come back to apply the configuration shown here.

https://www.xai-router.com/register

已经报错或卡住 Already stuck or seeing errors

把你使用的工具名、报错信息、当前配置片段和系统环境一起发到支持入口,定位会更快。 Send the tool name, error message, current config snippet, and system details to the support channel for faster diagnosis.

https://t.me/+iqkmKQHncagzYmNl