API · api.we2ai.com
API docsAPI 文档
One base URL and one key for Claude, GPT, Gemini and Grok — text, image and video. Use the official SDKs of each vendor; only the base URL and the key change. 一个 Base URL、一把 Key,调用 Claude、GPT、Gemini、Grok 的文本、图片和视频模型。直接用各家官方 SDK,只需要改 Base URL 和 Key。
Quick start快速开始
- Sign up and create an API key in the console. Pick the group that matches the models you want (see Groups & endpoints). 注册后在控制台创建 API Key,分组选你要用的模型所在的组(见分组与端点)。
- Point your SDK at
https://api.we2ai.com(Anthropic / Gemini style) orhttps://api.we2ai.com/v1(OpenAI style). 把 SDK 的 Base URL 指向https://api.we2ai.com(Anthropic、Gemini 风格)或https://api.we2ai.com/v1(OpenAI 风格)。 - Send a request.
/v1/chat/completionsworks for every group, so it is the easiest first call: 发请求。/v1/chat/completions对所有分组都可用,用它做第一次调用最省事:
curl https://api.we2ai.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"messages": [{"role": "user", "content": "Say hi in 3 words"}]
}'
from openai import OpenAI
client = OpenAI(api_key="sk-your-api-key", base_url="https://api.we2ai.com/v1")
resp = client.chat.completions.create(
model="gpt-6-luna",
messages=[{"role": "user", "content": "Say hi in 3 words"}],
)
print(resp.choices[0].message.content)
model with any model your key's group can call. The list changes as we add models — GET /v1/models always returns the current one for your key (see Models & usage).
model 换成你的 Key 所在分组可调用的任意模型。模型会持续更新,GET /v1/models 永远返回你这把 Key 当前可用的列表(见模型与用量)。
Authentication认证
Send your key in any one of these headers. Use whichever your SDK already sends. 在下面任意一个请求头里带上 Key,用你的 SDK 默认发送的那个即可。
| Header | Typical use常见用法 |
|---|---|
Authorization: Bearer sk-… | OpenAI SDKs, curl, CodexOpenAI SDK、curl、Codex |
x-api-key: sk-… | Anthropic SDKsAnthropic SDK |
x-goog-api-key: … | Gemini / Google SDKsGemini / Google SDK |
Groups & endpoints分组与端点
Every key belongs to a group, and the group decides which models it can call. Base URL for all endpoints: https://api.we2ai.com.
每把 Key 属于一个分组,分组决定能调用哪些模型。所有端点的 Base URL 都是 https://api.we2ai.com。
| Group分组 | Models模型 | Endpoints端点 |
|---|---|---|
| Claude | Claude | POST /v1/messagesPOST /v1/chat/completions |
| OpenAI | GPT, Codex | POST /v1/chat/completionsPOST /v1/responses |
| Image-2 | GPT ImageGPT 图片模型 | POST /v1/images/generationsPOST /v1/images/edits |
| Gemini | Gemini (text & image文本与图片) | POST /v1beta/models/{model}:generateContentPOST /v1beta/models/{model}:streamGenerateContentPOST /v1/chat/completions |
| Grok | Grok (text, image, video文本、图片、视频) | POST /v1/chat/completionsPOST /v1/responsesPOST /v1/images/generationsPOST /v1/videos |
| Volcengine | Doubao-Seedance (video视频) | POST /v1/videosGET /v1/videos/{request_id}GET /v1/videos/{request_id}/content |
Calling a model your group does not serve returns an error (see Errors). To use several vendors, create one key per group. 调用你所在分组没有的模型会返回错误(见错误处理)。要同时用多家模型,就为每个分组各建一把 Key。
Streaming works on every text endpoint: set "stream": true (Gemini: use :streamGenerateContent). Responses are standard Server-Sent Events.
所有文本端点都支持流式:设置 "stream": true(Gemini 用 :streamGenerateContent),返回标准 Server-Sent Events。
Claude
The native Anthropic Messages API. Use the official Anthropic SDK with base_url="https://api.we2ai.com".
原生 Anthropic Messages API。使用官方 Anthropic SDK,base_url="https://api.we2ai.com"。
curl https://api.we2ai.com/v1/messages \
-H "x-api-key: sk-your-api-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Say hi in 3 words"}]
}'
import anthropic
client = anthropic.Anthropic(api_key="sk-your-api-key", base_url="https://api.we2ai.com")
msg = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hi in 3 words"}],
)
print(msg.content[0].text)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: "sk-your-api-key", baseURL: "https://api.we2ai.com" });
const msg = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Say hi in 3 words" }],
});
console.log(msg.content[0].text);
Images go in as image content blocks (base64), exactly as in Anthropic's API.
图片以 image 内容块(base64)传入,和 Anthropic 官方 API 一致。
OpenAI / GPT
OpenAI-compatible Chat Completions and Responses. Use the official OpenAI SDK with base_url="https://api.we2ai.com/v1".
兼容 OpenAI 的 Chat Completions 与 Responses。使用官方 OpenAI SDK,base_url="https://api.we2ai.com/v1"。
curl https://api.we2ai.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"stream": true,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write quicksort in Python."}
]
}'
curl https://api.we2ai.com/v1/responses \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-6-luna", "input": "Say hi in 3 words"}'
The Responses API is what Codex uses — see Claude Code & Codex. Codex 使用的就是 Responses API,配置见 Claude Code 与 Codex。
Gemini
The native Gemini API, compatible with Google's SDKs (x-goog-api-key). Prefer OpenAI style? /v1/chat/completions with a Gemini-group key works too.
原生 Gemini API,兼容 Google SDK(x-goog-api-key)。想用 OpenAI 风格?用 Gemini 分组的 Key 调 /v1/chat/completions 也可以。
curl "https://api.we2ai.com/v1beta/models/gemini-3.1-pro-preview:generateContent" \
-H "x-goog-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"system_instruction": {"parts": [{"text": "Answer briefly."}]},
"contents": [{"role": "user", "parts": [{"text": "What is machine learning?"}]}],
"generationConfig": {"maxOutputTokens": 1024}
}'
import requests
r = requests.post(
"https://api.we2ai.com/v1beta/models/gemini-3.1-pro-preview:generateContent",
headers={"x-goog-api-key": "your-api-key"},
json={"contents": [{"parts": [{"text": "Say hi in 3 words"}]}]},
)
print(r.json()["candidates"][0]["content"]["parts"][0]["text"])
Image input uses inline_data parts (mime_type + base64 data). GET /v1beta/models lists the models your key can call.
图片输入使用 inline_data(mime_type + base64 的 data)。GET /v1beta/models 列出你这把 Key 可调用的模型。
Video input (inline base64)视频输入(inline base64)
Text models such as gemini-3.1-pro-preview can understand video. Send the file as a base64 inlineData part next to your text prompt. Keep the original file under 15 MB.
gemini-3.1-pro-preview 等文本模型可以理解视频:把视频文件做 base64 编码,作为 inlineData 放在文字提示旁边即可。原始视频文件请控制在 15 MB 以内。
# Build the request body in a file: a base64 video is too large for a command-line argument
{
printf '{"contents":[{"role":"user","parts":[{"inlineData":{"mimeType":"video/mp4","data":"'
base64 < demo.mp4 | tr -d '\n'
printf '"}},{"text":"Summarize this video."}]}]}'
} > body.json
curl "https://api.we2ai.com/v1beta/models/gemini-3.1-pro-preview:generateContent" \
-H "x-goog-api-key: your-api-key" \
-H "Content-Type: application/json" \
--max-time 600 \
--data-binary @body.json
import base64, requests
with open("demo.mp4", "rb") as f:
video = base64.b64encode(f.read()).decode()
r = requests.post(
"https://api.we2ai.com/v1beta/models/gemini-3.1-pro-preview:generateContent",
headers={"x-goog-api-key": "your-api-key"},
timeout=600,
json={"contents": [{"role": "user", "parts": [
{"inlineData": {"mimeType": "video/mp4", "data": video}},
{"text": "Summarize this video."},
]}]},
)
print(r.json()["candidates"][0]["content"]["parts"][0]["text"])
mimeType must match the file — video/mp4, video/webm, video/mov, video/mpeg, video/avi, video/x-flv, video/wmv or video/3gpp. data is plain base64: no line breaks and no data:…;base64, prefix. Cost: video is billed as input tokens, roughly 300 tokens per second of video; add "generationConfig": {"mediaResolution": "MEDIA_RESOLUTION_LOW"} to cut that to about 100 (Google's published figures). Time: video takes longer than text, so allow a few minutes for the response.
大小:base64 会让体积增加约 33%,15 MB 的视频编码后请求约 20 MB。更长的视频请先压缩、降低分辨率,或只截取需要的片段。格式:mimeType 必须和文件一致,可选 video/mp4、video/webm、video/mov、video/mpeg、video/avi、video/x-flv、video/wmv、video/3gpp。data 是纯 base64,不能带换行,也不能带 data:…;base64, 前缀。费用:视频按输入 token 计费,约每秒视频 300 token;加上 "generationConfig": {"mediaResolution": "MEDIA_RESOLUTION_LOW"} 可降到约 100(Google 公布的数据)。耗时:视频比纯文本慢,请预留几分钟等待响应。
Grok
Grok text models use the same OpenAI-style endpoints. Image and video are in the sections below. Grok 文本模型使用同样的 OpenAI 风格端点,图片和视频见下面两节。
curl https://api.we2ai.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.7",
"messages": [{"role": "user", "content": "Say hi in 3 words"}]
}'
Reasoning models also return their reasoning in reasoning_content. /v1/responses is supported as well.
推理模型会在 reasoning_content 里附带推理过程。同样支持 /v1/responses。
Image generation图片生成
OpenAI · GPT Image
Needs a key from an image-enabled group (e.g. Image-2). The response contains b64_json by default.
需要支持图片的分组的 Key(例如 Image-2)。默认返回 b64_json。
curl https://api.we2ai.com/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A red apple on a white table, studio light",
"n": 1,
"size": "1024x1024"
}'
Editing uses POST /v1/images/edits with multipart/form-data (image, optional mask, prompt), as in OpenAI's API.
图片编辑用 POST /v1/images/edits,multipart/form-data(image、可选 mask、prompt),与 OpenAI 官方一致。
import base64
from openai import OpenAI
client = OpenAI(api_key="sk-your-api-key", base_url="https://api.we2ai.com/v1")
r = client.images.generate(model="gpt-image-2", prompt="A red apple on a white table", size="1024x1024")
open("out.png", "wb").write(base64.b64decode(r.data[0].b64_json))
GPT Image 2.6 · SVG outputSVG 输出
gpt-image-2.6-flare and gpt-image-2.6-sunburst can return a vector image. Set output_format to "svg", n to 1, and name the model that writes the SVG in svg.model — it is required. Use a text model, not an image model; the supported author models are gpt-6-luna and gpt-5.6-luna, and any other value returns 400.
gpt-image-2.6-flare 与 gpt-image-2.6-sunburst 可输出矢量图。把 output_format 设为 "svg"、n 设为 1,并在 svg.model 里指定负责写 SVG 的模型,该字段必填。填文本模型,不是图片模型;支持的作者模型是 gpt-6-luna 和 gpt-5.6-luna,填其他值返回 400。
curl https://api.we2ai.com/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.6-flare",
"prompt": "A minimal flat logo of a red ball on a wooden table",
"size": "1024x1024",
"quality": "low",
"output_format": "svg",
"n": 1,
"svg": { "model": "gpt-6-luna", "reasoning": { "effort": "low" } }
}'
import base64, requests
r = requests.post("https://api.we2ai.com/v1/images/generations",
headers={"Authorization": "Bearer sk-your-api-key"},
json={"model": "gpt-image-2.6-flare",
"prompt": "A minimal flat logo of a red ball on a wooden table",
"size": "1024x1024", "quality": "low",
"output_format": "svg", "n": 1,
"svg": {"model": "gpt-6-luna", "reasoning": {"effort": "low"}}},
timeout=300).json()
open("out.svg", "wb").write(base64.b64decode(r["data"][0]["b64_json"]))
| Item项 | Notes说明 |
|---|---|
output_format | Must be exactly "svg" — lowercase, no surrounding spaces; other spellings return 400.必须恰好是 "svg":小写、前后无空格;其他写法返回 400。 |
svg.model | Required, and it must be exactly gpt-6-luna or gpt-5.6-luna (lowercase, no spaces). A missing value or an unsupported value returns 400; the unsupported-value message lists the supported models.必填,且必须恰好是 gpt-6-luna 或 gpt-5.6-luna(小写、无空格)。缺少或不支持的值返回 400,不支持时的错误信息里会列出支持的模型。 |
svg.reasoning.effort | Optional, and it must be nested under svg.reasoning — a top-level reasoning field has no effect. Allowed values, lowercase and exact: none, minimal, low, medium, high, xhigh, max (anything else, including an empty string, returns 400); omit it to use the model's default. low / medium / high are verified.可选,必须嵌套在 svg.reasoning 下,写在顶层不生效。可选值(小写、精确匹配):none、minimal、low、medium、high、xhigh、max(其他值包括空字符串都返回 400);不填则用模型默认值。已验证 low / medium / high。 |
| Check the result检查结果 | A successful (HTTP 200) response is an SVG. If an upstream returns another format (for example a PNG), the gateway tries other upstreams automatically (up to 3 extra attempts for this reason) and does not hand the PNG to you. If no attempt produces an SVG the request fails with an error (usually 502 upstream_error) and is not billed.HTTP 200 的成功响应一定是 SVG。某个上游返回了其他格式(例如 PNG)时,网关会自动换其他上游重试(因此原因最多再试 3 次),不会把 PNG 交给你。所有尝试都没有产出 SVG 时,请求以错误结束(通常是 502 upstream_error),且不计费。 |
| Response响应 | data has exactly one item; data[0].b64_json is the SVG text in standard base64 (UTF-8 XML, well-formed, rooted at an svg element in the SVG namespace; custom DTD entities are not supported). SVG is always returned as b64_json, never as a URL. The response may also carry svg_usage with the author model's token counts; it is informational.data 恰好一项;data[0].b64_json 是标准 base64 编码的 SVG 文本(UTF-8 XML,格式良好,根元素是 SVG 命名空间下的 svg;不支持自定义 DTD 实体)。SVG 一律以 b64_json 返回,不会以 URL 形式返回。响应里可能另带 svg_usage,给出作者模型消耗的 token,仅供参考。 |
| Time耗时 | About 25–60 s at quality: "low"; "medium" measured up to ~135 s. Each automatic retry adds about as much again. SVG requests send no heartbeat — the first byte is the final result — so set the client timeout to 300 s or more, and make sure every proxy, CDN or load balancer between you and us allows an idle read of at least that long.quality: "low" 约 25–60 秒,"medium" 实测最长约 135 秒,每次自动重试再增加差不多的时间。SVG 请求没有心跳,首字节就是最终结果,所以客户端超时请设为 300 秒以上,并确认你到我们之间的每一层代理、CDN 或负载均衡都允许至少这么长的读空闲。 |
| Not supported不支持 | n above 1, stream, partial_images, output_compression, /v1/images/edits, and models other than gpt-image-2.6-flare / gpt-image-2.6-sunburst — each returns 400. The asynchronous task endpoints do not accept SVG either; use the synchronous endpoint. OpenAI describes the result as static vector content, but treat the SVG as untrusted input and sanitize it before embedding it in a web page.n 大于 1、stream、partial_images、output_compression、/v1/images/edits,以及 gpt-image-2.6-flare / gpt-image-2.6-sunburst 之外的模型,都返回 400。异步任务端点同样不接受 SVG,请用同步端点。OpenAI 称结果为静态矢量内容,但请把 SVG 当作不可信输入,嵌入网页前先做清理。 |
Gemini
Use the native generateContent with responseModalities. imageSize (1K / 2K / 4K) sets the resolution — higher resolutions cost more, so set it explicitly. The image comes back as an inlineData part.
使用原生 generateContent 并设置 responseModalities。imageSize(1K / 2K / 4K)决定分辨率,分辨率越高越贵,建议显式指定。图片以 inlineData 返回。
curl "https://api.we2ai.com/v1beta/models/gemini-3.1-flash-image:generateContent" \
-H "x-goog-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "A red apple on a white table"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {"aspectRatio": "1:1", "imageSize": "1K"}
}
}'
import base64, requests
r = requests.post(
"https://api.we2ai.com/v1beta/models/gemini-3.1-flash-image:generateContent",
headers={"x-goog-api-key": "your-api-key"},
json={
"contents": [{"parts": [{"text": "A red apple on a white table"}]}],
"generationConfig": {"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {"aspectRatio": "1:1", "imageSize": "1K"}},
},
)
for part in r.json()["candidates"][0]["content"]["parts"]:
if "inlineData" in part:
open("out.png", "wb").write(base64.b64decode(part["inlineData"]["data"]))
Grok Imagine
Same OpenAI-style endpoint. Without response_format the response has a temporary url; set "response_format": "b64_json" to get the image bytes directly.
同样的 OpenAI 风格端点。不传 response_format 时返回临时 url;设置 "response_format": "b64_json" 则直接返回图片数据。
curl https://api.we2ai.com/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image-2.0",
"prompt": "A red apple on a white table",
"n": 1,
"response_format": "b64_json"
}'
Video generation视频生成
Grok Imagine video is asynchronous: create a task, poll its status, then download the result. A task is billed when it succeeds. Grok Imagine 视频是异步的:创建任务、轮询状态、下载结果。任务成功时才计费。
# 1. create — returns {"request_id": "..."}
curl https://api.we2ai.com/v1/videos \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video-1.5",
"prompt": "A red apple rotating slowly on a white table",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "480p"
}'
# 2. poll until status is "succeeded" (pending → ... → succeeded)
curl https://api.we2ai.com/v1/videos/{request_id} \
-H "Authorization: Bearer sk-your-api-key"
# 3. download the file (the Authorization header is required)
curl https://api.we2ai.com/v1/videos/{request_id}/content \
-H "Authorization: Bearer sk-your-api-key" -o out.mp4
To animate an image, add "image": {"url": "https://…", "type": "image_url"} (a data URL also works) to the create request.
要让图片动起来,在创建请求里加 "image": {"url": "https://…", "type": "image_url"}(也可以用 data URL)。
Doubao-Seedance (Volcengine)(火山)
Doubao-Seedance video (e.g. doubao-seedance-2.0, doubao-seedance-2.0-fast, doubao-seedance-2.0-mini, doubao-seedance-2.5) uses the same async pattern with an Ark-native body: create a task, poll its status, then download the result. A task is billed when it succeeds.
Doubao-Seedance 视频(如 doubao-seedance-2.0、doubao-seedance-2.0-fast、doubao-seedance-2.0-mini、doubao-seedance-2.5)使用同样的异步三步,请求体为 Ark 原生格式:创建任务、轮询状态、下载结果。任务成功时才计费。
# 1. create — returns {"id": "..."}
curl https://api.we2ai.com/v1/videos \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedance-2.0",
"content": [
{"type": "text", "text": "一个人在都市街头回望镜头,电影感"},
{"type": "image_url", "image_url": {"url": "https://…/frame.jpg"}, "role": "first_frame"}
],
"duration": 5,
"resolution": "720p",
"ratio": "16:9",
"watermark": false,
"generate_audio": true
}'
# 2. poll until status is "succeeded" (queued → running → succeeded/failed)
curl https://api.we2ai.com/v1/videos/{request_id} \
-H "Authorization: Bearer sk-your-api-key"
# 3. download the file (the Authorization header is required)
curl https://api.we2ai.com/v1/videos/{request_id}/content \
-H "Authorization: Bearer sk-your-api-key" -o out.mp4
resolution is 480p / 720p / 1080p (billing scales with it); 4k is also available on doubao-seedance-2.0 only, and 2k is not supported, duration is in seconds, ratio like 16:9. The first frame is optional: image_url.url must be a publicly accessible URL. Append ?part=last_frame to the content call to fetch the last frame as an image — the last frame is only generated when the create request includes "return_last_frame": true; without it the content call answers upstream_error.
resolution 取 480p / 720p / 1080p(计费随分辨率分档);doubao-seedance-2.0 另支持 4k,不支持 2k,duration 单位为秒,ratio 如 16:9。首帧可选:image_url.url 须是可从互联网访问的 URL。下载内容的调用加 ?part=last_frame 可取尾帧图——尾帧只在创建请求带 "return_last_frame": true 时生成,未带该参数时取尾帧会报 upstream_error。
POST /api/v3/contents/generations/tasks to create, GET/DELETE /api/v3/contents/generations/tasks/{task_id} to poll or cancel. A task starts running almost immediately and cannot be cancelled afterwards — DELETE answers 409 InvalidAction.RunningTaskDeletion. Requests and responses are the native Ark format; the base URL is still https://api.we2ai.com. callback_url is not supported.
官方 Ark SDK 同样可用:POST /api/v3/contents/generations/tasks 创建任务,GET/DELETE /api/v3/contents/generations/tasks/{task_id} 轮询或取消。任务创建后立即进入 running,开始后不可取消——DELETE 会返回 409 InvalidAction.RunningTaskDeletion。请求/响应均为 Ark 原生格式,Base URL 仍是 https://api.we2ai.com。不支持 callback_url。
http(s) URL that the upstream can fetch without credentials, and keep it reachable until the task finishes. Base64 / data URLs and asset:// references are not supported and are rejected with 400. Real-person face images can be passed as ordinary URLs; no portrait verification or asset upload is needed.
图片、视频、音频素材一律传可从互联网访问的 http(s) URL:上游无需登录即可下载,且在任务完成前保持可访问。不支持 base64 / data URL 和 asset:// 素材引用,会直接返回 400。真人脸图片同样直接传 URL,无需人像认证,也无需上传素材。
frames (use duration), draft, a service_tier other than default, inline prompt parameters such as --rs / --dur, and combining first/last frames with reference media.
以下参数在部分线路上会返回 400:frames(请用 duration)、draft、非 default 的 service_tier、提示词里的内联参数(如 --rs、--dur),以及首尾帧与参考素材同时使用。
Models & usage模型与用量
List the models your key can call查询 Key 可调用的模型
curl https://api.we2ai.com/v1/models -H "Authorization: Bearer sk-your-api-key"
# Gemini-group keys
curl https://api.we2ai.com/v1beta/models -H "x-goog-api-key: your-api-key"
Check usage and quota查询用量与额度
curl https://api.we2ai.com/v1/usage -H "Authorization: Bearer sk-your-api-key"
Returns the key's status and expiry, quota (limit, used, remaining, in USD) when a quota is set, and usage totals for today and overall: requests, tokens and cost. Optional query parameters: days (1–90) for the daily breakdown, start_date / end_date (YYYY-MM-DD) for per-model stats.
返回 Key 的状态和到期时间;设置了额度时返回额度(limit、used、remaining,单位美元);以及今日和累计的请求数、token 数和费用。可选参数:days(1–90)控制按日明细,start_date / end_date(YYYY-MM-DD)控制按模型统计的区间。
Claude Code & CodexClaude Code 与 Codex
Fastest: the WE2AI desktop client switches Claude Code, Codex and WorkBuddy to WE2AI models in one click. To configure them by hand: 最快的方式:WE2AI 桌面客户端一键把 Claude Code、Codex、WorkBuddy 切到 WE2AI 的模型。手动配置如下:
export ANTHROPIC_BASE_URL="https://api.we2ai.com"
export ANTHROPIC_AUTH_TOKEN="sk-your-api-key"
claude
model_provider = "we2ai"
model = "gpt-6-luna"
[model_providers.we2ai]
name = "WE2AI"
base_url = "https://api.we2ai.com/v1"
env_key = "WE2AI_API_KEY"
wire_api = "responses"
requires_openai_auth = false
supports_websockets = false
export WE2AI_API_KEY="sk-your-api-key"
codex
Codex needs a key from a group that serves its model; with a WE2AI key you do not need a ChatGPT subscription — usage is billed per token. Codex 需要所在分组提供对应模型的 Key;使用 WE2AI 的 Key 不需要 ChatGPT 订阅,按 token 计费。
Errors错误处理
| HTTP | Meaning含义 | What to do怎么处理 |
|---|---|---|
| 400 | Invalid request parameters请求参数有误 | Fix the request; the message says which field.按错误信息修正请求。 |
| 401 | Key missing, invalid or disabledKey 缺失、无效或已停用 | Check the key and the header you send it in; many failed attempts in a row are rate limited.检查 Key 和所用请求头;连续多次认证失败会被限流。 |
| 403 | Key expired, IP not allowed, group unavailable, or insufficient account balanceKey 已过期、IP 不在允许范围、分组不可用,或账户余额不足 | The error code says which (e.g. API_KEY_EXPIRED, INSUFFICIENT_BALANCE); fix it in the console.错误里的 code 会写明原因(如 API_KEY_EXPIRED、INSUFFICIENT_BALANCE),到控制台处理。 |
| 404 / 503 | The model is not available to your key's group你的分组没有这个模型 | /v1/chat/completions answers 404 model_not_found; /v1/messages answers 503 "No available accounts". Check GET /v1/models./v1/chat/completions 返回 404 model_not_found,/v1/messages 返回 503 "No available accounts"。用 GET /v1/models 核对。 |
| 429 | Rate limit, or the key's quota / usage limit is reached触发限流,或 Key 的额度 / 用量上限已达到 | Rate limits: retry with exponential backoff. API_KEY_QUOTA_EXHAUSTED: raise the key's quota in the console — retrying will not help.限流:指数退避后重试。API_KEY_QUOTA_EXHAUSTED:到控制台提高这把 Key 的额度,重试没有用。 |
| 5xx | Temporary upstream error上游临时故障 | Retry after a short wait; keep requests idempotent.稍等后重试,请求保持幂等。 |
Error bodies follow the protocol of the endpoint you called (Anthropic, OpenAI or Google style). Authentication failures return {"code":"INVALID_API_KEY","message":"Invalid API key"}.
错误体的格式跟随你调用的端点的协议(Anthropic、OpenAI 或 Google 风格)。认证失败返回 {"code":"INVALID_API_KEY","message":"Invalid API key"}。
import time, requests
def call(payload, retries=3):
for i in range(retries):
r = requests.post("https://api.we2ai.com/v1/chat/completions",
headers={"Authorization": "Bearer sk-your-api-key"}, json=payload)
if r.status_code == 429 or r.status_code >= 500: # a 429 with API_KEY_QUOTA_EXHAUSTED will not recover by retrying
time.sleep(2 ** i)
continue
r.raise_for_status()
return r.json()
raise RuntimeError("retries exhausted")