⚡ 5分钟接入指南

AI-Bridge 提供统一的 API 接口,兼容 OpenAI 格式。国内直连官方原生通道,无需修改现有代码即可接入 Claude Code、Codex、Cursor 等开发工具。

  1. 注册账号并购买套餐

    前往 注册页 创建账号,然后在 产品页 购买 Token 套餐。Token 永不过期,按实际用量消耗。

  2. 创建 API 密钥

    登录后进入 API 密钥 页面,点击「创建新密钥」,复制生成的 ab-... 格式密钥。

  3. 配置客户端

    将客户端的 Base URL 指向 AI-Bridge,API Key 填入您的 ab-... 密钥,即可开始使用。

✓ 就这么简单! 国内直连官方原生通道,无需配置代理,无需海外信用卡,即刻接入 Claude Code、Codex、Cursor 等工作流。

🔧 客户端配置

Claude Code / Claude Desktop

在终端或 .env 文件中设置以下环境变量:

# Claude 客户端配置 ANTHROPIC_BASE_URL=https://your-server.com:3001 ANTHROPIC_API_KEY=ab-xxxxxxxxxxxxxxxx # 填入 AI-Bridge 密钥

OpenAI 格式客户端(通用)

所有支持自定义 Base URL 的 OpenAI 兼容客户端均可使用:

OPENAI_BASE_URL=https://your-server.com:3001/v1 OPENAI_API_KEY=ab-xxxxxxxxxxxxxxxx

Python SDK

import anthropic client = anthropic.Anthropic( base_url="https://your-server.com:3001", api_key="ab-xxxxxxxxxxxxxxxx", ) message = client.messages.create( model="claude-3-5-sonnet-20241022", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}] )

Node.js SDK

import Anthropic from '@anthropic-ai/sdk'; const client = new Anthropic({ baseURL: 'https://your-server.com:3001', apiKey: 'ab-xxxxxxxxxxxxxxxx', });

curl 直接调用

curl -X POST https://your-server.com:3001/v1/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-3-5-sonnet-20241022", "messages": [{"role": "user", "content": "你好"}] }'
提示: 请将 your-server.com 替换为实际服务器地址,ab-xxxxxxxxxxxxxxxx 替换为您的 AI-Bridge 密钥。密钥可在 API 密钥 页面创建。

🤖 支持的模型

AI-Bridge 支持国际顶级大模型,通过统一接口访问,系统自动处理协议转换和故障转移。

模型 提供商 优势 上下文 状态
Claude 3.5 Sonnet Anthropic 代码能力最强,推理准确 200K 推荐
Claude 3.5 Haiku Anthropic 响应速度快,成本低 200K 可用
Claude 3 Opus Anthropic 最强通用能力,适合复杂任务 200K 可用
GPT-4o OpenAI 多模态,通用能力强 128K 备用
GPT-4o Mini OpenAI 高性价比,快速响应 128K 备用
Gemini 2.0 Pro Google 超长上下文,大代码库分析 100万+ 备用
Gemini 2.0 Flash Google 极速响应,低延迟 100万+ 备用
说明: 实际可用模型取决于管理员配置的 API Key。如某模型不可用,系统会自动故障转移到其他模型。

🟠 Claude 模型

Claude 是 AI-Bridge 的首选模型,代码生成能力全球顶尖,支持超长上下文,特别适合 Claude Code 等编程工具。

可用 Model ID

Claude 3.5 Sonnet

代码能力最强,推荐首选

claude-3-5-sonnet-20241022

Claude 3.5 Haiku

速度最快,适合简单任务

claude-3-5-haiku-20241022

Claude 3 Opus

最强通用,复杂推理

claude-3-opus-20240229

专属接入方式(原生 Anthropic 格式)

# 使用 Anthropic 原生消息格式 curl -X POST https://your-server.com:3001/v1/messages \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-3-5-sonnet-20241022", "max_tokens": 2048, "messages": [{"role": "user", "content": "请写一个快速排序算法"}] }'

🟢 GPT 模型(OpenAI)

GPT-4o 是 OpenAI 的旗舰模型,多模态能力强,通用场景表现优异,作为 Claude 的备用选项。

可用 Model ID

GPT-4o

旗舰模型,多模态能力

gpt-4o

GPT-4o Mini

高性价比,快速响应

