知識庫 開發者
聊天、回覆與訊息
三種詢問模型的方法,採用客戶已在使用的三種格式,全部運行在相同的模型上,且計費方式完全相同。
為了方便起見,此頁面是機器翻譯的。英文原件為適用版本。
聊天補全
OpenAI 的對話格式,也是幾乎所有工具都支援的格式。傳送目前的對話內容, 並取得下一則訊息。
POST https://nymbot.ai/api/v1/chat/completions — 需要一個 API 金鑰。
只有 model 和 messages 是必要的。如果選擇的模型不接受某個取樣參數,該參數會在不報錯的情況下被忽略,因此一個請求主體即可適用於多種模型。
模型列表提供了每個模型的 supported_parameters比起直接丟棄,更傾向於拒絕的是任何模型完全無法做到的事情:對於無法看見的模型來說是圖片,對於無法調用的模型來說是工具。
| 領域 | 類型 | 需要 | 描述 |
|---|---|---|---|
model | 字串 | 是的 | nymbot/auto (或 auto) 用於 Nymbot 在標準餘額上的路由,或目錄模型 ID,例如 anthropic/claude-sonnet-5 在 Pro 餘額中。應用程式的簡稱與別名也接受。可能以 a 結尾。 後綴. |
messages | 陣列 | 是的 | 對話。角色 system, developer (視為系統), user, assistant 和 tool. Content 是一個字串或一個列表 text 和 image_url 零件;僅限使用者訊息中的圖片。 input_audio 且檔案部分被拒絕。 |
stream | 布林值 | 不 | 按原樣發送答案。看 串流. |
stream_options | 物件 | 不 | {"include_usage": true} 新增包含 token 數量與成本的最後一個區塊。 |
max_tokensmax_completion_tokens | 整數 | 不 | 寫入的最大標記數。若高於模型的最大值,則會降低至模型的最大值。這也會設定從您的餘額中扣除的金額,因此較小的數字需要較少的點數即可開始。 |
temperaturetop_p | 數字 | 不 | 抽樣控制: temperature 從 0 到 2, top_p 從 0 到 1。 |
stop | 字串或陣列 | 不 | 結束答案的文字:一個字串或最多 4 個字串,每個字串最多 256 個字元。不被以下項目使用 nymbot/auto. |
seed | 整數 | 不 | 在模型支援的情況下,用於可重複採樣。 |
presence_penaltyfrequency_penalty | 數字 | 不 | 重複控制,範圍各為 -2 到 2。 |
response_format | 物件 | 不 | {"type": "json_object"} 或者 {"type": "json_schema", "json_schema": {…}},在模型支援的情況下。不被使用於 nymbot/auto. |
toolstool_choiceparallel_tool_calls | 陣列、字串或物件、布林值 | 不 | 函式呼叫。參見 工具呼叫. A web_search 工具開啟了 網路搜尋. 最多 128 個工具與 512 KB 的定義,最多嵌套 64 層;更多則是一個 400. |
reasoning_effortreasoning | 字串, 物件 | 不 | "minimal", "low", "medium" 或者 "high", 或者 {"effort": "high"}. "none" 或者 {"enabled": false} 將其關閉。看 推理. |
plugins | 陣列 | 不 | [{"id": "web", "max_results": 5}] 總是先搜尋網路。最多 10 個結果。 |
n | 整數 | 不 | 只有 1。除此之外皆會返回 400. |
logit_biasusermetadata | 物件, 字串, 物件 | 不 | 已接受但未轉發。 logit_bias 將最多 300 個 token id 映射到 -100 到 100 之間的數字; user 最多 256 個字元; metadata 最多包含 16 個字串值,鍵長最多 64 個字元,值長最多 512 個字元。 |
回覆是平凡的 chat.completion,包含成本在內 usage.cost
(以美元計)以及在 nymbot 物件 model 是已解析的模型 ID,
所以回傳的簡短名稱會變成完整名稱。如果模型在回答前進行了推理,其
推理過程位於 message.reasoning_content, 與答案分開。
回應
{
"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 是根據回傳的結果計算出來的,因為供應商的報告方式不同: tool_calls 當模型要求使用工具時, length 當
回答使用了所有允許的 token(或者模型耗盡了所有 token 進行推理而未寫出
回答)時, content_filter 當提供者拒絕時,而且 stop
否則。 usage.completion_tokens_details.reasoning_tokens 總是 0:隱藏
推理標記(reasoning tokens)會被計算並計費,在 completion_tokens.
| 狀態 | 何時 |
|---|---|
400 | 不 model 或者 messages (missing_required_parameter); 音訊或檔案部分,或是無法看見它們的模型所使用的圖片 (unsupported_content); 超過 20 張照片 (too_many_images); 取樣參數類型錯誤或超出範圍 (invalid_value); 一個非公開的圖片連結 (invalid_image_url); 無法調用它們的模型上的工具 (unsupported_tool); n 除了 1 以外;a :thinking 無法推理的模型上的後綴 (model_not_found); 或供應商拒絕了請求 (upstream_rejected). |
402 | 模型消耗的餘額無法支付預留款項。 |
403 | 最差的情況是鍵帽不合身 (key_limit_reached). 較低 max_tokens 或提高上限。 |
404 | 沒有以此名稱命名的模型 (model_not_found). |
429 | 金鑰的速率限制,或是供應商的 (upstream_rate_limited). |
502, 503 | 供應商失敗 (upstream_error) 或已過載 (upstream_overloaded,與 Retry-After除非提供商針對嘗試進行了計費,否則不會收取任何費用。 |
每個端點共用的狀態碼列於 錯誤.
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);
串流
與 "stream": true 答案在模型寫作時以伺服器傳送事件 (server-sent events) 的形式傳回。每個事件都是一個 chat.completion.chunk 在一個 data: 行,且
串流結束於 data: [DONE]. 推理出現於
delta.reasoning_content,答案在 delta.content.
串流任何可能需要大約 100 秒以上的內容,例如長答案、大型
max_tokens 或是推理模型。非串流模式的請求在答案完成前不會發送任何內容,而您與 Nymbot 之間的網路可能會在閒置約 100 秒後關閉連線;此時模型仍會完成運作且產生的內容仍會計費,但答案會遺失。串流模式會發送保持連線(keep-alives)訊號,因此只要模型還在寫作,連線就會保持開啟。
串流
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]
- 以...開頭的行
:在模型思考時,每 15 秒會發送一次 keep-alive 註釋。SSE 用戶端會跳過這些內容。 - 要求
"stream_options": {"include_usage": true}要取得上方最後一個區塊, 在空的情況下choices,代幣數量、成本以及nymbot物件 - 費用會在串流結束後結算。如果您提前關閉連線,模型並不會停止:Nymbot 會繼續讀取供應商剩餘的串流(最多持續 25 秒)以取得其 token 數量,而您支付的金額將依供應商報告的數據為準。若缺乏該數量,費用將根據您的輸入、已生成的內容,加上該推理模型整體的輸出額度進行估算。
- 在第一個區塊之前的錯誤,例如
401或者402,會以包含狀態碼的 一般 JSON 形式返回,而不是串流。串流開始後的錯誤 會作為最後一個傳回data: {"error": {…}}事件,且串流在沒有...的情況下結束[DONE]. - 使用工具的請求以及在 OpenAI 的 Responses 傳輸層上的模型,並不會從供應商端進行串流。它們仍然會以有效的串流形式進行回答,但在答案完整生成後才一次性發送。
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);
}
工具呼叫
描述中的函數 tools 而且模型可以要求進行呼叫而不是
回答。您執行該函數,並將其結果作為一個 tool 具有相同的訊息
tool_call_id,並再次發送對話。Nymbot 從不執行你的函式;
它將模型的請求傳回給你。
tool_choice 拿取 "auto", "none",
"required" 或者 {"type": "function", "function": {"name": "…"}}.
模型列表標記了哪些模型可以調用工具 (capabilities.tools). 工具被
拒絕,原因為 400 unsupported_tool 開啟 nymbot/auto 而且在少數運行於 OpenAI Responses 傳輸層的目錄模型上,
Nymbot 無法向其傳遞工具。
與 "stream": true,一個包含工具的請求會完整運行,隨後以一般的區塊序列發送:角色、一個攜帶所有工具呼叫及其索引、ID、名稱與參數的區塊,以及結束區塊。讀取串流工具呼叫的客戶端會照常處理。
部分回應
"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);
請求中的圖片
帶有模型的 capabilities.vision 可以讀取圖片。新增一個 image_url
使用者訊息的一部分,帶有公開的 https:// 連結或 a
data:image/…;base64, URL。每次請求最多 20 張圖片。
拒絕 SVG 圖片,也不接受超過 4,096 個字元的連結,或包含使用者名稱或密碼的連結
(400 invalid_image_url). 一個選用的 detail 是
auto, low 或者 high.
與 nymbot/auto,包含圖片的請求會被路由至一個具備視覺能力的標準模型。一個不具備視覺能力的目錄模型 capabilities.vision 拒絕附帶...的圖片
400 unsupported_content. 圖片只能出現在使用者訊息中。
連結必須指向公開主機;Nymbot 會將圖片傳遞給模型的提供者,且不會保留圖片。
圖片會根據供應商計算的輸入 token 進行計費,就像請求中的其他部分一樣。
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);
推理
帶有模型的 capabilities.reasoning 在回答之前可以思考。要求更多或更少
的內容,使用 reasoning_effort ("minimal", "low",
"medium" 或者 "high") 或 "reasoning": {"effort": "high"},或
新增 :thinking 對模型名稱而言,這意味著高投入。對於沒有推理能力的模型,該設定會被忽略。使用 nymbot/auto, :thinking 將
請求發送到標準推理路由。
在 Anthropic 模型上,投入的精力會轉化為大約 1,000、2,000、8,000 或 16,000 個 token 的思考預算,絕不會超過。 max_tokens 允許。當...時,停止思考
tool_choice 強制使用工具,且當請求持續進入工具迴圈(其最後一條訊息是工具結果)時,因為 Anthropic 需要先前的已簽署思考過程來恢復它。
這同樣適用於 Responses 和 Messages 端點。
推理回來了 message.reasoning_content, 或者
delta.reasoning_content 在串流時,絕不要混入答案中。推理是
輸出內容,並會以此方式計費,在內部 completion_tokens. 一些供應商不會
回傳推理文本,但仍然會收費。
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);
模型後綴
模型名稱上的後綴可以在不使用其他欄位的情況下,改變請求的處理方式。
它們對於完整 ID 和簡短名稱同樣有效,例如 anthropic/claude-sonnet-5:online.
| 後綴 | 效果 |
|---|---|
:online | 先搜尋網路,例如 plugins: [{"id": "web"}]. 看 網路搜尋. |
:thinking | 高推理強度;開啟 nymbot/auto,推理路徑。在一個無法推理的模型上, 400 model_not_found 顯示為「未找到端點」。 |
:nitro, :floor, :exacto, :extended | 已接受並忽略。每個目錄模型只有一條路由,因此沒有更快、更便宜或更長的選項可供選擇;允許使用後綴,因此從其他服務複製的模型名稱仍可正常運作。 |
任何其他後綴都會被忽略。會先嘗試完整的名稱,因此即使模型 ID 確實包含冒號,該模型仍可運作;若失敗,則會逐一從末尾移除後綴,直到找到匹配的模型為止。模型名稱長度最多為 200 個字元,且最多只能有 4 個後綴;若超過此長度則會被拒絕,錯誤訊息為 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);
網路搜尋
任何聊天模型都可以從即時網路獲取答案。Nymbot 會搜尋最後一條使用者訊息(其前 2,000 個字元),閱讀最佳頁面,並將這些頁面連同問題一起提供給模型,並標記為模型不應接受指令的外部內容。共有兩種模式:
- 始終搜尋:
"plugins": [{"id": "web", "max_results": 5}], 或是一個:online模型上的後綴。 - 在有幫助時進行搜尋:
"tools": [{"type": "web_search", "parameters": {"max_results": 5}}],也被接受為web_search_preview或者openrouter:web_search. Nymbot 僅在問題看起來需要最新資訊時才進行搜尋,其測試機制與該應用程式相同。
max_results 預設為 5,最多為 10。來源會以以下方式傳回
nymbot.web_search.sources, 每個都有一個 title, snippet 和
url,且隨著 url_citation 訊息上的註解。
每一次運行的搜尋除了 token 之外,還會額外產生 0.008 美元的費用(轉換為 sats),這也是持有成本的一部分。它所閱讀的頁面也是輸入 token,因此從網路獲取的答案比直接提問的成本更高,有時甚至高出好幾倍。
部分回應
"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);
回應 API
OpenAI 的新格式,由 OpenAI Agents SDK 與 Codex 使用。 其運行的模型、計費方式與功能皆與 Chat Completions 相同。
POST https://nymbot.ai/api/v1/responses — 需要一個 API 金鑰。
| 領域 | 類型 | 需要 | 描述 |
|---|---|---|---|
model | 字串 | 是的 | 至於 聊天補全,包含字尾。 |
input | 字串或陣列 | 是的 | 一個字串,或是一組項目列表:messages (roles user, assistant, system, developer) 與 input_text, input_image 和 output_text 零件,以及 function_call 和 function_call_output 工具用品。 input_image 拿一個 image_url 連結或資料 URL,而非檔案 ID。 reasoning 和 web_search_call 項目已跳過; item_reference 被拒絕了。 |
instructions | 字串 | 不 | 系統指令。 |
max_output_tokens | 整數 | 不 | 要寫出最多的 token。 |
temperaturetop_p | 數字 | 不 | 採樣控制,模型套用這些控制之處。 |
toolstool_choiceparallel_tool_calls | 陣列、字串或物件、布林值 | 不 | 函式工具,在回應的形狀中 ({"type": "function", "name": …, "parameters": …}). A web_search 或者 web_search_preview 工具開啟了 網路搜尋 在有幫助時。其他的內建工具則被拒絕。 |
reasoning | 物件 | 不 | {"effort": "minimal" | "low" | "medium" | "high"}. xhigh 和 max 意思 high; none 將其關閉。 |
text.formatresponse_format | 物件 | 不 | 結構化輸出,如 JSON schema 或 json_object. |
metadata | 物件 | 不 | 在回應中保持不變。最多 16 個字串值,鍵最多 64 個字元,值最多 512 個字元。 |
stream | 布林值 | 不 | 如下所述串流事件。 |
store | 布林值 | 不 | 已忽略。不儲存任何內容,且回應總是顯示 "store": false. |
previous_response_idconversationbackground | 字串, 物件, 布林 | 不 | 不支援: 400 unsupported_parameter. 回應不會被儲存,因此請在傳送時包含完整的對話內容 input 每一次。 |
回應
{
"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 }
}
出現了一個工具請求,位在 output 作為一個 function_call 帶有物品的
call_id, name 和 arguments; 將結果以 a 送回
function_call_output 具有相同內容的項目 call_id. 推理,當
模型回傳它時,是一個 reasoning 帶有物品的 reasoning_text 內容,
首先列出。 status 是 incomplete 當答案來襲時
max_output_tokens 或者供應商拒絕了,伴隨著
incomplete_details.reason 設定為 max_output_tokens 或者
content_filter. 回應也會像 OpenAI 一樣反映請求的設定(temperature、
tools、tool choice 等等),並攜帶 nymbot 成本
物件。
以串流方式傳輸,每個事件都是一個 event: 線與 a data: 帶有 a 的行
sequence_number, 依此順序: response.created,
response.in_progress, response.output_item.added,
response.content_part.added,任何數量的 response.output_text.delta,
response.output_text.done, response.content_part.done,
response.output_item.done, 最後 response.completed 及其 response.incomplete 相反,而且在串流開始後發生了
失敗,其開頭為 response.failed. 推理流作為其
自身的項目,並帶有 response.reasoning_text.delta 和 .done. 工具呼叫
位於訊息之後,每一項皆為一個項目,包含 response.function_call_arguments.delta
和 .done.
| 狀態 | 何時 |
|---|---|
400 | 不 model 或者 input; previous_response_id, conversation, background 或一個 item_reference (unsupported_parameter); 不支援的工具或內容類型。 |
402, 403, 404, 429, 502, 503 | 至於對話補全。 |
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);
Anthropic 訊息
Anthropic 的格式,適用於 Anthropic SDK 和 Claude Code。它適用於目錄中的每個模型,而不僅僅是 Claude:請求會被翻譯,通過相同的流水線執行,然後再翻譯回來。
POST https://nymbot.ai/api/v1/messages — 需要 API 金鑰,因為 x-api-key 或者 Authorization: Bearer.
這 anthropic-version 和 anthropic-beta 標頭會被接受且
被忽略。Anthropic 模型名稱會與目錄進行比對,因此 Claude Code 與 SDKs 能
使用它們現有的名稱:
- 目錄所知的名稱,例如
claude-sonnet-5或者anthropic/claude-opus-5,照原樣使用。 - 否則為日期 (
-20260514),-latest,版本標籤例如-v1, 一個帶括號的標籤,例如[1m]和一個anthropic/或者anthropic.前綴被移除,且點與橫線 版本中的會以兩種方式嘗試 (claude-haiku-4-5發現claude-haiku-4.5). - 如果仍未匹配到任何內容,則會使用該系列(Opus、Sonnet 或 Haiku),只要 目錄的版本與要求的版本相同或更新。
- 不匹配任何內容的名稱會返回
404not_found_error.
| 領域 | 類型 | 需要 | 描述 |
|---|---|---|---|
model | 字串 | 是的 | 目錄模型 ID,或 Anthropic 模型名稱。 |
max_tokens | 整數 | 是的 | 要寫出最多的 token。 |
messages | 陣列 | 是的 | user 和 assistant 轉向,帶著 text, image (base64 或 URL 來源), tool_use 和 tool_result 區塊 thinking 先前回合的區塊會被接受或捨棄。 |
system | 字串或陣列 | 不 | 系統提示詞,以字串或文本塊的形式。 |
temperaturetop_p | 數字 | 不 | 採樣控制,模型套用這些控制之處。 top_k 被接受並丟棄。 |
stop_sequences | 字串陣列 | 不 | 結束回答的文字。最多 4 個字串,每個最多 256 個字元。 |
toolstool_choice | 陣列,物件 | 不 | 具有...的工具 name, description 和 input_schema. A web_search 伺服器工具啟動 網路搜尋; Anthropic 的其他內建工具 (bash, text editor, computer use) 被拒絕,原因為 unsupported_tool. tool_choice 拿取 auto, any, tool 或者 none,而且 disable_parallel_tool_use. |
thinking | 物件 | 不 | {"type": "enabled", "budget_tokens": 8192}, {"type": "adaptive"} 或者 {"type": "disabled"}預算會選擇一個努力程度:低於 2,048 為極小,2,048 以上為低,8,192 以上為中,16,384 以上為高。自適應使用 output_config.effort,或高。 |
stream | 布林值 | 不 | 以 Anthropic 的事件格式進行串流。 |
metadata | 物件 | 不 | 已接受並被忽略。 |
回應
{
"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 也可以持有 tool_use 區塊與 a thinking
區塊,其 signature 是空的。 stop_reason 是
end_turn, max_tokens, tool_use 或者 refusal,
運算方式與...相同 finish_reason 開啟
聊天補全; stop_sequence 一直都是
null,即使停止序列結束了回答。 input_tokens 計數
僅限新輸入;快取輸入位於兩個快取欄位中。成本在於
nymbot 物件與 X-Nymbot-Cost-Sats 頁首
串流傳輸中,Anthropic 的活動如下: message_start,
content_block_start, ping, content_block_delta
(text_delta, input_json_delta 或者 thinking_delta),
content_block_stop, message_delta 包含停止原因、使用量以及
the nymbot 成本對象,以及 message_stop. A ping 在模型運作時,
每 15 秒也會傳送一次。工具呼叫會在文本之後傳送,每個皆為
tool_use 將其整個輸入包含在一個區塊中 input_json_delta.
此端點上的錯誤使用 Anthropic 的格式:
{"type": "error", "error": {"type": "not_found_error", "message": "…"}}. A
短餘額是 402 billing_error,一個超載的提供者
503 overloaded_error串流開始後的失敗會以 an 形式傳送 error 事件。
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);
計算權杖
估計一次 Messages 請求會使用多少輸入 token,以便客戶端在發送前進行檢查。這是免費的,但仍需要金鑰。
POST https://nymbot.ai/api/v1/messages/count_tokens — 需要 API 金鑰。免費。
內容與...相同 訊息,沒有 max_tokens;
模型名稱必須能解析。計數是一個估計值:系統提示詞、
訊息、工具呼叫與工具定義的字元數除以四,再加上每張圖片 1,600。
這並非供應商自身的 tokenizer,因此實際計數可能會有所不同。
已達到上限的密鑰仍可使用。
回應
{ "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);
列出模型
API 所接受的每個模型與生成器及其對應成本。此列表是從與應用程式選擇器相同的即時目錄中讀取的,因此它始終代表伺服器將運行的內容。
GET https://nymbot.ai/api/v1/models — 不需要金鑰。已快取五分鐘。
GET /api/v1/models/{id} 回傳一筆項目。
| 領域 | 類型 | 需要 | 描述 |
|---|---|---|---|
type | 字串 (查詢) | 不 | chat (預設值), image, video, audio, embedding 或者 all. 可以給出幾個,例如 image,video. |
價格即是您所支付的金額,已包含費用與利潤,並以當前比特幣價格換算為美元與聰(sats)。 balance 指出模型消耗的是哪種餘額。
nymbot_key 模型的簡稱在應用程式中。 created 永遠是
0,因為目錄並未記錄模型何時被新增。沒有已發布代幣
費率的模型,其定價為 per_request 反而。
nymbot/auto 總是第一,定價為 variable,帶著一個
routes 列出各標準路由的費率。它列出了視覺與推理,但
沒有列出工具。
GET /api/v1/models/{id} 接受與請求相同的名稱和別名,並回傳它們所指向的模型項目。
回應
{
"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"
}
]
}
其他類型:
- 圖像 項目具有
capabilities(accepts_image_url,requires_image_url,edit) 與 價格per_generation. - 影片 項目具有
max_duration_seconds和resolutions, 以及一個價格per_second針對每個解析度。 - 音訊 項目具有
audio_typespeech或者transcription,定價per_1k_chars或者per_minute. - 嵌入 項目具有
dimensions,context_length,max_inputs以及每百萬輸入 token 的價格。
已標價 "estimated": true 是該應用程式對價格未公開之發電機的估算。一個未知的 type 回報 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);