📚 API 文档

欢迎使用 九六数字!本文档将帮助您快速接入我们的服务。

快速开始

1. 注册账号

访问 注册页面 创建您的账号。

2. 创建 API Key

登录后在 控制台 创建您的 API Key。

3. 充值

在控制台进行账户充值,确保有足够的余额。

4. 配置客户端

根据您使用的工具,参考下方的客户端配置指南进行配置。

5. 开始调用

使用您的 API Key 开始调用 Claude API。

客户端配置指南

我们支持多种主流 AI 编程工具,选择您使用的工具查看配置方法:

Claude Code(终端版 + VS Code 插件)

安装 Claude Code

macOS / Linux / WSL2:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex
注意:由于 Claude 官方封锁了中国及香港用户,需要翻墙至美国或日本才能下载安装。安装后可不用翻墙直连我们的服务。

配置环境变量(推荐)

macOS / Linux / WSL2:

编辑 ~/.zshrc~/.bashrc,添加:

export ANTHROPIC_BASE_URL="http://8.210.39.63:3000"
export ANTHROPIC_AUTH_TOKEN="sk-你的API Key"

保存后执行:

source ~/.zshrc  # 或 source ~/.bashrc

Windows PowerShell:

setx ANTHROPIC_BASE_URL "http://8.210.39.63:3000"
setx ANTHROPIC_AUTH_TOKEN "你的API Key"

或使用配置文件

创建/编辑 ~/.claude/settings.json

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://8.210.39.63:3000",
    "ANTHROPIC_AUTH_TOKEN": "sk-你的API Key"
  }
}

VS Code 插件配置

1. 在 VS Code 中安装 Claude Code 插件

2. 打开设置(settings.json),添加:

{
  "claude-code.env": {
    "ANTHROPIC_BASE_URL": "http://8.210.39.63:3000",
    "ANTHROPIC_API_KEY": "sk-你的API Key"
  }
}

OpenClaw

安装 OpenClaw

macOS / Linux / WSL2:

curl -fsSL https://openclaw.ai/install.sh | bash

Windows PowerShell:

iwr -useb https://openclaw.ai/install.ps1 | iex

配置 OpenClaw

编辑 ~/.openclaw/openclaw.json

{
  "agents": {
    "defaults": {
      "model": "claude-opus-4-6",
      "models": {
        "claude-opus-4-6": {}
      }
    }
  },
  "providers": {
    "proxy": {
      "baseUrl": "http://8.210.39.63:3000",
      "authHeader": true,
      "auth": "api-key",
      "apiKey": "sk-你的API Key",
      "api": "anthropic-messages",
      "models": [
        {
          "id": "claude-opus-4-6",
          "name": "claude-opus-4-6",
          "reasoning": false,
          "contextWindow": 1000000,
          "maxTokens": 65536
        }
      ]
    }
  }
}

重启服务:

openclaw gateway restart

OpenCode

编辑 ~/.config/opencode/opencode.json(或 opencode.jsonc):

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anthropic": {
      "options": {
        "baseURL": "http://8.210.39.63:3000",
        "apiKey": "sk-你的API Key"
      }
    }
  },
  "model": "anthropic/claude-opus-4-6",
  "small_model": "anthropic/claude-haiku-4-5"
}
注意:请务必使用 anthropic 协议,不要用 openai 协议,否则可能出现调用报错。

Codex CLI

编辑 ~/.codex/config.toml

model_provider = "OpenAI"
model = "gpt-5.4"
review_model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
model_context_window = 1000000
model_auto_compact_token_limit = 900000

[model_providers.OpenAI]
name = "OpenAI"
base_url = "http://8.210.39.63:3000"
wire_api = "responses"
requires_openai_auth = true

编辑 ~/.codex/auth.json

{
  "OPENAI_API_KEY": "你的API Key"
}
Codex 用户注意:创建密钥时,分组一定要选择 Codex 的分组。

Claude API 调用

POST /v1/messages

请求头

参数 类型 说明
x-api-key string 您的 API Key(必需)
anthropic-version string API 版本,固定为 2023-06-01
Content-Type string 固定为 application/json

