AIComing API
一个 API Key,调用 200+ 主流大模型。完全兼容 OpenAI SDK,支持流式、函数调用、视觉、Embeddings、图像与视频生成。把 base_url 换成 https://api.aicoming.top/v1,即可零成本切换。
注册并充值
邮箱注册,支持 Google / GitHub 登录。
创建 API Key
收藏 3 家以上商家,创建 Key 并选择路由模式。
替换 base_url 调用
OpenAI SDK / Cursor / Claude Code 零改造接入。
快速开始
把 sk-your-key 替换为你在控制台获取的 Key,立即运行。
curl https://api.aicoming.top/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-key" \
-d '{
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "你好"}]
}'
from openai import OpenAI
client = OpenAI(
api_key="sk-your-key",
base_url="https://api.aicoming.top/v1",
)
resp = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({ apiKey: "sk-your-key", baseURL: "https://api.aicoming.top/v1" });
const r = await client.chat.completions.create({ model: "gpt-5.5", messages: [{ role: "user", content: "你好" }] });
console.log(r.choices[0].message.content);鉴权与密钥
使用 Bearer Token 鉴权:
Authorization: Bearer sk-your-key
Content-Type: application/json限制 Key 可调用的模型
可为每个 API Key 设置「可调用模型白名单」:该 Key 只能调用白名单内的模型,调其它模型会被拒绝(403 model_not_allowed_for_key)。留空 = 不限制。仅限制调用,不影响计费与商家上架。
- 主站:在控制台「API Keys」页,点对应 Key 行的「限模型」勾选;分站用户:在店面「API 密钥」页点「设置」。
- 按模型名 / slug 匹配,大小写不敏感;改动后约 30 秒内生效。
模型列表
调用 GET /v1/models 获取当前可用模型。
Chat Completions
核心对话接口,请求格式与 OpenAI 100% 一致。
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
| model必填 | string | 模型 ID,如 |
| messages必填 | array | 消息数组 |
| stream | boolean | 是否流式返回。 |
| temperature | number | 0–2,默认 1。 |
| tools | array | 函数调用工具数组。 |
| response_format | object |
|
在线试用
选择你的 API Key,发送真实请求。
流式输出
设置 stream: true 返回 SSE。data: [DONE] 表示结束。
stream = client.chat.completions.create(model="gpt-5.5", messages=[{"role":"user","content":"写诗"}], stream=True)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
const stream = await client.chat.completions.create({model:"gpt-5.5",messages:[{role:"user",content:"写诗"}],stream:true});
for await(const c of stream) process.stdout.write(c.choices[0]?.delta?.content||"");图像生成 Beta
统一入口,平台按 size 自动分流 1k/2k/4k。支持文生图与图生图(编辑)两种模式。
gpt-image-2,按 max(宽,高) 自动选档:≤1024→1k · ≤2560→2k · ≤3840→4k。价格按档位计费。文生图
| 参数 | 类型 | 说明 |
|---|---|---|
| model必填 | string | 模型 ID: |
| prompt必填 | string | 文本描述,最大 32000 字符。 |
| size | string | 输出尺寸,如 详见下方尺寸约束。 |
| quality | string |
|
| n | integer | 生成数量,1–4,默认 1。 |
| response_format | string |
|
| user | string | 终端用户标识符。 |
curl https://api.aicoming.top/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-key" \
-d '{
"model": "gpt-image-2",
"prompt": "赛博朋克夜景,霓虹灯倒映在雨水中",
"size": "1792x1024",
"quality": "low",
"n": 1
}'
from openai import OpenAI
import base64
client = OpenAI(api_key="sk-your-key", base_url="https://api.aicoming.top/v1")
resp = client.images.generate(
model="gpt-image-2",
prompt="赛博朋克夜景,霓虹灯倒映在雨水中",
size="1792x1024",
quality="low",
n=1,
)
with open("out.png", "wb") as f:
f.write(base64.b64decode(resp.data[0].b64_json))图生图(编辑)
传入参考图进行编辑。也可通过 /v1/images/generations 携带 image 字段自动路由到编辑接口。
| 参数 | 类型 | 说明 |
|---|---|---|
| model必填 | string | 模型 ID: |
| prompt必填 | string | 编辑指令,最大 32000 字符。 |
| images必填 | array | 参考图数组,每项为 也可用 image 字段传字符串或数组(generations 兼容写法)。 |
| size | string | 输出尺寸,如 |
| quality | string |
|
| n | integer | 生成数量,1–4,默认 1。 |
curl https://api.aicoming.top/v1/images/edits \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-key" \
-d '{
"model": "gpt-image-2",
"prompt": "把背景换成海滩",
"images": [{"image_url": "https://example.com/ref.jpg"}],
"size": "1024x1024",
"quality": "low"
}'
from openai import OpenAI
import base64
client = OpenAI(api_key="sk-your-key", base_url="https://api.aicoming.top/v1")
# 方式一:通过 /v1/images/generations + image 字段
resp = client.images.generate(
model="gpt-image-2",
prompt="把背景换成海滩",
size="1024x1024",
n=1,
extra_body={"image": ["https://example.com/ref.jpg"]},
)
with open("edited.png", "wb") as f:
f.write(base64.b64decode(resp.data[0].b64_json))尺寸约束
| 约束 | 说明 |
|---|---|
| 最大边长 | ≤ |
| 宽高倍数 | 宽、高均为 |
| 宽高比 | 不超过 |
| 总像素数 | 655,360 ~ 8,294,400(约 0.6MP ~ 8.3MP) |
常用尺寸速查:
| 档位 | 推荐尺寸 | 比例 |
|---|---|---|
| 1K | 1024x1024 · 1536x1024 · 1024x1536 · 1792x1024 | 1:1 · 3:2 · 2:3 · 16:9 |
| 2K | 2048x2048 · 1920x1080 · 2560x1440 | 1:1 · 16:9 · 16:9 |
| 4K | 2880x2880 · 3840x2160 · 3520x2352 | 1:1 · 16:9 · 3:2 |
响应格式
{
"created": 1779622166,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}流式生图 ⚡ Streaming
设置 stream: true,接口以 SSE(Server-Sent Events)返回。stream: true 对所有生图模型可用:路由到不支持流式的渠道时,服务端在出图完成后以单个 completed 事件返回(伪流式,协议一致);渐显 partial 帧只在带「⚡ 流式」徽章的渠道且 partial_images > 0 时出现。
| 参数 | 类型 | 说明 |
|---|---|---|
| stream | boolean | 是否以 SSE 流式返回,默认 |
| partial_images | integer | 渐显 partial 帧数量,0–3,默认 |
curl -N https://aicoming.top/v1/images/generations \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"gpt-image-2-1k","prompt":"a cat","stream":true,"partial_images":2}'请求体就是普通生图请求 + "stream": true(size/quality/图生图的 image 字段都照常带;SDK 不直接支持图片流式,用 requests 逐行读 SSE):
import requests, json, base64
with requests.post(
"https://api.aicoming.top/v1/images/generations",
headers={"Authorization": "Bearer sk-your-key"},
json={
"model": "gpt-image-2",
"prompt": "a cat",
"size": "1024x1024",
"stream": True, # 开启 SSE 流式
# "partial_images": 2, # 渐显帧(当前暂关闭,可省)
# "image": ["https://.../ref.jpg"], # 图生图时加此字段
},
stream=True, timeout=300,
) as resp:
for line in resp.iter_lines():
if not line or not line.startswith(b"data: "):
continue
ev = json.loads(line[6:])
if ev["type"] == "image_generation.completed":
open("out.png", "wb").write(base64.b64decode(ev["b64_json"]))
elif ev["type"] == "error":
raise RuntimeError(ev["error"]["message"])SSE 事件流示例(依次为渐显帧、最终图、错误三种事件):
event: image_generation.partial_image
data: {"type":"image_generation.partial_image","b64_json":"iVBORw0...","partial_image_index":0,"created_at":1779622166}
event: image_generation.partial_image
data: {"type":"image_generation.partial_image","b64_json":"iVBORw0...","partial_image_index":1,"created_at":1779622172}
event: image_generation.completed
data: {"type":"image_generation.completed","b64_json":"iVBORw0KGgoAAAANSUhEUgAA...","created_at":1779622180}
# 出错时(任意阶段):
event: error
data: {"type":"error","error":{"message":"..."}}stream 与 async 互斥(同时传返回 400 stream and async are mutually exclusive);流式仅支持 n=1(否则 400 stream supports n=1 only)。异步生图
设置 async: true,提交成功返回 202 任务信封,随后用任务 id 轮询取结果(与视频生成相同的任务轮询模式,轮询免费)。若该模型当前没有支持异步的渠道,返回 400 async not supported for this model——此时去掉 async 退回同步调用即可。async 与 stream 互斥。
nano-banana-pro(Gemini 图像模型)
基于 Gemini 的高质量图像模型。同一端点支持文生图与图生图——请求体携带 image 字段时自动切换为图生图。与 gpt-image-2 不同,nano-banana-pro 不参与 1k/2k/4k 分档。
2640x1440,size / aspect_ratio 不生效(图生图时比例跟随参考图);单张耗时约 60–85s,请使用 api.aicoming.top 并放宽客户端超时;推荐传 return_url: true,响应返回 OSS 链接(data[0].url)而非 base64。| 参数 | 类型 | 说明 |
|---|---|---|
| model必填 | string | 模型 ID: |
| prompt必填 | string | 文本描述 / 编辑指令。 |
| image | string | array | 参考图 URL(字符串或数组)。传入即自动走图生图。 |
| return_url | boolean |
|
| n | integer | 生成数量,默认 1。 |
curl https://api.aicoming.top/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-key" \
-d '{
"model": "nano-banana-pro",
"prompt": "一只橘猫坐在木桌上,柔和的窗光,写实风格",
"return_url": true,
"n": 1
}'
import requests, base64
resp = requests.post(
"https://api.aicoming.top/v1/images/generations",
headers={"Authorization": "Bearer sk-your-key"},
json={"model": "nano-banana-pro",
"prompt": "一只橘猫坐在木桌上,柔和的窗光,写实风格",
"return_url": True, "n": 1},
timeout=180, # 单张约 60~85s
)
item = resp.json()["data"][0]
raw = (requests.get(item["url"]).content if item.get("url")
else base64.b64decode(item["b64_json"]))
open("out.png", "wb").write(raw)
curl https://api.aicoming.top/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-key" \
-d '{
"model": "nano-banana-pro",
"prompt": "保持人物和服装不变,背景换成樱花日式街道",
"image": "https://example.com/ref.jpg",
"return_url": true,
"n": 1
}'
import requests, base64
resp = requests.post(
"https://api.aicoming.top/v1/images/generations",
headers={"Authorization": "Bearer sk-your-key"},
json={"model": "nano-banana-pro",
"prompt": "保持人物和服装不变,背景换成樱花日式街道",
"image": "https://example.com/ref.jpg", # 多图传数组
"return_url": True, "n": 1},
timeout=180,
)
item = resp.json()["data"][0]
raw = (requests.get(item["url"]).content if item.get("url")
else base64.b64decode(item["b64_json"]))
open("edited.png", "wb").write(raw)视频生成 Beta
支持文生视频 / 图生视频(如 bytedance-seedance-2.0-text-to-video / -image-to-video 等)。异步:先提交拿 task_id,再轮询查结果视频地址。
https://api.aicoming.top(直连、超时 10 分钟),并放宽客户端超时。提交接口约 120s、轮询接口约 60s 超时。| 参数 | 类型 | 说明 |
|---|---|---|
| model必填 | string | 视频模型 ID。文生视频用 |
| prompt必填 | string | 文本描述 / 运镜指令。 |
| resolution | string | 分辨率档位: |
| seconds | integer | 时长(秒),范围 1–600,不传默认 5。别名 |
| image | string | 图生视频专用:参考图 URL(需公网可访问)。携带即自动走图生视频。 |
文生视频
{"model":"bytedance-seedance-2.0-text-to-video","prompt":"一只猫在沙滩上奔跑","resolution":"1080p","seconds":5}图生视频
传参考图 URL(公网可访问),其余同上。
{"model":"bytedance-seedance-2.0-image-to-video","prompt":"镜头缓慢推进","image":"https://cdn.aicoming.top/your-ref.png","resolution":"720p","seconds":5}提交成功后返回任务 id(位于 id 或 data[0].task_id,原样透传上游):
{"id":"task_abc123","status":"queued"}用该 id 轮询查结果(轮询免费,不计费):
任务完成后视频地址在响应中返回(字段以上游为准,常见于 data 数组或 video_url):
{"id":"task_abc123","status":"succeeded","data":[{"video_url":"https://cdn.aicoming.top/.../result.mp4"}]}每秒单价 × 时长(秒),分辨率分档(480p/720p/1080p 单价不同);部分模型按次。resolution 默认 1080p、seconds 默认 5 秒(范围 1–600)。提交失败、轮询查询均不计费。具体单价见 价格表。Embeddings
文本编码为向量。
{"model":"text-embedding-3-large","input":["AIComing 是 AI 中转平台"],"dimensions":1536}Responses API
兼容 Codex 的 /v1/responses。
curl https://api.aicoming.top/v1/responses -H "Authorization: Bearer sk-your-key" -H "Content-Type: application/json" -d '{"model":"gpt-5.5","input":"用 Python 写快排"}'SDK
API 完全兼容 OpenAI,直接使用官方 SDK:
openai (Python)
pip install openai
openai (Node.js)
npm i openai
go-openai
go get github.com/sashabaranov/go-openai
客户端配置
OPENAI_BASE_URL=https://api.aicoming.top/v1
OPENAI_API_KEY=sk-your-key
export ANTHROPIC_BASE_URL=https://api.aicoming.top/v1
export ANTHROPIC_API_KEY=sk-your-key
Settings → Models → OpenAI API Key
API Key: sk-your-key
Base URL: https://api.aicoming.top/v1
Override OpenAI Base URL: ✅
设置 → 模型提供商 → 添加自定义提供商
名称: AIComing API 地址: https://api.aicoming.top
API Key: sk-your-key 路径前缀: /v1智能路由
调用时按 Key 的策略从你收藏的商家中挑选供应商,失败自动切换到下一家,逐家轮询全部可用收藏商家,直到成功或全部失败(不再需要手动设置最大尝试数)。
| 模式 | 说明 |
|---|---|
| price_asc | 从单价最低开始(默认)。 |
| latency_first | 优先响应最快。 |
| balanced | 按商家评分排序。 |
| manual | 按你设定的顺序。 |
总路由 Key
每个账号自动生成一个总路由 Key:无需逐个指定商家,它自动覆盖你当前收藏的全部商家,以后新收藏的商家也会自动加入路由,按最低价智能选路。适合"一个 Key 走天下"。在控制台「API Keys」页顶部查看。使用前需先收藏至少一个商家。
错误码
| HTTP | type | 说明 |
|---|---|---|
| 400 | model_not_supported | Key 绑定的商家不支持此模型。 |
| 400 | providers_not_favorited | Key 的商家未在收藏列表中。 |
| 401 | unauthorized | Key 不存在或已禁用。 |
| 403 | model_not_allowed_for_key | 该 Key 设置了可调用模型白名单,当前模型不在其中。 |
| 402 | insufficient_quota | 余额不足,充值后恢复。 |
| 429 | rate_limited | 频率限制。 |
| 502 | all_providers_failed | 上游故障,稍后重试。 |
| 503 | providers_unavailable | 增加更多收藏商家。 |
计费与扣费
- Chat · 按输入/输出 tokens(¥/1M)。
- Image · 按张,1k/2k/4k 分辨率不同价。
- Video · 按时长计费:
每秒单价 × 时长(秒),分辨率分档(如 480p/720p/1080p 不同单价);部分模型按次;少数模型按 Token 计费(按上游返回的 usage token 数 × 输入/输出单价,模型页会标注/M单价)。 - Audio · 按次(¥/次)。
- 缓存 · prompt caching 命中部分按更低价计费。
- 失败 · 4xx/5xx 不计费;路由中途失败的尝试不计费。
- 余额 · 实时扣费,余额不足返回 402。