Ainzy API 接入指南Setup Guide
接入指南Setup Guide

把 Ainzy 接进你的工具和代码

Connect Ainzy to your tools and code

接口与 OpenAI、Anthropic 官方格式一致。现有代码和工具只需要换 Base URL 和 key,别的不用改。

The API follows the OpenAI and Anthropic formats exactly. Existing code and tools only need a new base URL and key. Nothing else changes.

三步开始

Three steps

注册、充值、建令牌,然后就可以调用了。

Register, add credit, create a key. Then start calling.

01

注册账号

Register

用邮箱注册,填入邮件里的验证码即可登录。已有账号直接登录

Sign up with your email and enter the code we send you. Already have an account? Sign in.

02

充值

Add credit

进入钱包选择金额,支付宝付款。余额以美元计,按 ¥7 = $1 结算。

Open the wallet and pick an amount and pay with Alipay. Balance is in US dollars; Alipay settles at ¥7 = $1.

03

创建令牌

Create a key

令牌页新建令牌,选好分组后保存,复制以 sk- 开头的 key。分组决定这把 key 能调哪些模型、按什么价格计费。

On the keys page create a key, pick a group, save, and copy the key starting with sk-. The group decides which models the key can call and at what price.

一把 key 只属于一个分组。想同时用国产模型和 Codex,就建两把 key。

A key belongs to exactly one group. To use both the Chinese models and Codex, create two keys.

接入地址

Endpoints

同一把 key、同一个域名,三种协议都可以用,都支持流式输出。

Same key, same host, three protocols. Streaming works on all of them.

协议Protocol地址URL适用Use with
OpenAI Chathttps://ainzy.net/v1/chat/completionsOpenAI SDK、Cursor、Cline、Roo Code、绝大多数第三方应用OpenAI SDKs, Cursor, Cline, Roo Code, most third-party apps
OpenAI Responseshttps://ainzy.net/v1/responsesCodex CLI、使用 Responses API 的新版 SDKCodex CLI and SDKs that use the Responses API
Anthropic Messageshttps://ainzy.net/v1/messagesClaude Code、Anthropic SDKClaude Code, Anthropic SDKs
模型列表Model listhttps://ainzy.net/v1/models返回当前这把 key 所在分组能用的模型名Returns the model names available to this key's group

Base URL 到底填哪个

Which base URL to enter

  • OpenAI 系工具和 SDK(base_url / OPENAI_BASE_URL):填 https://ainzy.net/v1
  • Claude Code 和 Anthropic SDK(ANTHROPIC_BASE_URL):填 https://ainzy.net,不带 /v1
  • 鉴权统一用请求头 Authorization: Bearer sk-你的key;Anthropic 协议也接受 x-api-key
  • OpenAI-style tools and SDKs (base_url / OPENAI_BASE_URL): https://ainzy.net/v1
  • Claude Code and Anthropic SDKs (ANTHROPIC_BASE_URL): https://ainzy.net, without /v1
  • Authenticate with the header Authorization: Bearer sk-YOUR_KEY; the Anthropic protocol also accepts x-api-key

不确定模型名时,先请求一次 /v1/models,列表里有的就能用。模型名区分大小写。

Not sure about a model name? Call /v1/models first. Anything in the list works. Model names are case-sensitive.

分组与模型

Groups & models

创建令牌时选择分组。价格以价格页为准,页面会按你的分组实时显示每百万 token 的单价。

Pick a group when creating a key. Prices live on the pricing page, which shows the per-million-token rate for your group.

分组Group模型Models说明Notes
国模官方 1.5 折高缓存组Chinese models, 15% of list, high cache
chinese-model-15
deepseek-v4-flash deepseek-v4-flash-0731 deepseek-v4-pro
glm-5.3 glm-5.2 glm-5.3-flash
kimi-k3
DeepSeek、智谱 GLM、Kimi。按官方牌价 1.5 折计费,缓存命中另按缓存价DeepSeek, Zhipu GLM and Kimi at 15% of official list price. Cache hits are billed at the cache rate
国模官方 2.5 折组Chinese models, 25% of list
chinese-model-25
deepseek-v4.1-flash DeepSeek V4.1 Flash,支持 reasoning_effortDeepSeek V4.1 Flash, supports reasoning_effort
Codex
codex
gpt-5.4 gpt-5.5 gpt-5.6 gpt-5.6-sol gpt-5.6-terra
gpt-5.3-codex-spark codex-auto-review gpt-6-astra
GPT 与 Codex 系列,走 /v1/responses/v1/chat/completions 都可以GPT and Codex models, via /v1/responses or /v1/chat/completions
Grok
grok
grok-4.3 grok-4.5 grok-4.6 xAI Grok 系列xAI Grok models

工具接入

Tools

常用编程工具的配置方法。图形化切换请用 CC Switch,它会替你管理这些配置文件,并且能一键拉取你这把 key 能用的模型。

Configs for common coding tools. For a graphical switcher use CC Switch. It manages these config files for you and can fetch the models your key can use.

