Luncat ka eusi
Kembali ka Nymbot

Dasar pangaweruh ngembangkeun

Chat, Jawaban jeung Pesan

Tilu cara pikeun nelepon model kitu, dina tilu format klien geus ngomong, sakabéh ngajalankeun dina model anu sarua jeung dibayaran cara anu sarua.

Ngeunaan kompléks

The OpenAI chat format, jeung hiji nu sapertos unggal alat ngarojong. Hésé ngobrol nepi ka ayeuna jeung meunangkeun pesan sakali balik.

POST https://nymbot.ai/api/v1/chat/completions Anjeun kudu nyadiakeun API.

Sadaya model jeung messages A parameter sampling nu model dipilih teu nyokot disimpen tanpa salah, jadi hiji request body ngoperasikeun di antara model. supported_parametersApa anu ditolak jeung teu ditinggalkeun téh naon model teu bisa ngalakukeun: gambar pikeun model nu teu bisa ningali, alat pikeun model nu teu bisa nelepon aranjeunna.

Field nutipe nuDiperlukanDaptarkeun
modelPikeun stringSumuhunnymbot/auto (Ieu téh auto) pikeun routing Nymbot dina keseimbangan standar, atawa ID model katalog kayaning anthropic/claude-sonnet-5 di Pro keseimbangan. nu short names na alias aplikasi ogé diakui. Bisa diakhiri dina Ngeunaan.
messagesNgeunaanSumuhunNgobrol jeung peran system, developer (diwanohkeun salaku sistem) user, assistant jeung toolKonten mangrupakeun string atawa daftar tina text jeung image_url bagian; gambar ngan dina pesan pamaké. input_audio Dupi bagian file anu ditolak.
streamBouléonnu nuNurutkeun jawabna salaku ditulis. tingali Anjeunna streaming.
stream_optionsObjek ieunu nu{"include_usage": true} Ieu ngabalukarkeun hiji bagian final jeung jumlah token jeung biaya.
max_tokens
max_completion_tokens
Ngeunaannu nuPaling token pikeun ditulis. Diminutkeun ka maksimum model lamun luhur. ogé nyetel sababaraha anu ditangtayungan ti saldo anjeun, jadi jumlah leutik kudu kurang kredit pikeun ngamimitian.
temperature
top_p
Numutkeunnu nuNgeunaan kontrol sampel: temperature ti 0 ka 2, top_p ti 0 ka 1.
stopstring jeung arraynu nuTékstur anu ngéléhkeun jawaban: string atawa maximum 4 string, unggal maximum 256 karakter. nymbot/auto.
seedNgeunaannu nuPikeun sampel repeatable, dimana model mantuan eta.
presence_penalty
frequency_penalty
Numutkeunnu nuKontrol ulikan, unggal ti -2 ka 2.
response_formatObjek ieunu nu{"type": "json_object"} Anjeunna {"type": "json_schema", "json_schema": {…}}, dimana model ngarojong eta. teu dipaké ku nymbot/auto.
tools
tool_choice
parallel_tool_calls
array, string atawa obyek, booleannu nuNurutkeun fungsi. tingali Panggilan alatAnjeunna web_search Alat ieu ngajalankeun NurutkeunDina maksimum 128 alat jeung 512 KB tina definisi, nembongkeun dina maksimum 64 tingkat gelap; leuwih mangrupakeun 400.
reasoning_effort
reasoning
Ngeunaan obyeknu nu"minimal", "low", "medium" Anjeunna "high"Anjeunna {"effort": "high"}. "none" Anjeunna {"enabled": false} Ngeunaan ieu. tingali Argumentasi.
pluginsNgeunaannu nu[{"id": "web", "max_results": 5}] Always searches the web first. nepi ka 10 hasil.
nNgeunaannu nuHiji-hijina kitu deui bakal balik 400.
logit_bias
user
metadata
Ngeunaan string, obyeknu nuNurutkeun jeung teu dikirimkeun. logit_bias peta dina maksimum 300 ID token ka angka ti -100 ka 100; user Ngeunaan maksimum 256 karakter. metadata ngabogaan nepi ka 16 nilai string, kunci nepi ka 64 karakter jeung nilai nepi ka 512.

Jawaban téh biasa. chat.completionKu kituna, cost dina usage.cost (dalam dolar) jeung dina nymbot Objek téh. model ieu model id resolved, jadi hiji short name datang balik salaku full one. Lamun model reasoned saméméh ngobrol, reasoning nya téh di message.reasoning_contentIeu téh dipisahkeun ti jawab.

Jawaban

{
  "id": "chatcmpl-5f1c0a9e27d84b3c",
  "object": "chat.completion",
  "created": 1790726400,
  "model": "anthropic/claude-sonnet-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A Lightning invoice is a one-time payment request..."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1240,
    "completion_tokens": 380,
    "total_tokens": 1620,
    "prompt_tokens_details": { "cached_tokens": 0 },
    "completion_tokens_details": { "reasoning_tokens": 0 },
    "cost": 0.01895
  },
  "nymbot": {
    "balance": "pro",
    "charged_credits": 0.162,
    "charged_sats": 16.2,
    "balance_credits": 412.425,
    "balance_sats": 41242.5
  }
}

