快速開始
把任意 OpenAI 相容 SDK 的 base_url 指向我們的網關,開始呼叫。第一次回應通常在幾秒內返回。
from openai import OpenAI
client = OpenAI(
api_key="sk-xc-your-key-here",
base_url="https://api.nexevo.ai/v1",
)
resp = client.chat.completions.create(
model="nexevo/balanced",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)鑑權
在 Keys 頁面建立 API 金鑰,以 Bearer token 形式放在 Authorization 頭。每個請求都需要合法金鑰;已撤銷或過期的金鑰會被立即拒絕。
GET /v1/billing/balance HTTP/1.1
Host: api.nexevo.ai
Authorization: Bearer sk-xc-abc123...單 key 的設定(子額度 / IP 白名單 / 模型限制 / 過期)可以在 Keys 頁配置。用來給不同應用程式或環境簽發作用域受限的金鑰。
對話 completions
POST 到 /v1/chat/completions,使用 OpenAI 標準 message 格式。用 model=nexevo/balanced 我們會依照你的問題自動路由到最適合的上游。也支援 temperature / max_tokens / top_p / stop 等標準參數。
resp = client.chat.completions.create(
model="nexevo/balanced",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum entanglement"},
],
temperature=0.7,
max_tokens=500,
)
print(resp.choices[0].message.content)| model | string | Required | 指定呼叫的模型 ID,如 gpt-4o / claude-opus-4-7。<br/>智能路由別名:nexevo/fast / nexevo/balanced / nexevo/auto。查看全部 121 個模型 → |
| messages | Message[] | Required | OpenAI 标准对话历史。{role, content} 数组,role ∈ system/user/assistant/tool。 |
| stream | boolean | Default: false | 开启 SSE 流式;返回 ChatCompletionChunk 序列,需用 SSE 解析器消费。 |
| temperature | number | Default: 1 | 采样温度,0-2。低 = 确定性 / 代码;高 = 创意。 |
| max_tokens | integer | Optional | 单次响应最大 token。不设则用模型默认。 |
| top_p | number | Default: 1 | 核采样阈值。一般 temperature OR top_p 二选一。 |
| tools | Tool[] | Optional | OpenAI function calling 标准 tools 数组。详见 Function calling 节。 |
| tool_choice | "auto" | "none" | object | Optional | 工具选择策略;指定具体 tool 名可强制调用。 |
| response_format | object | Optional | JSON 模式或 Schema 严格模式: {type: "json_object"} 或 {type: "json_schema", json_schema: {...}}。 |
| models | string[] | Optional | Nexevo 扩展:多模型 fallback 列表。主 model 失败按顺序尝试,大幅提升可用性。 |
| provider | ProviderPreference | Optional | Nexevo 扩展:路由偏好,如 {order: ["groq"], allow_fallbacks: true}。 |
| max_price | MaxPrice | Optional | Nexevo 扩展:成本上限 USD,如 {prompt: 0.01, completion: 0.05}。超价直接拒绝。 |
串流回應
設 stream=true,我們會逐 token 轉送上游的 SSE,附加延遲極小。流以 `data: [DONE]` 結束。工具呼叫透過 tool_calls delta 傳回-與 OpenAI 格式完全一致。
stream = client.chat.completions.create(
model="nexevo/balanced",
messages=[{"role": "user", "content": "Write a haiku."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)Function calling
傳入 `tools` 陣列(JSON Schema 描述函數)。若模型決定調工具,回傳 `tool_calls`。你本地執行函數,把結果以 tool role 訊息追加,再次調 API--和 OpenAI 標準流程一樣。
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
resp = client.chat.completions.create(
model="nexevo/balanced",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=tools,
)
tool_call = resp.choices[0].message.tool_calls[0]
print(tool_call.function.name, tool_call.function.arguments)圖像 / 視頻 / 3D 生成
Nexevo 生成閘道統一 8 家 provider 22 個模型 — 圖像 / 視頻 / 3D。圖像同步返 URL 或 base64;視頻 / 3D 異步走 job_id 輪詢(SDK 提供 generate_and_wait 助手)。Sora 2 / Veo 3 / Runway 視頻自動映射到 OSS 24h 簽名 URL。可運行範例見 /cookbook 的 Generation 分類。
# 1) 文生图(同步)— DALL-E 3 / Imagen 4 / FLUX
img = client.images.generate(
model="nexevo/image-balanced", # or "dall-e-3" / "imagen-4-ultra" / "flux-pro"
prompt="a serene Japanese garden in cyberpunk style",
n=1, size="1024x1024",
)
print(img["data"][0]["url"])
# 2) 文生视频(异步)— Sora 2 / Veo 3 / Wan 2.6
job = client.videos.generate_and_wait(
model="sora-2", # or "veo-3" / "wan-2.6"
prompt="a cat skating in neon Tokyo",
duration_sec=5, aspect_ratio="16:9",
poll_interval_sec=5, timeout_sec=600,
)
print(job["results"][0]["url"]) # OSS 24h signed URL
# 3) 3D 资产 — Hunyuan 3D 直连
asset = client.models3d.generate_and_wait(
model="hunyuan-3d-2", prompt="a low-poly viking longboat",
output_format="glb",
)
print(asset["results"][0]["url"])
# 4) 图生视频 — Runway Gen-4 需先上传参考图
with open("char.png", "rb") as f:
up = client.generation.uploads.upload(
f.read(), filename="char.png", content_type="image/png",
)
job = client.videos.generate_and_wait(
model="runway-gen4",
prompt="zoom in slowly while waves crash",
duration_sec=5,
reference_image_url=up["url"],
)| model | string | Required | 模型 id,如 nexevo/image-balanced / dall-e-3 / imagen-4-ultra / flux-pro。完整 22 模型见 GET /generation/models。 |
| prompt | string | Required | 文本描述,最多 4000 字符。 |
| n | integer | Default: 1 | 生成数量,1-10。Imagen 上限 4,DALL-E 3 仅 1。 |
| size | string | Default: 1024x1024 | 尺寸,常见 1024x1024 / 1792x1024 / 1024x1792;Imagen 自动映射到 aspectRatio。 |
| quality | "standard" | "hd" | Optional | 仅 DALL-E 3 / gpt-image-1 用。hd 价格×2,细节更好。 |
| reference_image_b64 | string | Optional | 图生图用,base64 PNG / JPG。OpenAI gpt-image-1 / FLUX 支持;DALL-E 3 不支持。 |
| negative_prompt | string | Optional | 不想要的元素描述。OpenAI 自动忽略,Replicate / Wan 用。 |
| seed | integer | Optional | 确定性种子,同 prompt + seed 出同图(部分 provider)。 |
| model | string | Required | sora-2 / sora-2-pro / veo-3 / veo-3-fast / wan-2.6 / wan-2.6-pro / runway-gen4 / nexevo/video-{fast|balanced|pro}。 |
| prompt | string | Required | 视频文本描述。 |
| duration_sec | number | Default: 5 | 视频时长,1-30 秒。Sora 2 / Veo 3 推荐 5-10。 |
| aspect_ratio | string | Default: "16:9" | 16:9 / 9:16 / 1:1 / 4:3 / 3:4。 |
| reference_image_url | string | Optional | 图生视频参考图(https URL)。Runway Gen-4 强制必传;Wan 2.6 用作首帧。先调 POST /v1/generation/upload 拿 OSS URL。 |
| negative_prompt | string | Optional | Wan / Replicate / Veo 用。 |
| seed | integer | Optional | 确定性种子(部分 provider)。 |
| model | string | Required | hunyuan-3d-2 / hunyuan-3d-2-pro / nexevo/3d-{fast|balanced}。 |
| prompt | string | Optional | 文本描述(prompt 或 reference_image_url 二选一)。 |
| reference_image_url | string | Optional | 图生 3D 参考图(https URL)。 |
| output_format | string | Default: "glb" | glb / obj / usdz / stl / fbx。 |
| file | multipart file | Required | multipart/form-data 字段名 file,PNG / JPG / WebP / GIF,≤ 10 MB。 |
| id | string | Optional | Nexevo 内部 job_id(gen_xxxx)。 |
| status | "pending" | "running" | "succeeded" | "failed" | "canceled" | Optional | 异步任务状态。 |
| progress | number | Optional | 0-100,部分 provider(Replicate / Veo)实时报。 |
| results | GenResult[] | Optional | 完成后含 { url, b64_json, mime_type, duration_ms, ... }。Sora 2 / Veo 3 / Runway 自动镜像到 OSS,URL 24h 有效。 |
| charged_usd | string | Optional | 扣费金额(完成时填入)。 |
| error | object | null | Optional | 失败时含 { code, message, retryable }。 |
Embeddings · 文本向量化
把文本壓縮成固定維度向量,用於 RAG 檢索、語義搜尋、聚類。OpenAI 相容 schema。計費按 input tokens,典型 $0.02-0.13/1M。
# OpenAI 兼容 schema — 把 OpenAI client 的 base_url 改成我们的就能用
resp = client.embeddings.create(
model="text-embedding-3-large", # 也可写 voyage-3 / jina-embeddings-v3 / bge-m3
input="Nexevo.ai 是一个 LLM 网关", # 或 list[str] 批量
)
vec = resp["data"][0]["embedding"] # 3072 个浮点数
print(len(vec), resp["usage"]["prompt_tokens"])
# 智能路由 — admin 可后台改路由目标,你的代码不用改
resp = client.embeddings.create(
model="nexevo/embed-balanced", # 智能路由 = voyage-3(默认)
input=["doc 1...", "doc 2...", "doc 3..."],
)
for row in resp["data"]:
print(row["index"], len(row["embedding"]))| model | string | Required | 客户面 model id。可填:text-embedding-3-large / text-embedding-3-small / voyage-3-large / voyage-3 / jina-embeddings-v3 / bge-m3 / embed-multilingual-v3.0;或智能路由 nexevo/embed-fast / nexevo/embed-balanced。 |
| input | string | string[] | Required | 单段文本或批量(批量上限取决于 provider,通常 100-2048)。 |
| encoding_format | "float" | "base64" | Default: "float" | 返回向量的编码;base64 体积小但需要客户端 decode。 |
| dimensions | integer | Optional | 降维向量维度。仅 text-embedding-3-* / jina-embeddings-v3 支持。 |
| user | string | Optional | tenant 标识,审计与速率限制用。 |
Rerank · RAG 第二段精排
把 embedding 召回的 top-50 候選精排,只留 top-5 給 chat。提升 RAG 答題準確度的關鍵。
# RAG 第二段:把 embedding 召回的 top-50 候选重排,只留 top-5 最相关
ranked = client.rerank.create(
model="rerank-v3.5", # 也可 jina-reranker-v2-base / bge-reranker-v2
query="如何重置员工 VPN?",
documents=top50_docs, # list[str] 或 list[{"text": "..."}]
top_n=5,
)
for r in ranked["results"]:
print(r["relevance_score"], r["document"][:60])| model | string | Required | 客户面 model id:rerank-v3.5(Cohere)/ rerank-multilingual-v3.0 / jina-reranker-v2-base / bge-reranker-v2 / nexevo/rerank-fast / nexevo/rerank-balanced。 |
| query | string | Required | 检索 query / 用户问题。 |
| documents | string[] | object[] | Required | 候选文档列表,通常来自 embedding 检索 top-50。可以是 string 或 {"text": "..."}。 |
| top_n | integer | Optional | 排序后保留前 N 条。不设则全返(已排序)。 |
| return_documents | boolean | Default: true | 返回时是否包含原文。设 false 只返 index + score 节流。 |
完整 RAG 流水線
embedding 召回 → rerank 精排 → chat 答題。1 萬篇文檔成本從 ~$5 降到 ~$0.06。
# 完整 RAG 三段:embedding 召回 → rerank 精排 → chat 答题
# 总成本 ~$0.06 vs 直接塞 1 万篇文档给 chat ~$5+(差 100x)
from nexevo_ai import Nexevo
client = Nexevo()
# ── 1. 离线索引(只跑一次)──
all_docs = ["...", "...", ...] # 1 万篇文档
emb_resp = client.embeddings.create(model="bge-m3", input=all_docs)
vectors = [d["embedding"] for d in emb_resp["data"]]
# (省略向量库存取代码 — 用 Pinecone / Milvus / pgvector 都行)
# ── 2. 用户提问时(每次请求触发)──
question = "如何重置员工 VPN?"
# 2a) embed 问题 → 检索 top-50
q_emb = client.embeddings.create(model="bge-m3", input=question)
top50 = vector_db.query(q_emb["data"][0]["embedding"], k=50)
# 2b) rerank top-50 → top-5 最相关
ranked = client.rerank.create(
model="rerank-v3.5",
query=question,
documents=[d.text for d in top50],
top_n=5,
)["results"]
top5 = [top50[r["index"]] for r in ranked]
# 2c) chat 用 top-5 答题
context = "\n\n".join(d.text for d in top5)
ans = client.chat.completions.create(
model="nexevo/balanced",
messages=[
{"role": "system",
"content": f"基于以下材料答题(只能用这些材料,不要编):\n\n{context}"},
{"role": "user", "content": question},
],
)
print(ans.choices[0].message.content)Agents · Agent-as-a-Service
把高層任務交給 agent — 它自己分解步驟、調 tool、循環直到答出來。內建 tool:rag_search + list_models。兩種模式:wait=true 阻塞,wait=false 異步;另有 SSE 流式。
from nexevo_ai import Nexevo
client = Nexevo()
# 1) 同步模式(默认 wait=True)— 阻塞等结果,deadline 默认 120s,可调到 3600s
job = client.agents.run(
task="找一个最便宜的中文 RAG embedding 模型,告诉我维度和单价",
model="nexevo/balanced", # chat brain,可换 claude / gpt-5 等
max_steps=10,
)
print(job["result"])
# Agent 内部会:
# step 1: chat → tool_call list_models(kind=embedding, modality 多语言)
# step 2: tool_result 返 BGE-m3 / Jina-v3 等候选
# step 3: chat 综合 → final_answer "BGE-m3 1024 维,$0.07/1M"
# 2) 给 RAG 任务预加载文档
job = client.agents.run(
task="基于这些资料答:如何重置员工 VPN?",
rag_documents=[
"VPN 服务器列表请联系 IT 支持...",
"重置 VPN 密码需要登录员工门户...",
# ... 上千条
],
tools=["rag_search"],
)
# 3) 异步任务(长任务推荐)
submitted = client.agents.run(task="复杂调研任务...", wait=False)
job = client.agents.run_and_wait(submitted["id"], timeout_sec=300)
# 4) Memory tools(2026-04-29 P4 v2)— LLM 主动读写工作记忆 / 长期记忆
# 任务级 memory:节点之间共享中间事实(避免 prompt 拼接爆炸)
# tenant 级 memory:跨任务的"上次客户做过 X" 让 agent 第二次更聪明
# 工具自动注入,LLM 调用 memory_read({level:"task", key:"..."}) 即可| task | string | Required | 用户面任务描述。Agent 内部 LLM brain 拿这个当 user message 起循环。 |
| model | string | Default: "nexevo/balanced" | Agent 大脑(chat completion 模型)。可换 claude-opus-4-7 / gpt-5 / nexevo/fast 等。 |
| tools | string[] | Optional | 启用的内置 tool 名;不填 = 全部启用。内置:rag_search / list_models / web_search / generate_image / python_exec / spawn_agent / memory_read / memory_write。 |
| max_steps | integer | Default: 10 | 最多循环几步;防 LLM 死循环。上限 30。 |
| rag_documents | string[] | Optional | rag_search tool 启动时预加载的文档,内部用 BGE-m3 embed + rerank-v3.5 精排。 |
| system_prompt | string | Optional | 覆盖默认 agent 系统提示。 |
| wait | boolean | Default: true | 同步阻塞等结果(true,默认 deadline 120s,可调上限 3600s)/ 异步立返 task_id 后客户走 GET /v1/tasks/{id} poll(false,长任务推荐)。 |
| timeout_sec | integer | Default: 120 | 仅 wait=true 时生效,超时返当前状态(可能仍 running),客户后续 poll。上限 3600s。 |
| enable_verifier | boolean | Default: false | final_answer 出来后跑 cheap-model 多维度评估(factuality / relevance / completeness / safety),overall < threshold → verifier_passed=false。 |
| verifier_threshold | float | Default: 0.7 | verifier overall 分数低于此值标 failed。建议 0.6-0.8。 |
| max_cost_usd | float | Optional | 软告警上限 — 估算累计花费超此值时 emit budget_warning step,**任务继续**;真正硬门 = 账户余额。避免估算误差导致误杀。 |
SSE 流式 — 即時拿每步事件
# 流式 — 实时拿每步事件,边跑边看
for ev in client.agents.run_stream(task="..."):
if ev["type"] == "step":
s = ev["step"]
if s["type"] == "tool_call":
print(f"→ 调用 {s['tool_name']}({s['tool_input']})")
elif s["type"] == "tool_result":
print(f" ← {s['tool_output']}")
elif s["type"] == "final_answer":
print(f"\n答:{s['content']}")
elif ev["type"] == "done":
print(f"\n总 token: in={ev['job']['total_tokens_in']}, out={ev['job']['total_tokens_out']}")/v1/tasks · 任務即服務 + Self-Healing v2
上面 /v1/agents/run 是對話式 agent。/v1/tasks 是任務即服務 — 加 Planner 自動拆 DAG、Verifier 多維評分、Auto-repair 反思+重跑閉環、Partial Success 標記。Plan→Execute→Evaluate→Adjust→Loop 完整自我修復架構,預期成功率 +20-25 pp。
| goal | string | Required | 高层任务目标(替代 task)。Planner 拆 DAG 时从这里读。 |
| deliverables | object[] | Optional | 结构化交付物声明:[{type:"email", target:"x@y.com"}] 或 webhook。 |
| budget_usd | float | Optional | 任务级软告警预算(同 max_cost_usd 语义)。 |
| deadline_sec | integer | Default: 120 | 任务超时;wait=true 时是同步上限,wait=false 时是后台执行上限。≥10、≤3600。 |
| enable_planner | boolean | Default: false | 用便宜 model(nexevo/fast 默认)拆 NL goal → DAG plan,executor 按图并行调度。复杂任务质量提升明显。 |
| planner_model | string | Default: "nexevo/fast" | Planner 用什么模型(便宜模型够,通常无需改)。 |
| planner_n_candidates | integer | Default: 1 | 并行生成 N 个候选 plan + 启发评分选优(节点数 / aggregate 唯一性 / tool_call 存在 / 引用合法)。1 单跑 / 2-5 多样性。 |
| auto_repair_max_rounds | integer | Default: 0 | **Self-Healing**:verifier 失败时 → cheap-LLM 反思根因 → 重新 plan + 局部 re-run(checkpoint 复用成功节点)。0 关 / 1-3 启用。期望成功率 +20-25 pp。 |
| autonomy_level | "L1" | "L2" | "L3" | Default: "L3" | L1 启动前一次性确认 / L2 副作用工具(email / webhook / mcp:slack:*)调用前确认 / L3 完全托管。 |
from nexevo_ai import Nexevo
client = Nexevo()
# Self-Healing v2 — 任务自我修复闭环(Plan → Execute → Evaluate → Adjust)
result = client.tasks.submit(
goal="调研 2025 Q2 全球生成式视频生成 Top 5 厂商,输出对比表(ARR/客户/技术亮点)",
enable_planner=True,
planner_n_candidates=3, # 并行生成 3 个候选 plan,启发选优
auto_repair_max_rounds=2, # verifier 失败 → 反思 + 重 plan 最多 2 轮
deadline_sec=600, # 长任务给充裕时间
wait=True, # 阻塞拿结果(或 wait=False 异步 poll)
deliverables=[{"type": "email", "target": "you@company.com"}],
)
# response 含:plan(实际跑的)+ deliverables + verifier 多维分 + partial 标记
print(result["plan"]["nodes"]) # 看 agent 怎么拆的
print(result["deliverables"][0]["content"]) # 主答
print(result["deliverables"][0]["metadata"]) # verifier 多维分
if result["partial"]:
print("部分成功节点:", result["succeeded_node_ids"])
print("失败节点:", result["failed_node_ids"])對話歷史
可選模組,用於 chat UI 的後端持久化。每個 conversation 是一個有標題/元資料的容器,append message 不觸發 LLM 僅做持久化(配合 chat completions 使用)。完整 CRUD + 訊息追加。
conv = client.conversations.create(title="My Session")
client.conversations.append_message(
conv["conversation_id"], role="user", content="Hello!",
)
all_convs = client.conversations.list(limit=20)
detail = client.conversations.get(conv["conversation_id"])| title | string | Optional | 对话标题。可后续 update。 |
| metadata | object | Optional | 任意 JSON,关联你自己的 user_id / session_id / topic 等。最大 4KB。 |
| role | "user" | "assistant" | "system" | "tool" | Required | 消息角色。 |
| content | string | Required | 消息文本。注意:此 endpoint 只持久化,不触发 LLM。 |
帳號管理
註冊/登入/密碼重設/2FA/資料編輯/GDPR 自助停用。多數 endpoint 面向 web 應用流程;後端整合只需 me() / change-password / 2FA。所有受保護 endpoint 走 Bearer token。
me = client.auth.me()
client.auth.update_profile(full_name="Jane Doe")
client.auth.change_password(
current_password="old-pwd",
new_password="new-pwd-123",
)
status = client.auth.two_fa_status()API Key 管理
動態建立/撤銷 API key,可設定月度消費上限(monthly_spend_cap_usd)、超閾值警告 webhook(HTTPS only)、地理路由策略(cn-only / overseas-only / any)。 create() 傳回 full_key 僅一次,務必儲存。
new = client.keys.create(name="prod-2026")
print(new["full_key"]) # 只此一次显示
client.keys.update_spend_cap(
new["key"]["key_id"],
monthly_spend_cap_usd="100",
)
client.keys.update_alert_webhook(
new["key"]["key_id"],
url="https://your-app.com/billing-alert",
)| name | string | Required | Key 显示名(用于在 dashboard 区分)。1-100 字符。 |
| monthly_spend_cap_usd | string | Optional | 月度上限 USD,字符串保留精度(如 "100.00")。超 cap 后该 key 该月所有请求被拒。 |
| clear | boolean | Default: false | true = 清除当前 cap(无限额)。 |
帳單 / 用量 / 儲值
餘額、每日用量、按檔分項 (by_tier:fast / balanced / passthrough / byok)、Stripe 儲值。計費檔由請求的 model 決定 — model=nexevo/fast → fast 扁平價;傳真實模型 ID → passthrough +5%。所有金額字串請按 decimal 處理,不要 float。
bal = client.billing.balance()
usage = client.billing.usage(days=7)
plan = client.billing.get_plan()
hint = client.billing.upgrade_hint()
if hint["hint"]:
print(f"建议: {hint['hint']['recommend_plan']}, "
f"可省 {hint['hint']['savings_pct']}%")
session = client.billing.checkout(
amount_usd=20,
idempotency_key="topup-2026-04-27-001",
)
print(session["checkout_url"])| amount_usd | number | Required | 充值金额 USD,> 0。 |
| idempotency_key | string | Required | 幂等 key,同 key 重试不会重复扣款。建议格式:topup-YYYY-MM-DD-序号。 |
組織 / 多用戶
企業帳戶的多用戶管理。支援 owner / admin / developer 三種角色,成員邀請/移除/轉讓所有權。所有 key + billing 在組織名下共享,適合公司團隊存取。
org = client.organizations.create("Acme Inc")
client.organizations.invite_member(
org["organization"]["org_id"],
email="dev@acme.com",
role="developer",
)
members = client.organizations.list_members(org["organization"]["org_id"])
client.organizations.transfer_owner(
org["organization"]["org_id"],
new_owner_user_id="u_789",
)RLHF 回饋
從 chat 回應頭 X-Nexevo-Generation-Id 拿 generation_id,提交 thumbs up/down + 可選評論 + tag。回饋直接進資料飛輪,自學習路由會用它優化未來選模型。
resp = client.chat.completions.create(
model="nexevo/balanced",
messages=[{"role": "user", "content": "Hello!"}],
)
gen_id = resp["nexevo"]["generation_id"]
client.feedback.submit(
generation_id=gen_id,
rating=1,
comment="Helpful!",
tags=["accurate"],
)
summary = client.feedback.summary(days=7)| generation_id | string | Required | 从 chat 响应头 X-Nexevo-Generation-Id 或 SDK resp.nexevo.generation_id 拿。 |
| rating | 1 | -1 | Required | 1 = 👍, -1 = 👎。 |
| comment | string | Optional | 可选自由文本(最多 ~2K 字符)。 |
| tags | string[] | Optional | 可选标签。常用: accurate / incorrect / too_verbose / irrelevant。 |
錯誤處理
錯誤格式對齊 OpenAI:單一 `error` 物件包含 `message` / `type` / `code` 三個欄位。常見 code: `invalid_api_key` (401)、`insufficient_balance` (402)、`rate_limit_exceeded` (429)、`tenant_monthly_quota_exceeded` (429)、`upstream_error` (502)。上游 5xx 我們會透明重試;只有所有重試都失敗你才會看到最終錯誤。
{
"error": {
"message": "Account balance depleted. Please top up to continue.",
"type": "insufficient_balance",
"code": "account_suspended"
}
}速率限制
每 key 預設 60 RPM。超限回傳 429,附 `X-RateLimit-Remaining` 和 `X-RateLimit-Reset` 頭。企業方案可放寬上限-聯絡我們客製化。
回應頭
每次回應都附帶實用元資料頭:
| X-Trace-ID | unique request ID, include it in support tickets |
| X-Usage-Input-Tokens | input tokens counted for billing |
| X-Usage-Output-Tokens | output tokens counted for billing |
| X-RateLimit-Remaining | remaining requests in current window |
| X-RateLimit-Reset | seconds until window resets |
價格
所有內部模型統一平價:輸入 $3.00 / 百萬 token,輸出 $12.00 / 百萬 token。快取命中(精確 + 語意)以正常價 25% 計費。重試和對沖路徑的成本由我們內部吸收——你只為最終看到的答案付費。
SDK 相容性
因為我們暴露 OpenAI 相容 API,大多數現有 SDK 零改動可用。只要把 base_url 指到我們的網關即可。
OpenAI 相容 SDK
原生 SDK
我們維護的官方 SDK,封裝了智慧路由 / 餘額 / RLHF 回饋等擴充能力。100% OpenAI 協定相容。
0 改動從 OpenAI 遷過來
保留你的 OpenAI 程式碼,只改兩行:把 api_key 換成 NEXEVO_API_KEY,加 base_url。
from openai import OpenAI
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
)
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hi"}],
)from openai import OpenAI
client = OpenAI(
api_key=os.environ["NEXEVO_API_KEY"],
base_url="https://api.nexevo.ai/v1",
)
resp = client.chat.completions.create(
model="nexevo/balanced",
messages=[{"role": "user", "content": "Hi"}],
)