gpt-4o-mini

调用示例

curl -X POST https://your-server.com:3001/v1/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "messages": [{"role": "user", "content": "帮我写一篇产品介绍"}] }'
Codex CLI 用户: 如需使用 Codex 等 OpenAI 专用工具,请参考 Codex CLI 接入 章节,使用 /v1/openai 专用路径。

🔵 Gemini 模型(Google)

Gemini 最大的优势是超长上下文(最高 200 万 Token),特别适合需要分析大型代码库或长文档的场景。

可用 Model ID

Gemini 2.0 Pro

100万+上下文,大代码库

gemini-2.0-pro-exp

Gemini 2.0 Flash

极速版,低延迟

gemini-2.0-flash-exp

调用示例

curl -X POST https://your-server.com:3001/v1/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-2.0-pro-exp", "messages": [{"role": "user", "content": "分析这段代码..."}] }'

📡 流式输出(SSE)

AI-Bridge 完整支持 Server-Sent Events (SSE) 流式输出,Claude Code 等工具默认使用流式模式。

启用流式输出

在请求体中添加 "stream": true 即可:

# 流式输出,加 -N 参数实时显示 curl -N -X POST https://your-server.com:3001/v1/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-3-5-sonnet-20241022", "messages": [{"role": "user", "content": "写一首诗"}], "stream": true }' # 期望输出:逐行收到 data: {...},最后 data: [DONE]

Python 流式示例

import anthropic client = anthropic.Anthropic( base_url="https://your-server.com:3001", api_key="ab-xxxxxxxxxxxxxxxx", ) with client.messages.stream( model="claude-3-5-sonnet-20241022", max_tokens=1024, messages=[{"role": "user", "content": "讲个故事"}], ) as stream: for text in stream.text_stream: print(text, end="", flush=True)

🔄 自动故障转移

当某个模型 API 不可用时,AI-Bridge 自动切换到备用模型,确保服务 99%+ 可用性。

故障转移链路

用户请求 Claude 3.5 Sonnet ↓ Claude API 超时 / 失败 ↓ 自动切换到 GPT-4o (备用1) ↓ GPT-4o 失败 ↓ 自动切换到 Gemini 2.0 Pro (备用2) ↓ 返回响应给用户(包含实际使用的模型信息)

响应中包含实际使用的模型

// 响应示例:请求 claude,但系统自动用了 gpt-4o { "id": "chatcmpl-xxx", "model": "gpt-4o", // 实际使用的模型 "provider": "openai", // 实际使用的提供商 "choices": [...] }
Token 计费: 故障转移时,按实际使用的模型 Token 计费。不同模型的 Token 消耗倍率不同,请参考 套餐页面 了解详情。

💻 Codex CLI 接入

AI-Bridge 为 Codex CLI 等 OpenAI 原生工具提供专用透传路由 /v1/openai,完整兼容所有 OpenAI API。

配置方式

# Codex CLI 专用配置 export OPENAI_API_KEY=ab-xxxxxxxxxxxxxxxx # 填入 AI-Bridge 密钥 export OPENAI_BASE_URL=https://your-server.com:3001/v1/openai # 然后正常使用 codex 命令 codex "帮我修复这个 bug"

验证连接

# 测试模型列表接口(Codex 启动时会调用) curl https://your-server.com:3001/v1/openai/models \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" # 测试流式对话 curl -N https://your-server.com:3001/v1/openai/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":"hi"}],"stream":true}'
前提条件: 管理员需在后台「系统设置」中配置 OPENAI_API_KEY。请联系服务提供商确认已完成配置。

❓ 常见问题

Token 会过期吗?
购买的 Token 永不过期,您随时可以使用。只要账号正常,Token 会一直保留在余额中。
如何计算 Token 用量?
Token 按照 API 实际返回的用量计算,包含输入(prompt)和输出(completion)Token。每次请求结束后,系统会根据返回的 usage 字段精确扣除。可在「额度管理」页面查看每次消耗明细。
不同模型的 Token 消耗一样吗?
不同模型 Token 消耗倍率不同。Claude 和 GPT-4o 等高端模型倍率较高,GPT-4o Mini 等轻量模型倍率较低。具体倍率请参考套餐页面的说明。
为什么请求返回的模型和我请求的不一样?
这是自动故障转移机制触发了。当您指定的模型暂时不可用时,系统会自动切换到备用模型确保请求成功。响应体中的 model 字段反映了实际使用的模型。如果不需要自动切换,可以联系管理员关闭此功能。
API 密钥和上游 Anthropic Key 有什么区别?
AI-Bridge API 密钥(ab-...):用于向 AI-Bridge 发起请求,消耗您购买的 Token 套餐。这是您日常在客户端填写的密钥。