finish_reason ieu dikaluarkeun ti naon datang balik, saprak provider nyatakeun eta béda: tool_calls Ku kituna, lamun anjeun nyarankeun alat, length Demi sasatoan anu dimaksud nyaéta vertebrata, anu dimaksud nyaéta vertebrata. content_filter Demi sasatoan anu dimaksud nyaéta vertebrata. stop Nu séjénna. usage.completion_tokens_details.reasoning_tokens Always 0: token argumen tersembunyi dihitung, jeung dibayarkan, dina completion_tokens.

Status nuKu kituna
400nu nu model Anjeunna messages (missing_required_parameterNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (unsupported_contentNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (too_many_imagesNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (invalid_valueNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (invalid_image_urlNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (unsupported_tool); n Ngeunaan author nu: a. :thinking Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (model_not_foundNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (upstream_rejected).
402Saldo anu modél ngéléhkeun teu bisa nyertakeun holding.
403Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (key_limit_reachedDi handap ieu max_tokens Anjeun bisa ngaronjatkeun cap.
404Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (model_not_found).
429Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (upstream_rate_limited).
502, 503Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (upstream_errorNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (upstream_overloadedjeung Retry-AfterNaha kitu anu dibayaran lamun provider dibayaran pikeun percobaan.

Kode status unggal endpoint saham anu ditangtayungan di handap Salahkeun.

cURL

curl https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "messages": [
      {"role": "system", "content": "Answer in one short paragraph."},
      {"role": "user", "content": "What is a Lightning invoice?"}
    ],
    "max_tokens": 400
  }'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

reply = client.chat.completions.create(
    model="anthropic/claude-sonnet-5",
    messages=[
        {"role": "system", "content": "Answer in one short paragraph."},
        {"role": "user", "content": "What is a Lightning invoice?"},
    ],
    max_tokens=400,
)
print(reply.choices[0].message.content)
print(reply.usage.cost)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const reply = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5",
  messages: [
    { role: "system", content: "Answer in one short paragraph." },
    { role: "user", content: "What is a Lightning invoice?" },
  ],
  max_tokens: 400,
});
console.log(reply.choices[0].message.content);
console.log(reply.usage.cost);

Anjeunna streaming

jeung "stream": true Jawaban datang salaku acara dikirimkeun ku server nalika model dituliskeun eta. chat.completion.chunk Anjeunna a data: baris, jeung aliran ieu diakhiri ku data: [DONE]Argumentasi anu datang ka delta.reasoning_contentJawaban téh di delta.content.

Ngirimkeun sagala hal anu bisa ngurangan leuwih ti kira-kira 100 detik, kayaning jawaban panjang, max_tokens A request nu teu ditransmiskeun teu ngirimkeun kitu nepi ka jawabna geus lengkap, sarta jaringan antara anjeun jeung Nymbot bisa ditutup sambungan hésé sanggeus kira-kira 100 detik; model masih diakhiri jeung naon éta ditulis dicharge, tapi jawabna hilang. A stream ngirimkeun keep-alives, jadi eta tetep buka sabudeureun model ditulis.

Ngarankeun

data: {"id":"chatcmpl-5f1c0a9e27d84b3c","object":"chat.completion.chunk","created":1790726400,"model":"anthropic/claude-sonnet-5","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-5f1c0a9e27d84b3c","object":"chat.completion.chunk","created":1790726400,"model":"anthropic/claude-sonnet-5","choices":[{"index":0,"delta":{"content":"A Lightning invoice"},"finish_reason":null}]}

: keep-alive

data: {"id":"chatcmpl-5f1c0a9e27d84b3c","object":"chat.completion.chunk","created":1790726400,"model":"anthropic/claude-sonnet-5","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"chatcmpl-5f1c0a9e27d84b3c","object":"chat.completion.chunk","created":1790726400,"model":"anthropic/claude-sonnet-5","choices":[],"usage":{"prompt_tokens":1240,"completion_tokens":380,"total_tokens":1620,"cost":0.01895},"nymbot":{"balance":"pro","charged_credits":0.162,"charged_sats":16.2,"balance_credits":412.425,"balance_sats":41242.5}}

data: [DONE]
  • baris dimimitian ku : Nurutkeun komentar anu tetep hirup, dikirimkeun unggal 15 detik nalika model ieu berpikir. klien SSE leungitkeun aranjeunna.
  • Minta pikeun "stream_options": {"include_usage": true} pikeun meunangkeun potongan terakhir di luhur, jeung hiji kosong choicesDemi sasatoan anu dimaksud nyaéta vertebrata. nymbot Objek téh.
  • Nymbot nelepon sisa stream provider, pikeun nepi ka 25 detik, pikeun meunangkeun token count nya, jeung anjeun mayar naon provider ngabarkeun. tanpa anu count biaya ieu estimated ti input anjeun jeung naon anu ditulis, ditambah kabéh output allowance pikeun model nu alesan.
  • Salahkeun salah dina bagian mimiti, kayaning 401 Anjeunna 402, balik salaku JSON biasa jeung kode status na, teu salaku aliran. A kesalahan sanggeus aliran geus dimimitian datang salaku terakhir data: {"error": {…}} Ieu ngabalukarkeun acara, sarta aliran diakhiri tanpa [DONE].
  • Percobaan kalawan alat, jeung model on OpenAI's Responses transport, teu aliran ti provider. Aranjeunna masih nganggur jeung aliran sah, dikirimkeun saprak jawab geus lengkap.

cURL

curl -N https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nymbot/auto",
    "stream": true,
    "stream_options": {"include_usage": true},
    "messages": [{"role": "user", "content": "Write a haiku about sats."}]
  }'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

stream = client.chat.completions.create(
    model="nymbot/auto",
    stream=True,
    stream_options={"include_usage": True},
    messages=[{"role": "user", "content": "Write a haiku about sats."}],
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="", flush=True)
    elif chunk.usage:
        print("\ncost:", chunk.usage.cost)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const stream = await client.chat.completions.create({
  model: "nymbot/auto",
  stream: true,
  stream_options: { include_usage: true },
  messages: [{ role: "user", content: "Write a haiku about sats." }],
});
for await (const chunk of stream) {
  if (chunk.choices.length) process.stdout.write(chunk.choices[0].delta.content || "");
  else if (chunk.usage) console.log("\ncost:", chunk.usage.cost);
}

Ngobrol alat

Nurutkeun fungsi dina tools jeung model bisa nelepon pikeun nelepon badag jawab. Anjeun ngajalankeun fungsi, nambahkeun hasilna salaku tool Ngeunaan pesan anu sarua tool_call_idNymbot teu pernah ngajalankeun fungsi anjeun; eta nyadiakeun permintaan model ka anjeun.

tool_choice Anjeunna "auto", "none", "required" Anjeunna {"type": "function", "function": {"name": "…"}}Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (capabilities.toolsAlat anu ditolak ku 400 unsupported_tool Anjeunna nymbot/auto jeung dina sababaraha model katalog anu ngajalankeun dina transportasi Responses OpenAI, nu Nymbot teu bisa nganteurkeun alat ka.

jeung "stream": true, permintaan kalawan alat ngajalankeun dina hiji pot jeung lajeng dikirim salaku urutan potong normal: peran, hiji potongan ngabalukarkeun unggal call alat jeung indéks, id, ngaran jeung argumen, jeung potongan finish. klien anu nelepon panggero alat streaming ngabalukarkeun eta salaku biasa.

Jawaban téh, bagian

"choices": [
  {
    "index": 0,
    "message": {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_7d2e",
          "type": "function",
          "function": { "name": "get_invoice_status", "arguments": "{\"invoice_id\":\"a41f\"}" }
        }
      ]
    },
    "finish_reason": "tool_calls"
  }
]

cURL

curl https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "messages": [{"role": "user", "content": "Has invoice a41f been paid?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_invoice_status",
        "description": "Look up whether an invoice is paid.",
        "parameters": {
          "type": "object",
          "properties": {"invoice_id": {"type": "string"}},
          "required": ["invoice_id"]
        }
      }
    }]
  }'

Python

import json, os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

tools = [{
    "type": "function",
    "function": {
        "name": "get_invoice_status",
        "description": "Look up whether an invoice is paid.",
        "parameters": {
            "type": "object",
            "properties": {"invoice_id": {"type": "string"}},
            "required": ["invoice_id"],
        },
    },
}]
messages = [{"role": "user", "content": "Has invoice a41f been paid?"}]

reply = client.chat.completions.create(model="anthropic/claude-sonnet-5", messages=messages, tools=tools)
call = reply.choices[0].message.tool_calls[0]
args = json.loads(call.function.arguments)

messages.append(reply.choices[0].message)
messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps({"paid": True})})

final = client.chat.completions.create(model="anthropic/claude-sonnet-5", messages=messages, tools=tools)
print(final.choices[0].message.content)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const tools = [{
  type: "function",
  function: {
    name: "get_invoice_status",
    description: "Look up whether an invoice is paid.",
    parameters: {
      type: "object",
      properties: { invoice_id: { type: "string" } },
      required: ["invoice_id"],
    },
  },
}];
const messages = [{ role: "user", content: "Has invoice a41f been paid?" }];

const reply = await client.chat.completions.create({ model: "anthropic/claude-sonnet-5", messages, tools });
const call = reply.choices[0].message.tool_calls[0];
const args = JSON.parse(call.function.arguments);

messages.push(reply.choices[0].message);
messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify({ paid: true }) });