Claude Code

令牌选「国模官方 1.5 折高缓存组」,把下面这段加进 ~/.claude/settings.json(Windows 在 %USERPROFILE%\.claude\settings.json):

Create a key in the chinese-model-15 group and add this to ~/.claude/settings.json (on Windows: %USERPROFILE%\.claude\settings.json):

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ainzy.net",
    "ANTHROPIC_AUTH_TOKEN": "sk-你的key",
    "ANTHROPIC_MODEL": "glm-5.3",
    "ANTHROPIC_SMALL_FAST_MODEL": "glm-5.3-flash"
  }
}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ainzy.net",
    "ANTHROPIC_AUTH_TOKEN": "sk-YOUR_KEY",
    "ANTHROPIC_MODEL": "glm-5.3",
    "ANTHROPIC_SMALL_FAST_MODEL": "glm-5.3-flash"
  }
}

也可以直接设环境变量后运行 claude。模型名可换成同分组里的 kimi-k3deepseek-v4-pro 等。

Setting the same environment variables before running claude also works. Swap the model for any other in the group, such as kimi-k3 or deepseek-v4-pro.

Codex CLI

令牌选「Codex」分组,编辑 ~/.codex/config.toml

Create a key in the Codex group and edit ~/.codex/config.toml:

model = "gpt-5.5"
model_provider = "ainzy"

[model_providers.ainzy]
name = "Ainzy"
base_url = "https://ainzy.net/v1"
env_key = "AINZY_API_KEY"
wire_api = "responses"
model = "gpt-5.5"
model_provider = "ainzy"

[model_providers.ainzy]
name = "Ainzy"
base_url = "https://ainzy.net/v1"
env_key = "AINZY_API_KEY"
wire_api = "responses"

然后设环境变量 AINZY_API_KEY=sk-你的key 再运行 codex

Then set AINZY_API_KEY=sk-YOUR_KEY in your environment and run codex.

Cursor / Cline / Roo Code / 其他 OpenAI 兼容工具

Cursor / Cline / Roo Code / other OpenAI-compatible tools

  • 提供商选 OpenAIOpenAI Compatible
  • Base URL 填 https://ainzy.net/v1,API Key 填你的 sk- key
  • 模型名手动填写分组里的模型,例如 deepseek-v4-flashgpt-5.5grok-4.6
  • Choose OpenAI or OpenAI Compatible as the provider
  • Base URL https://ainzy.net/v1, API key your sk- key
  • Type the model name from your group, e.g. deepseek-v4-flash, gpt-5.5, grok-4.6

Cursor 覆盖 OpenAI Base URL 后请点「Verify」,通过即表示 key 和地址都对。

In Cursor, click "Verify" after overriding the OpenAI base URL. A pass means both the key and the URL are correct.

代码示例

Code samples

sk-你的key 换成你的令牌、模型名换成分组里的模型,直接运行。

Replace sk-YOUR_KEY with your key and the model with one from your group, then run.

curl https://ainzy.net/v1/chat/completions \
  -H "Authorization: Bearer sk-你的key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "你好,介绍一下你自己"}],
    "stream": true
  }'
curl https://ainzy.net/v1/chat/completions \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Hi, introduce yourself"}],
    "stream": true
  }'
from openai import OpenAI

client = OpenAI(base_url="https://ainzy.net/v1", api_key="sk-你的key")

stream = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "你好,介绍一下你自己"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
from openai import OpenAI

client = OpenAI(base_url="https://ainzy.net/v1", api_key="sk-YOUR_KEY")

stream = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "Hi, introduce yourself"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://ainzy.net/v1", apiKey: "sk-你的key" });