上游 Anthropic Key:如果您有自己的 Anthropic 官方 API Key,可在「个人设置」中托管,此时系统优先使用您自己的 Key 而非平台公用 Key,额度独立计算。
如何申请退款?
未使用的 Token 额度可以申请退款。请在「我的订单」页面找到对应订单,或直接联系客服,提供订单号后由人工处理退款。
响应速度慢怎么办?
响应速度取决于:1)当前网络线路质量;2)所选模型本身的响应时间;3)上游 API 负载。
建议:优先使用 Claude 3.5 Haiku 或 GPT-4o Mini 等轻量模型;如速度持续异常,请联系管理员检查 IP 池状态。

5-Minute Setup Guide

AI-Bridge provides a unified API compatible with OpenAI format. Connect to Claude Code, Codex, Cursor and more with native API channels — no code changes required.

  1. Sign up and choose a plan

    Go to Sign Up to create an account, then purchase a token plan from Products. Tokens never expire.

  2. Create an API key

    After login, go to API Keys and click "Create New Key". Copy the generated ab-... key.

  3. Configure your client

    Point your client's Base URL to AI-Bridge and use your ab-... key. That's it.

That's it! Direct native channels. No VPN needed. No overseas credit card. Instantly connect to Claude Code, Codex, Cursor workflows.

Client Configuration

Claude Code / Claude Desktop

Set the following environment variables in your terminal or .env file:

# Claude client config ANTHROPIC_BASE_URL=https://your-server.com:3001 ANTHROPIC_API_KEY=ab-xxxxxxxxxxxxxxxx

OpenAI-Compatible Clients

OPENAI_BASE_URL=https://your-server.com:3001/v1 OPENAI_API_KEY=ab-xxxxxxxxxxxxxxxx

Python SDK

import anthropic client = anthropic.Anthropic( base_url="https://your-server.com:3001", api_key="ab-xxxxxxxxxxxxxxxx", ) message = client.messages.create( model="claude-3-5-sonnet-20241022", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}] )

Node.js SDK

import Anthropic from '@anthropic-ai/sdk'; const client = new Anthropic({ baseURL: 'https://your-server.com:3001', apiKey: 'ab-xxxxxxxxxxxxxxxx', });

curl

curl -X POST https://your-server.com:3001/v1/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{"model":"claude-3-5-sonnet-20241022","messages":[{"role":"user","content":"Hello"}]}'
Note: Replace your-server.com with the actual server address and ab-xxxxxxxxxxxxxxxx with your AI-Bridge key.

Supported Models

AI-Bridge supports top-tier international models through a unified interface with automatic protocol conversion and failover.

Model Provider Strength Context Status
Claude 3.5 Sonnet Anthropic Best for code, accurate reasoning 200K Recommended
Claude 3.5 Haiku Anthropic Fast responses, low cost 200K Available
Claude 3 Opus Anthropic Strongest general ability 200K Available
GPT-4o OpenAI Multimodal, strong general purpose 128K Backup
GPT-4o Mini OpenAI High value, fast 128K Backup
Gemini 2.0 Pro Google Ultra-long context, large codebases 1M+ Backup
Gemini 2.0 Flash Google Ultra-fast, low latency 1M+ Backup
Note: Available models depend on admin configuration. If a model is unavailable, the system automatically fails over to alternatives.

Claude Models

Claude is AI-Bridge's primary model, with world-class code generation and ultra-long context support, ideal for Claude Code and other programming tools.

Available Model IDs

Claude 3.5 Sonnet

Best for code, recommended default

claude-3-5-sonnet-20241022

Claude 3.5 Haiku

Fastest, ideal for simple tasks

claude-3-5-haiku-20241022

Claude 3 Opus

Strongest general, complex reasoning

claude-3-opus-20240229

GPT Models (OpenAI)

GPT-4o is OpenAI's flagship model with strong multimodal capabilities, serving as a backup option to Claude.