const final = await client.chat.completions.create({ model: "anthropic/claude-sonnet-5", messages, tools });
console.log(final.choices[0].message.content);

Gambar dina permintaan

Modél anu capabilities.vision Anjeun tiasa nelepon gambar. image_url bagian ka pesan pamaké, jeung hiji publik https:// link jeung a data:image/…;base64, Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan 86.000.000, anjeun bakal nempatkeun kana artikel ieu ngeunaan 86.000.000.400 invalid_image_urlNgeunaan pilihan detail Anjeunna auto, low Anjeunna high.

jeung nymbot/auto, permintaan kalawan gambar dina eta diarahkeun ka model standar nu bisa nempo. capabilities.vision Ngaronjatkeun gambar jeung 400 unsupported_contentGambar bisa ngan aya dina pesan pamaké. link kudu nelepon ka host umum; Nymbot ngirimkeun gambar ka provider model na teu nyimpen eta.

A gambar dibayaran salaku token input anu provider dihitung pikeun eta, kawas saterusna permintaan.

cURL

curl https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this picture?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/receipt.jpg"}}
      ]
    }]
  }'

Python

import base64, os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

with open("receipt.jpg", "rb") as f:
    data_url = "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()

reply = client.chat.completions.create(
    model="anthropic/claude-sonnet-5",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What is in this picture?"},
            {"type": "image_url", "image_url": {"url": data_url}},
        ],
    }],
)
print(reply.choices[0].message.content)