请求体

参数 类型 说明
model string 模型名称(必需)
messages array 对话消息列表(必需)
max_tokens integer 最大生成 tokens 数(必需)
temperature float 温度参数,0-1 之间(可选)
stream boolean 是否流式返回(可选)

支持的模型

主要模型定价

模型系列 输入价格(每百万 Token) 输出价格(每百万 Token)
Claude Opus 4 $15.00 $75.00
Claude Sonnet 4 $3.00 $15.00
Claude Haiku 3.5 $0.80 $4.00

完整模型列表

工具配置时请使用完整模型名称:

推荐使用:
  • 日常编码:Sonnet 系列(性价比最高)
  • 复杂任务:Opus 系列(能力最强)
  • 不推荐:Haiku 系列(可能遇到官方限流)

Prompt Caching(提示缓存)

我们完整支持 Anthropic 的 Prompt Caching 功能,缓存命中的输入 Token 价格降低 90%,可大幅降低重复内容的费用。

示例代码

cURL

curl -X POST http://your-domain:3000/v1/messages \
  -H "x-api-key: sk-your-api-key" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello, Claude!"}
    ]
  }'

Python

import anthropic

client = anthropic.Anthropic(
    api_key="sk-your-api-key",
    base_url="http://your-domain:3000"
)

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, Claude!"}
    ]
)

print(message.content)

Node.js

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  apiKey: 'sk-your-api-key',
  baseURL: 'http://your-domain:3000'
});

const message = await client.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  messages: [
    { role: 'user', content: 'Hello, Claude!' }
  ]
});

console.log(message.content);

响应示例

{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "claude-3-5-sonnet-20241022",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 20
  }
}

用户管理 API

注册

POST /api/user/register
{
  "username": "your-username",
  "email": "your@email.com",
  "password": "your-password"
}

登录

POST /api/user/login
{
  "email": "your@email.com",
  "password": "your-password"
}

获取用户信息

GET /api/user/me

需要在请求头中携带 Authorization: Bearer <token>

创建 API Key

POST /api/user/keys
{
  "name": "生产环境",
  "rateLimit": 60
}

获取 API Keys

GET /api/user/keys

禁用 API Key

POST /api/user/keys/:keyId/disable

删除 API Key

DELETE /api/user/keys/:keyId

充值

POST /api/user/recharge
{
  "amount": 100,
  "description": "支付宝充值"
}

获取使用统计

GET /api/user/stats

获取使用记录

GET /api/user/logs?limit=100&offset=0

获取交易记录

GET /api/user/transactions?limit=100&offset=0

获取定价信息

GET /api/user/pricing

错误处理

余额不足

{
  "error": {
    "message": "账户余额不足,请充值",
    "type": "insufficient_balance"
  }
}

认证失败

{
  "error": "无效的 API Key"
}

速率限制

{
  "error": {
    "message": "请求过于频繁,请稍后再试",
    "type": "rate_limit_exceeded"
  }
}

常见问题

安装问题

Q: 安装时提示 command not found: claude

说明安装路径没有加入系统 PATH。

macOS / Linux 解决方法:

# zsh 用户(macOS 默认)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# bash 用户(Linux 默认)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Q: 安装脚本报错 syntax error near unexpected token

网络问题导致下载的是 HTML 页面而不是脚本。请检查网络连接或使用代理。

连接问题

Q: 报错 401 Unauthorized

API Key 认证失败,请检查:

Q: 报错 Connection timeout

无法连接到中转服务,请检查:

使用技巧

如何查看当前会话费用?

在 Claude Code 中输入 /cost 查看当前会话的 Token 用量和费用。

如何切换模型?

在 Claude Code 中输入 /model 然后选择想用的模型。

对话太长怎么办?

省钱技巧

费用参考

Claude Code 日均费用

根据 Anthropic 官方数据:

安全提示:
  • 请妥善保管您的 API Key,不要泄露给他人
  • 建议为不同的应用创建不同的 API Key
  • 定期检查使用统计,避免异常消费
  • 如发现 API Key 泄露,请立即禁用或删除
技术支持:

如有任何问题,请联系技术支持团队。