Available Model IDs

GPT-4o

Flagship model, multimodal

gpt-4o

GPT-4o Mini

High value, fast responses

gpt-4o-mini

Gemini Models (Google)

Gemini's biggest advantage is ultra-long context (up to 2M tokens), ideal for analyzing large codebases or long documents.

Available Model IDs

Gemini 2.0 Pro

1M+ context, large codebases

gemini-2.0-pro-exp

Gemini 2.0 Flash

Ultra-fast, low latency

gemini-2.0-flash-exp

Streaming (SSE)

AI-Bridge fully supports Server-Sent Events streaming. Claude Code and similar tools use streaming by default.

Enable Streaming

Add "stream": true to your request body:

# Streaming output, use -N for real-time display curl -N -X POST https://your-server.com:3001/v1/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{"model":"claude-3-5-sonnet-20241022","messages":[{"role":"user","content":"Hello"}],"stream":true}'

Python Streaming Example

import anthropic client = anthropic.Anthropic( base_url="https://your-server.com:3001", api_key="ab-xxxxxxxxxxxxxxxx", ) with client.messages.stream( model="claude-3-5-sonnet-20241022", max_tokens=1024, messages=[{"role": "user", "content": "Tell a story"}], ) as stream: for text in stream.text_stream: print(text, end="", flush=True)

Auto Failover

When a model API is unavailable, AI-Bridge automatically switches to a backup model to ensure 99%+ service availability.

Failover Chain

User requests Claude 3.5 Sonnet ↓ Claude API timeout / failure ↓ Auto switch to GPT-4o (backup 1) ↓ GPT-4o failure ↓ Auto switch to Gemini 2.0 Pro (backup 2) ↓ Return response (includes actual model used)

Response includes actual model used

// Response example: requested claude, system used gpt-4o { "id": "chatcmpl-xxx", "model": "gpt-4o", // actual model used "provider": "openai", // actual provider "choices": [...] }
Billing: During failover, tokens are billed based on the model actually used. Different models have different token multipliers. See Products for details.

Codex CLI Integration

AI-Bridge provides a dedicated passthrough route /v1/openai for Codex CLI and other native OpenAI tools, fully compatible with all OpenAI APIs.

Configuration

# Codex CLI configuration export OPENAI_API_KEY=ab-xxxxxxxxxxxxxxxx export OPENAI_BASE_URL=https://your-server.com:3001/v1/openai # Then use codex normally codex "fix this bug"

Verify Connection

# Test models endpoint (Codex calls this on startup) curl https://your-server.com:3001/v1/openai/models \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" # Test streaming chat curl -N https://your-server.com:3001/v1/openai/chat/completions \ -H "Authorization: Bearer ab-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":"hi"}],"stream":true}'
Prerequisite: Admin must configure OPENAI_API_KEY in the system settings. Contact your service provider to confirm.

FAQ

Do tokens expire?
No. Purchased tokens are permanent with no time limit. As long as your account is active, tokens remain in your balance.
How is token usage calculated?
Based on the actual usage field returned by the API, including input (prompt) and output (completion) tokens. After each request, the system deducts precisely based on the returned usage. You can view detailed consumption in the "Quota Management" page.
Do different models consume tokens at the same rate?
No. Different models have different token multipliers. Premium models like Claude and GPT-4o have higher rates, while lightweight models like GPT-4o Mini have lower rates. See the Products page for details.
Why is the response model different from what I requested?
This means auto failover was triggered. When your specified model is temporarily unavailable, the system automatically switches to a backup model. The model field in the response reflects the actual model used. Contact admin to disable this if needed.
What's the difference between AI-Bridge key and Anthropic key?
AI-Bridge API key (ab-...): Used to authenticate with AI-Bridge, consuming your purchased tokens. This is the key you use in your client.

Upstream Anthropic key: If you have your own official Anthropic API key, you can add it in Settings for priority routing with independent quota.
How do I request a refund?
Unused token balance can be refunded. Find the order in "My Orders" page, or contact support with your order number for manual processing.
What if responses are slow?
Response speed depends on: 1) Network quality; 2) The model's inherent response time; 3) Upstream API load.
Tips: Use lightweight models like Claude 3.5 Haiku or GPT-4o Mini. If speed issues persist, contact admin to check IP pool status.