JavaScript

import { readFile } from "node:fs/promises";
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const dataUrl = "data:image/jpeg;base64," + (await readFile("receipt.jpg")).toString("base64");

const reply = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5",
  messages: [{
    role: "user",
    content: [
      { type: "text", text: "What is in this picture?" },
      { type: "image_url", image_url: { url: dataUrl } },
    ],
  }],
});
console.log(reply.choices[0].message.content);

Argumentasi

Modél anu capabilities.reasoning Anjeun tiasa nyarankeun pikeun leuwih atawa kurang. reasoning_effort ("minimal", "low", "medium" Anjeunna "high"Ngeunaan "reasoning": {"effort": "high"}Ngeunaan add :thinking Ngeunaan model, anu ngagambarkeun usaha tinggi. Dina model tanpa ngajarkeun nu setelan diabaikan. nymbot/auto, :thinking Ngirimkeun permintaan ka lalampahan argumen standar.

Dina model Anthropic usaha jadi anggaran pikiran ngeunaan 1,000, 2,000, 8,000 atawa 16,000 token, teu leuwih ti max_tokens Ngeunaan pamikiran anu ditinggalkeun lamun tool_choice Anjeun kudu nyandak hiji alat, sarta lamun permintaan terus hiji loop alat (panggilan panungtungan nya mangrupakeun hasil alat), sabab Anthropic kudu pikiran ditandatanganan saméméh pikeun ngaronjatkeun eta.

Argumentasi ieu balik dina message.reasoning_contentAnjeunna delta.reasoning_content Demi sasatoan anu dimaksud nyaéta sasatoan anu dimaksud nyaéta sasatoan anu dimaksud nyaéta sasatoan anu dimaksud. completion_tokensSababaraha provider teu ngabalukarkeun teks argumen sama sekali, sarta éta masih dibayarkan.

cURL

curl https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "reasoning_effort": "high",
    "messages": [{"role": "user", "content": "Is 2^61 - 1 prime? Show why."}]
  }'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

reply = client.chat.completions.create(
    model="anthropic/claude-sonnet-5",
    reasoning_effort="high",
    messages=[{"role": "user", "content": "Is 2^61 - 1 prime? Show why."}],
)
message = reply.choices[0].message
print(getattr(message, "reasoning_content", None))
print(message.content)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const reply = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5",
  reasoning_effort: "high",
  messages: [{ role: "user", content: "Is 2^61 - 1 prime? Show why." }],
});
console.log(reply.choices[0].message.reasoning_content);
console.log(reply.choices[0].message.content);

Modél ieu

A suffix dina ngaran model ngarobah kumaha permintaan ieu diproses, tanpa medan séjén. Aranjeunna ngoperasikeun on full ids jeung short names alike, kawas dina anthropic/claude-sonnet-5:online.

NgeunaanNgeunaan
:onlineMeunangkeun situs web, kawas plugins: [{"id": "web"}]Anjeunna Nurutkeun.
:thinkingNgeunaan argumen anu luhur; dina nymbot/autoDemi sasatoan anu dimaksud nyaéta vertebrata, nyaéta vertebrata. 400 model_not_found ku “no endpoints found”.
:nitro, :floor, :exacto, :extendedKabéh model katalog ngabogaan hiji ruteu, jadi teu aya leuwih gancang, murah, atawa leuwih panjang pikeun milih; suffixes diperbolehkeun jadi ngaran model disalin ti jasa lianna masih kerja.

Any other suffix is ignored. The whole name is tried first, jadi hiji model nu id anu bener ngandung a colon still works; mun teu ieu, suffixes disimpen ti ujung hiji dina waktu mun hiji model cocog. A model name can be at a maximum of 200 characters long with at a maximum of 4 suffixes; a longer one is refused with 400 invalid_value.

cURL

curl https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5:thinking",
    "messages": [{"role": "user", "content": "Plan a three-day trip to Lisbon."}]
  }'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

