Skip to content

Unify API

Giữ code embeddings. Đổi hai dòng.

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.

POST /api/v1/embeddings
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-1bđược upstream của nền tảng phục vụ miễn phí, nên chạy được với mọi key.

Kết quả trả về

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 "…".

captured from prod
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
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.
x-anyrouter-provider-chain
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.
x-anyrouter-credential-source
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).
x-request-id
Gửi cho bộ phận hỗ trợ, hoặc tìm request trong log của bạn.
usage.cost
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í.

Hỗ trợ

  • Input là chuỗi hoặc mảng
  • encoding_format float hoặc base64

Model Decisions

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ử.

POST /api/v1/decisions
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"}

Tài liệu và use case liên quan

Tiếp theo