快速开始

1. 注册并获取 XAI API Key

  1. 访问 m.xairouter.com 注册账号。
  2. 按提示完成邮箱验证与账户激活。
  3. 在邮箱查看系统给你创建的 XAI API Key。

2. 配置 Base URL

将你的 SDK 或应用中的 base_url 替换为 XAI Router 的 Base URL:

  • Base URL: https://api.xairouter.com

3. 发出第一个请求(几种主流协议示例)

# 将 YOUR_XAI_API_KEY 替换为你自己的 Key
export XAI_API_KEY="sk-xxxx"

3.1 OpenAI Responses API

curl https://api.xairouter.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "gpt-5.6-sol",
    "input": "你好,XAI Router!请用一句话介绍你自己。"
  }'

3.2 OpenAI Chat Completions API

curl https://api.xairouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
      "model": "gpt-5.6-sol",
      "messages": [
        {
          "role": "user",
          "content": "你好,XAI Router!请用一句话介绍你自己。"
        }
      ]
    }'

3.3 Claude API

curl https://api.xairouter.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $XAI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "你好,Claude!请用一句话介绍你自己。"
      }
    ]
  }'

3.4 Gemini API

curl -X POST "https://api.xairouter.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "x-goog-api-key: $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "你好,Gemini!请用一句话介绍你自己。"
          }
        ]
      }
    ]
  }'

4. 查看用量与账单

在 m.xairouter.com 可查看:

  • 实时用量与模型维度消耗
  • 账单与充值记录