reply = client.chat.completions.create(
    model="anthropic/claude-sonnet-5:thinking",
    messages=[{"role": "user", "content": "Plan a three-day trip to Lisbon."}],
)
print(reply.choices[0].message.content)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const reply = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5:thinking",
  messages: [{ role: "user", content: "Plan a three-day trip to Lisbon." }],
});
console.log(reply.choices[0].message.content);

Any chat model can reply from the live web. Nymbot searches for the last user message (sipirang 2,000 karakter), read the best pages and gives them to the model with question, tagged as external content the model should not take instructions from. Aya dua mode:

  • Anjeunna terus pencarian: "plugins": [{"id": "web", "max_results": 5}]Anjeunna a :online Ieu cukup pikeun model.
  • Meunangkeun lamun dibantu: "tools": [{"type": "web_search", "parameters": {"max_results": 5}}]Ieu ogé dianggap salaku web_search_preview Anjeunna openrouter:web_searchNymbot searches ngan lamun pertanyaan tampaknya kudu informasi ayeuna, test anu sarua ngagunakeun aplikasi.

max_results nyaéta 5 ku default jeung di maksimum 10. sumber balik dina nymbot.web_search.sourcesDemi sasatoan anu aya di title, snippet jeung urlKu kituna url_citation Anotasi dina pesen.

Sakabéh pencarian nu ngajalankeun biaya $ 0.008, dialihkeun ka sats, di luhur token, sarta éta bagian tina hold. kaca nu dibaca nyaéta token input ogé, jadi jawab ti web biaya leuwih ti soalan anu sarua ditanyakeun dingin, kadang-kadang sababaraha kali leuwih.

Jawaban téh, bagian

"nymbot": {
  "balance": "pro",
  "charged_credits": 0.431,
  "charged_sats": 43.1,
  "balance_credits": 411.994,
  "balance_sats": 41199.4,
  "web_search": {
    "sources": [
      { "title": "Lightning Network - Wikipedia", "snippet": "The Lightning Network is a payment protocol...", "url": "https://en.wikipedia.org/wiki/Lightning_Network" }
    ]
  }
}

cURL

curl https://nymbot.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "plugins": [{"id": "web", "max_results": 5}],
    "messages": [{"role": "user", "content": "What changed in the latest Bitcoin Core release?"}]
  }'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

reply = client.chat.completions.create(
    model="anthropic/claude-sonnet-5",
    messages=[{"role": "user", "content": "What changed in the latest Bitcoin Core release?"}],
    extra_body={"plugins": [{"id": "web", "max_results": 5}]},
)
print(reply.choices[0].message.content)
for source in reply.model_extra["nymbot"]["web_search"]["sources"]:
    print(source["url"])

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const reply = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5",
  plugins: [{ id: "web", max_results: 5 }],
  messages: [{ role: "user", content: "What changed in the latest Bitcoin Core release?" }],
});
console.log(reply.choices[0].message.content);
for (const source of reply.nymbot.web_search.sources) console.log(source.url);

Ngeunaan API

Format anyar OpenAI, dipaké ku OpenAI Agents SDK jeung ku Codex. Ieu ngajalankeun dina model anu sarua, tagihan jeung fitur salaku Chat Complete.

POST https://nymbot.ai/api/v1/responses Anjeun kudu nyadiakeun API.