const stream = await client.chat.completions.create({
  model: "kimi-k3",
  messages: [{ role: "user", content: "你好,介绍一下你自己" }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://ainzy.net/v1", apiKey: "sk-YOUR_KEY" });

const stream = await client.chat.completions.create({
  model: "kimi-k3",
  messages: [{ role: "user", content: "Hi, introduce yourself" }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
import anthropic

client = anthropic.Anthropic(base_url="https://ainzy.net", api_key="sk-你的key")

with client.messages.stream(
    model="glm-5.3",
    max_tokens=1024,
    messages=[{"role": "user", "content": "你好,介绍一下你自己"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
import anthropic

client = anthropic.Anthropic(base_url="https://ainzy.net", api_key="sk-YOUR_KEY")

with client.messages.stream(
    model="glm-5.3",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hi, introduce yourself"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
curl https://ainzy.net/v1/responses \
  -H "Authorization: Bearer sk-你的key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "input": "用一句话解释什么是 API 网关"
  }'
curl https://ainzy.net/v1/responses \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "input": "Explain what an API gateway is in one sentence"
  }'

Responses 示例需要 Codex 分组的 key;其余示例用国产模型分组的 key 即可。

The Responses sample needs a Codex-group key. The others work with a Chinese-model-group key.

计费说明

Billing

  • 按量计费,无月费。只按实际消耗的 token 扣费,输入、输出、缓存命中分别计价。
  • 美元计价。余额单位是美元,价格页显示每百万 token 的美元单价。支付宝按 ¥7 = $1 换算。
  • 分组决定折扣。同一模型在不同分组价格不同,令牌建好后分组即固定。
  • 缓存命中更便宜。国产模型分组对命中缓存的输入 token 按缓存价计费,重复上下文越多越省。
  • 失败请求不扣费。返回错误的请求不会计入账单。
  • 不限单账号并发。没有每账号并发上限,高并发直接跑即可。
  • 邀请返利 10%。钱包页拿邀请链接,被邀请用户每笔充值的 10% 会在几分钟内进入你的邀请奖励,可划转到余额。
  • Pay as you go, no monthly fee. Only tokens actually consumed are charged. Input, output and cache-hit tokens are priced separately.
  • Priced in US dollars. Balance is in USD and the pricing page shows USD per million tokens. Alipay converts at ¥7 = $1.
  • The group sets the discount. The same model costs differently in different groups, and a key's group is fixed once created.
  • Cache hits cost less. In the Chinese-model groups, cached input tokens are billed at the cache rate. The more repeated context, the more you save.
  • Failed requests are free. Requests that return an error are not billed.
  • No per-account concurrency cap. Run as many parallel requests as you need.
  • 10% referral rebate. Get your invite link on the wallet page. 10% of every top-up by an invited user lands in your referral balance within minutes and can be moved to your main balance.

每一次调用的模型、token 数、扣费都记录在使用日志,账单逐条可查。

Every call's model, token counts and charge are recorded in the usage log, so the bill is auditable line by line.

错误对照

Errors

常见报错和处理方法。

Common errors and what to do about them.

状态Status返回内容Response原因与处理Cause and fix
401Invalid tokenkey 填错、没有 sk- 前缀、请求头不是 Bearer,或令牌已被禁用。到令牌页重新复制。Wrong key, missing sk- prefix, header not Bearer, or the key is disabled. Copy it again from the keys page.
404model_not_found
No available channel for the requested model
这把 key 的分组里没有这个模型。检查模型名拼写,或换用对应分组的 key。用 /v1/models 可以看当前 key 能用什么。The key's group does not include this model. Check the spelling or use a key from the right group. /v1/models lists what this key can use.
403用户额度不足Insufficient quota
剩余额度: $…remaining: $…
余额不够本次请求的预估费用。到钱包充值后重试。Balance is below the estimated cost of this request. Top up in the wallet and retry.
429请求过于频繁Too many requests短时间请求量过大,退避几秒后重试即可。Too many requests in a short window. Back off a few seconds and retry.
5xxupstream_error模型侧临时故障,稍后重试。失败请求不计费。持续出现请联系我们。Temporary fault on the model side. Retry later. Failed requests are not billed. Contact us if it persists.

常见问题

FAQ

国产模型第一个字出来很慢?

部分国产模型在回答前会先完成思考,首字通常在 10 秒左右,之后输出很快。建议始终开启 stream: true,客户端超时设到 120 秒以上。

一把 key 能不能同时用 Claude Code 和 Codex?

不能。key 属于分组,分组决定模型。Claude Code 用国产模型分组的 key,Codex 用 Codex 分组的 key,建两把即可。CC Switch 可以一键在两者之间切换。

调用日志里的费用和价格页对不上?

价格页显示的是每百万 token 的单价,日志里是本次请求的实际扣费,等于输入 token × 输入单价 + 输出 token × 输出单价 + 缓存命中 token × 缓存单价,再除以一百万。

支持函数调用、JSON 模式、视觉输入吗?

跟随模型本身的能力,网关原样透传请求参数。工具调用、JSON 输出、视觉输入等以各模型官方文档为准,参数写法与官方 API 一致,无需改动。

如何联系人工?

邮件 [email protected]。写明账号邮箱、出错时间和使用日志里的那条记录,我们能更快定位。

The first token from a Chinese model is slow?

Some of these models think before they answer, so the first token usually arrives after about 10 seconds and the rest streams quickly. Always use stream: true and set the client timeout to 120 seconds or more.

Can one key serve both Claude Code and Codex?

No. A key belongs to a group and the group decides the models. Use a Chinese-model-group key for Claude Code and a Codex-group key for Codex. CC Switch can flip between them with one click.

The charge in the usage log does not match the pricing page?

The pricing page shows the rate per million tokens. The log shows the actual charge for one request: input tokens × input rate + output tokens × output rate + cached tokens × cache rate, divided by one million.

Are function calling, JSON mode and vision supported?

Whatever the model itself supports. The gateway passes request parameters through unchanged, so tool calling, JSON output and vision follow each model's official documentation, with the same parameter names as the official API.

How do I reach a human?

Email [email protected]. Include your account email, the time of the request and the matching line from the usage log so we can find it quickly.

开始使用

Get started

注册账号,充值后建一把令牌就能调用

Register, add credit, create a key, and start calling

免费注册 →Create account →