Unify API
Keep your embeddings code. Change two lines.Giữ code embeddings. Đổi hai dòng.保留 embeddings 代码,只改两行。
Turn text into vectors with the OpenAI embeddings shape, on the same key as your chat calls.Biến văn bản thành vector theo dạng embeddings của OpenAI, dùng chung key với các lệnh chat.用 OpenAI embeddings 格式把文本转成向量,与聊天调用共用同一个 key。
import osfrom openai import OpenAIclient = OpenAI(removed: api_key=os.environ["OPENAI_API_KEY"],added: base_url="https://anyrouter.dev/api/v1",added: api_key=os.environ["ANYROUTER_API_KEY"],)emb = client.embeddings.create(removed: model="text-embedding-3-small",added: model="nvidia/nemotron-3.5-embed-1b", input=["Hello", "world"],)print(len(emb.data[0].embedding))nvidia/nemotron-3.5-embed-1bis served free by a platform upstream, so this runs on any key.được upstream của nền tảng phục vụ miễn phí, nên chạy được với mọi key.由平台上游免费提供,任何 key 都能运行。
What came backKết quả trả về返回了什么
The cURL tab above, run on prod on 2026-10-31 with a Go key. Only the fields shown are kept, and long values are cut with "…".Tab cURL ở trên, chạy trên prod ngày 2026-10-31 với key gói Go. Chỉ giữ các field hiển thị, giá trị dài được cắt bằng "…".上面的 cURL 标签页,于 2026-10-31 在生产环境用 Go 套餐 key 运行。只保留显示的字段,过长的值用 "…" 截断。
HTTP 200
x-anyrouter-model: nvidia/nemotron-3-embed-1b
x-anyrouter-provider-chain: kilo
x-anyrouter-credential-source: platform
x-request-id: req_cf24697f3ec441879f0adb82
{
"object": "list",
"model": "nvidia/nemotron-3-embed-1b:free",
"data": [
{
"index": 0,
"embedding": [
0.0022859701,
-0.080008954,
-0.013601524,
"…"
]
},
{
"index": 1,
"embedding": [
0.0038007896,
-0.077580824,
0.024034403,
"…"
]
}
],
"usage": {
"prompt_tokens": 6,
"total_tokens": 6,
"cost": 0
}
}- x-anyrouter-model
- The model that answered. A preset such as anyrouter/free names its pick here; pin a model id and it echoes yours.Model đã trả lời. Preset như anyrouter/free ghi model nó chọn ở đây; chỉ định model id thì header lặp lại id của bạn.实际回答的模型。anyrouter/free 等预设会在这里写出所选模型;指定模型 id 时则原样返回你的 id。
- x-anyrouter-provider-chain
- Each upstream tried, in order. One hop here; when a hop fails the next one answers and the header reads a->b.Các upstream đã thử, theo thứ tự. Ở đây chỉ một chặng; khi một chặng lỗi, chặng sau trả lời và header thành a->b.按顺序尝试过的上游。这里只有一跳;某一跳失败时由下一跳回答,header 变为 a->b。
- x-anyrouter-credential-source
- Whose upstream key paid: platform (ours), own_byok (yours) or pool (a donated key).Key upstream nào đã trả: platform (của chúng tôi), own_byok (của bạn) hoặc pool (key được đóng góp).由谁的上游 key 付费:platform(平台)、own_byok(你自己的)或 pool(捐赠的 key)。
- x-request-id
- Quote it to support, or find the request in your logs.Gửi cho bộ phận hỗ trợ, hoặc tìm request trong log của bạn.联系支持时提供它,或在日志中查找该请求。
- usage.cost
- What this request cost you, in USD, in the body. Zero on free models.Chi phí của request này, tính bằng USD, nằm trong body. Bằng 0 với model miễn phí.本次请求的费用(美元),写在 body 里。免费模型为 0。
What worksHỗ trợ已支持
- String or array inputInput là chuỗi hoặc mảng输入可为字符串或数组
- float or base64 encoding_formatencoding_format float hoặc base64encoding_format 支持 float 或 base64
Decisions modelsModel DecisionsDecisions 模型
Not a chat. Send a situation and a question with fixed choices, and get a probability for each choice back. Decisions are free on Go and up, with a 5-request trial on Free.Không phải chat. Gửi một tình huống và câu hỏi có các lựa chọn cố định, nhận lại xác suất cho từng lựa chọn. Decisions miễn phí từ gói Go trở lên, gói Free có 5 request dùng thử.不是聊天。发送一个情境和带固定选项的问题,返回每个选项的概率。Decisions 在 Go 及以上套餐免费,Free 套餐可试用 5 次请求。
curl https://anyrouter.dev/api/v1/decisions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "hal-x/thx-01", "state": "My card was charged twice",
"questions": {"team": {"type": "choice", "criteria": {"billing": "Payments", "tech": "API problems"}}}}'
# {"answers": {"team": {"type": "choice", "choice": "billing", "probabilities": {"billing": 0.97, "tech": 0.03}}}, "model": "hal-x/thx-01", "status": "completed"}