Field nutipe nuDiperlukanDaptarkeun
modelPikeun stringSumuhunPikeun Ngeunaan kompléksIeu kaasup suffixes.
inputstring jeung arraySumuhunA string, atawa daftar item: pesan (roles user, assistant, system, developerNgeunaan input_text, input_image jeung output_text Bagian ieu, jeung function_call jeung function_call_output barang pikeun alat. input_image Ngeunaan image_url link atawa data URL, teu file id. reasoning jeung web_search_call barang anu ditangtukeun; item_reference Ieu téh ditolak.
instructionsPikeun stringnu nuinstruksi pikeun sistem.
max_output_tokensNgeunaannu nuPaling gampang pikeun nyokot tulisan.
temperature
top_p
Numutkeunnu nuSampling kontrol, dimana model nyokot aranjeunna.
tools
tool_choice
parallel_tool_calls
array, string atawa obyek, booleannu nuNgeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan ({"type": "function", "name": …, "parameters": …}Ngeunaan web_search Anjeunna web_search_preview Alat ieu ngajalankeun Nurutkeun Anjeun tiasa ngaronjatkeun alat-alat séjén anu diwangun.
reasoningObjek ieunu nu{"effort": "minimal" | "low" | "medium" | "high"}. xhigh jeung max maksudna high; none Ngaronjatkeun eta off.
text.format
response_format
Objek ieunu nuNgatur output, salaku skema JSON atawa json_object.
metadataObjek ieunu nuDina maksimum 16 nilai string, kunci nepi ka 64 karakter jeung nilai nepi ka 512.
streamBouléonnu nuIeu ngabalukarkeun acara salaku dijelaskeun di handap.
storeBouléonnu nuNaha kitu disimpen, jeung jawabna selalu nyebutkeun "store": false.
previous_response_id
conversation
background
Ngeunaan string, obyek, booleannu nuNgeunaan dukungan: 400 unsupported_parameterJawaban teu disimpen, jadi ngirimkeun sakabéh percakapan ka input Tapi unggal waktos.

Jawaban

{
  "id": "resp_8c1e4b0f9a2d4e61",
  "object": "response",
  "created_at": 1790726400,
  "status": "completed",
  "model": "anthropic/claude-sonnet-5",
  "output": [
    {
      "type": "message",
      "id": "msg_2b7f",
      "role": "assistant",
      "status": "completed",
      "content": [{ "type": "output_text", "text": "A Lightning invoice is...", "annotations": [] }]
    }
  ],
  "output_text": "A Lightning invoice is...",
  "usage": {
    "input_tokens": 1240,
    "input_tokens_details": { "cached_tokens": 0 },
    "output_tokens": 380,
    "output_tokens_details": { "reasoning_tokens": 0 },
    "total_tokens": 1620
  },
  "incomplete_details": null,
  "error": null,
  "instructions": null,
  "store": false,
  "previous_response_id": null,
  "metadata": {},
  "nymbot": { "balance": "pro", "charged_credits": 0.162, "charged_sats": 16.2, "balance_credits": 412.425, "balance_sats": 41242.5 }
}

A tool request muncul dina output Anjeunna a function_call Titik jeung call_id, name jeung argumentsNgirimkeun hasilna jadi a function_call_output Ngeunaan item anu sarua call_idRasioning, lamun model nyadiakeun eta, nyaéta a reasoning Titik jeung reasoning_text Ngeunaan, nu disadiakeun di luhur. status Anjeunna incomplete Demi sasatoan anu dimaksud nyaéta: max_output_tokens Demi sasatoan anu dimaksud nyaéta vertebrata. incomplete_details.reason Anjeunna max_output_tokens Anjeunna content_filterJawaban ogé echoes settings tina permintaan (temperatur, alat, pilihan alat jeung saterusna) kawas OpenAI nu ngalakukeun, sarta ngabalukarkeun nymbot Ulah téh obyek.

Demi sasatoan anu dimaksud nyaéta: event: baris jeung a data: Dina garis a sequence_numberDina urutan ieu: response.created, response.in_progress, response.output_item.added, response.content_part.addedNgeunaan jumlah response.output_text.delta, response.output_text.done, response.content_part.done, response.output_item.doneSaterusna response.completed Ngeunaan jeung biaya. jawabna dipigawé ku response.incomplete Saterusna, jeung gagal sanggeus aliran dimimitian ku response.failedRésonansi aliran salaku item sorangan jeung response.reasoning_text.delta jeung .doneAlat panggero datang sanggeus pesan, unggal salaku item jeung response.function_call_arguments.delta jeung .done.

Status nuKu kituna
400nu nu model Anjeunna input; previous_response_id, conversation, background Anjeunna item_reference (unsupported_parameter); alat atawa tipe konten anu teu didukung.
402, 403, 404, 429, 502, 503Ku kituna pikeun chat completions.

cURL

curl https://nymbot.ai/api/v1/responses \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "instructions": "Answer in one short paragraph.",
    "input": "What is a Lightning invoice?"
  }'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://nymbot.ai/api/v1", api_key=os.environ["NYMBOT_API_KEY"])

response = client.responses.create(
    model="anthropic/claude-sonnet-5",
    instructions="Answer in one short paragraph.",
    input="What is a Lightning invoice?",
)
print(response.output_text)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://nymbot.ai/api/v1", apiKey: process.env.NYMBOT_API_KEY });

const response = await client.responses.create({
  model: "anthropic/claude-sonnet-5",
  instructions: "Answer in one short paragraph.",
  input: "What is a Lightning invoice?",
});
console.log(response.output_text);

Panggilan antropik

Format Anthropic, pikeun Anthropic SDKs jeung Claude Code. Ieu ngalaksanakeun unggal model dina katalog, teu ngan Claude: permintaan ieu diterjemahkeun, dilakukeun ngaliwatan pipeline anu sarua, sarta diterjemahkeun balik.

POST https://nymbot.ai/api/v1/messages — kudu API key, salaku x-api-key Anjeunna Authorization: Bearer.

Anjeunna anthropic-version jeung anthropic-beta ngaran model anthropic anu cocog jeung katalog, jadi Claude Code jeung SDKs kerja jeung ngaran nu geus dipaké:

  • Ngeunaan ngaran anu katuhu, kayaning claude-sonnet-5 Anjeunna anthropic/claude-opus-5Ieu dipaké salaku nu aya.
  • Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (-20260514), -latestVersi anu dimaksud nyaéta -v1Saterusna, hiji bracketed tag kawas [1m] Anjeunna anthropic/ Anjeunna anthropic. Ngeunaan author nu: Lamun anjeun resep artikel ieu ngeunaan (claude-haiku-4-5 Ngeunaan claude-haiku-4.5).
  • Upami ieu masih teu cocog, keluarga (Opus, Sonnet atawa Haiku) dipaké, salila versi katalog anu sarua atawa anyar ti anu diminta pikeun.
  • A ngaran nu cocog kitu balik 404 not_found_error.
Field nutipe nuDiperlukanDaptarkeun
modelPikeun stringSumuhunA ID model katalog, atawa ngaran model Anthropic.
max_tokensNgeunaanSumuhunPaling gampang pikeun nyokot tulisan.
messagesNgeunaanSumuhunuser jeung assistant Anjeunna, jeung text, image (base64 atawa sumber URL) tool_use jeung tool_result Blok téh. thinking blok ti tur sateuacan anu diakui jeung ditinggalkeun.
systemstring jeung arraynu nuSistem prompt, salaku string atawa blok teks.
temperature
top_p
Numutkeunnu nuSampling kontrol, dimana model nyokot aranjeunna. top_k Ieu ditangtukeun jeung ditinggalkeun.
stop_sequencesNgeunaan stringnu nuTékstur anu ngakhiran jawabna. Maksimalna 4 string, maksimum 256 karakter unggal.
tools
tool_choice
Ngeunaan obyeknu nuAlat jeung name, description jeung input_schemaAnjeunna web_search Server alat ngajalankeun Nurutkeun; alat dibéjérbéaskeun Anthropic lianna (bash, editor teks, pamakéan komputer) anu ditolak ku unsupported_tool. tool_choice Anjeunna auto, any, tool Anjeunna nonejeung disable_parallel_tool_use.
thinkingObjek ieunu nu{"type": "enabled", "budget_tokens": 8192}, {"type": "adaptive"} Anjeunna {"type": "disabled"}The anggaran milih tingkat usaha: di handap 2048 minimum, ti 2048 low, ti 8192 medium, ti 16384 tinggi. output_config.effortIeu téh tinggi.
streamBouléonnu nuDina format acara tina Anthropic.
metadataObjek ieunu nuNgeunaan jeung diabaikan.

Jawaban

{
  "id": "msg_01c7a2f93e5b4d08",
  "type": "message",
  "role": "assistant",
  "model": "anthropic/claude-sonnet-5",
  "content": [{ "type": "text", "text": "A Lightning invoice is..." }],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 1240,
    "output_tokens": 380,
    "cache_read_input_tokens": 0,
    "cache_creation_input_tokens": 0
  },
  "nymbot": { "balance": "pro", "charged_credits": 0.162, "charged_sats": 16.2, "balance_credits": 412.425, "balance_sats": 41242.5 }
}

content Anjeunna bisa nyimpen tool_use Blok jeung thinking Blok nu signature Ieu téh kosong. stop_reason Anjeunna end_turn, max_tokens, tool_use Anjeunna refusalDiwangun ku cara anu sarua jeung finish_reason Anjeunna Ngeunaan kompléks; stop_sequence Anjeunna selalu null, malah lamun urutan stop ngéléhkeun jawabna. input_tokens Ngeunaan bahan-bahan anu dipikaresepkeun kana bahan-bahan anu dipikaresepkeun kana bahan-bahan anu dipikaresep. nymbot Objek jeung X-Nymbot-Cost-Sats Anjeunna

Ngaropéa, acara anu Anthropic's: message_start, content_block_start, ping, content_block_delta (text_delta, input_json_delta Anjeunna thinking_delta), content_block_stop, message_delta Demi sasatoan anu dimaksud nyaéta vertebrata, nyaéta vertebrata. nymbot Ulah ngabalukarkeun obyek, jeung message_stopAnjeunna ping Ieu ogé dikirimkeun unggal 15 detik nalika model ieu dioperasikeun. panggero alat datang sanggeus teks, unggal salaku tool_use blok jeung sakabéh input di hiji input_json_delta.

Errors dina endpoint ieu ngagunakeun format Anthropic: {"type": "error", "error": {"type": "not_found_error", "message": "…"}}Ieu sahenteuna salila salila 402 billing_errorPikeun provider overloaded. 503 overloaded_errorA gagal sanggeus aliran geus dimimitian dikirim salaku error Ieu acara.

cURL

curl https://nymbot.ai/api/v1/messages \
  -H "x-api-key: $NYMBOT_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "What is a Lightning invoice?"}]
  }'

Python

import os
import anthropic

client = anthropic.Anthropic(base_url="https://nymbot.ai/api", api_key=os.environ["NYMBOT_API_KEY"])

message = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "What is a Lightning invoice?"}],
)
print(message.content[0].text)

JavaScript

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ baseURL: "https://nymbot.ai/api", apiKey: process.env.NYMBOT_API_KEY });

const message = await client.messages.create({
  model: "claude-sonnet-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "What is a Lightning invoice?" }],
});
console.log(message.content[0].text);

Ngeunaan token

A estimate of how many input tokens a Messages request would use, jadi hiji klien bisa cek saméméh eta ngirimkeun.

POST https://nymbot.ai/api/v1/messages/count_tokens — kudu API key. bébas.

Tubuh téh sarua jeung PanggilanTapi tanpa max_tokens; ngaran model kudu resolusi. hitungan mangrupakeun estimasi: karakter sistem prompt, pesan, panggilan alat jeung definisi alat dibagi ku empat, plus 1,600 pikeun unggal gambar. Ieu teu tokenizer sorangan provider, jadi hitungan nyata bisa beda. A kunci nu geus kapanggih cap na masih bisa ngagunakeun eta.

Jawaban

{ "input_tokens": 318 }

cURL

curl https://nymbot.ai/api/v1/messages/count_tokens \
  -H "x-api-key: $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "messages": [{"role": "user", "content": "What is a Lightning invoice?"}]
  }'

Python

import os
import anthropic

client = anthropic.Anthropic(base_url="https://nymbot.ai/api", api_key=os.environ["NYMBOT_API_KEY"])

count = client.messages.count_tokens(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "What is a Lightning invoice?"}],
)
print(count.input_tokens)

JavaScript

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ baseURL: "https://nymbot.ai/api", apiKey: process.env.NYMBOT_API_KEY });

const count = await client.messages.countTokens({
  model: "claude-sonnet-5",
  messages: [{ role: "user", content: "What is a Lightning invoice?" }],
});
console.log(count.input_tokens);

Nurutkeun model

Sakabéh model jeung generator API nampi, jeung naon biaya. daftar dibaca ti katalog hirup anu sarua jeung picker aplikasi, jadi éta selalu naon server bakal ngajalankeun.

GET https://nymbot.ai/api/v1/models — no key needed. disimpen pikeun lima menit.

GET /api/v1/models/{id} Meunangkeun 1 entri.

Field nutipe nuDiperlukanDaptarkeun
typeNgeunaan string (query)nu nuchat Demi sasatoan anu dimaksud nyaéta vertebrata. image, video, audio, embedding Anjeunna allAnjeun tiasa nyadiakeun sababaraha, salaku image,video.

Harga nyaéta naon anjeun bayar, jeung fee jeung margin geus di, dina dolar jeung dina sats dina harga Bitcoin ayeuna. balance Ieu ngécéskeun naon model ngéléhkeun. nymbot_key mangrupakeun ngaran pendek model dina app. created Ieu selalu 0 saprak katalog teu dicatat lamun model ieu ditambahkeun. model tanpa koin token diterbitkeun anu harga per_request tibatan.

nymbot/auto Éta selalu di awal, dibayar salaku variableKu kituna a routes Ieu nyaritakeun visi jeung argumen, tapi teu alat.

GET /api/v1/models/{id} nampa ngaran anu sarua jeung alias salaku permintaan, sarta ngabalukarkeun entri pikeun model nu aranjeunna resolving ka.

Jawaban

{
  "object": "list",
  "data": [
    {
      "id": "anthropic/claude-sonnet-5",
      "object": "model",
      "type": "chat",
      "owned_by": "anthropic",
      "name": "Claude Sonnet 5",
      "created": 0,
      "context_length": 1000000,
      "max_output_tokens": 64000,
      "architecture": { "input_modalities": ["text", "image"], "output_modalities": ["text"] },
      "supported_parameters": ["max_tokens", "temperature", "tools", "tool_choice", "reasoning", "response_format", "stop"],
      "capabilities": { "vision": true, "video": false, "tools": true, "reasoning": true, "web_search": true },
      "balance": "pro",
      "pricing": {
        "type": "per_token",
        "currency": "USD",
        "input_per_1M_tokens": 4.725,
        "output_per_1M_tokens": 23.625,
        "cache_read_per_1M_tokens": 0.4725,
        "sats_input_per_1M_tokens": 4038,
        "sats_output_per_1M_tokens": 20192
      },
      "description": "...",
      "nymbot_key": "claude-sonnet"
    }
  ]
}

Ngeunaan tipe séjénna:

  • Gambarna Anjeunna kudu capabilities (accepts_image_url, requires_image_url, editNgeunaan harga per_generation.
  • Video nu Anjeunna kudu max_duration_seconds jeung resolutionsPikeun harga per_second Pikeun unggal resolusi.
  • Anjeunna audio Anjeunna kudu audio_type speech Anjeunna transcriptionHarga anu per_1k_chars Anjeunna per_minute.
  • Ngeunaan Anjeunna kudu dimensions, context_length, max_inputs Ngeunaan harga 1 juta token input.

Harga ditandatanganan "estimated": true Ieu mangrupikeun estimasi aplikasi pikeun generator nu harga anu teu dipublikasikeun. type Ngobrol 400.

cURL

curl "https://nymbot.ai/api/v1/models?type=chat"

Python

import requests

models = requests.get("https://nymbot.ai/api/v1/models", params={"type": "chat"}).json()["data"]
for m in models:
    print(m["id"], m["balance"], m["pricing"].get("input_per_1M_tokens"))

JavaScript

const res = await fetch("https://nymbot.ai/api/v1/models?type=chat");
const { data } = await res.json();
for (const m of data) console.log(m.id, m.balance, m.pricing.input_per_1M_tokens);