跳至內容
回到 Nymbot

知識庫 開發者

圖像、音訊與嵌入向量

來自應用程式的生成器,以及搜尋的構建區塊:圖片、 影片、語音、逐字稿和嵌入,每一項皆從您的餘額中按使用量計費。

生成圖像

根據提示詞生成一到四張圖片,並在完成後回傳。它與以下生成器為同一套: ?image 在應用程式中。

POST https://nymbot.ai/api/v1/images/generations — 需要 API 金鑰,或者 每次請求一次 Lightning 付款.

Ids 來自於 GET /api/v1/models?type=image. 標準生成器, @cf/black-forest-labs/flux-1-schnell,每張圖片固定花費 5 個標準積分 (50 sats)。其他每個生成器都以各自的價格消耗 Pro 積分,並包含通常的費用和利潤,如: 該應用程式. n 圖片費用 n 倍數。產生器不接受的欄位會被捨棄而非拒絕; 標準產生器僅使用提示。

領域類型需要描述
model字串是的一個產生器 ID,例如 nano-banana.
prompt字串是的要畫什麼。僅使用前 2,000 個字元。
n整數不1 到 4。預設為 1。亦可接受為 num_images.
size字串不縱橫比例如 "16:9",或 OpenAI 的尺寸例如 "1792x1024", 並轉化為最接近的 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9, 5:4 與 4:5。 "auto" 交給生成器。
aspect_ratio字串不與……相同 size, 且若兩者皆發送則獲勝。
quality字串不特定於生成器的,例如 "low", "medium" 或者 "high".
negative_prompt字串不該省略什麼。
output_format字串不"png", "jpeg" 或者 "webp".
response_format字串不"url" (預設) 或 "b64_json".
image_url字串不一張作為起點的照片:an https:// 最多 4,096 個字元且不包含使用者名稱或密碼的連結,或者一個 data:image/…;base64 URL (PNG, JPEG, WebP 或 GIF;非 SVG)。僅適用於具有以下功能的產生器 edit; 對於那些有……的人是必需的 requires_image_url.

resolution 未使用:每個產生器都會產生自己的大小。With url, 每張圖片都會上傳到公開的 Blossom 主機並提供其連結(只有少數生成器 會回傳自己的連結,並將其轉發)。任何擁有連結的人都可以開啟它,且 一旦上傳便無法撤下;請參閱 API 可以看到什麼。帶著 b64_json 圖片在回應中返回,從未被上傳。一張作為...發送的圖片 data: URL 輸入 image_url 是以與...相同的方式檢查嗎 編輯 並先上傳至 Blossom 以便產生器可以獲取它;它 如果請求失敗

如果其中的一些 n 照片失敗,您只會收到成功的那些,且僅針對 成功的部分(以及提供商儘管失敗仍收取的任何費用)進行計費,並且 nymbot.failed 說明有多少個遺失。如果全部失敗,請求將返回 502.

回應

{
  "created": 1790726400,
  "model": "nano-banana",
  "cost": 0.2126,
  "data": [
    {
      "url": "https://blossom.example/5c0e4b7d3a91f2e8...c4.png",
      "content_type": "image/png"
    }
  ],
  "nymbot": { "balance": "pro", "charged_credits": 1.817, "charged_sats": 181.7, "balance_credits": 410.608, "balance_sats": 41060.8 }
}
狀態何時
400無提示; n 1 到 4 之外 (invalid_value); 不合適的大小 (invalid_size) 或圖片 (invalid_image, invalid_image_url); 一個存在但不是圖像生成器的模型 (invalid_model); 一張無法編輯的生成器圖片 (edit_unsupported); 需要圖片的那個人卻沒有 (image_required).
402餘額無法支付所要求的每一張圖片。
404沒有以此名稱命名的模型 (model_not_found).
502發電機故障了 (upstream_error). 除非供應商針對該次嘗試進行計費,否則不會收取任何費用;在這種情況下,錯誤已 charged_sats.
503目前無法託管圖片 (media_hosting_unavailable). b64_json 仍然有效。

cURL

curl https://nymbot.ai/api/v1/images/generations \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana",
    "prompt": "A lighthouse at dusk, oil painting",
    "size": "16:9"
  }'

Python

import os
import requests

res = requests.post(
    "https://nymbot.ai/api/v1/images/generations",
    headers={"Authorization": "Bearer " + os.environ["NYMBOT_API_KEY"]},
    json={"model": "nano-banana", "prompt": "A lighthouse at dusk, oil painting", "size": "16:9"},
)
res.raise_for_status()
print(res.json()["data"][0]["url"])

JavaScript

const res = await fetch("https://nymbot.ai/api/v1/images/generations", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.NYMBOT_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ model: "nano-banana", prompt: "A lighthouse at dusk, oil painting", size: "16:9" }),
});
const body = await res.json();
console.log(body.data[0].url);

編輯圖片

根據提示修改您上傳的照片。這是 OpenAI 的編輯端點,因此 OpenAI SDKs' images.edit 照常運作。只有 Pro 生成器具備 edit 在 模型列表中接受它。

POST https://nymbot.ai/api/v1/images/edits — 需要 API 金鑰,或者 每次請求一次 Lightning 付款. 身體是 multipart/form-data,最高可達 32 MB。

領域類型需要描述
image檔案是的要編輯的圖片:PNG、JPEG、WebP 或 GIF,最高 20 MB。也接受為 image[]; 第一個被使用了。
prompt字串是的要改變什麼。
model字串是的一台帶有 edit.
n整數不1 到 4。
size
aspect_ratio
quality
negative_prompt
output_format
字串不至於生成。
response_format字串不"b64_json" (這裡的預設值)或 "url".

您上傳的圖片會被檢查是否為格式正確的 PNG、JPEG、WebP 或 GIF,並以其真實類型發送,且會放置在公開的 Blossom 主機上,因為生成器是透過連結獲取輸入內容的。 請將其視為公開內容。如果編輯失敗且未收取費用,存放的副本將會再次被刪除。回應的格式與生成時相同。 定價方式為生成器的價格,某些生成器的價格會包含輸入圖片的費用。

回應

{
  "created": 1790726460,
  "model": "nano-banana",
  "cost": 0.2126,
  "data": [{ "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }],
  "nymbot": { "balance": "pro", "charged_credits": 1.817, "charged_sats": 181.7, "balance_credits": 408.791, "balance_sats": 40879.1 }
}
狀態何時
400無圖片或提示詞,一個不是圖片的檔案 (invalid_image), 或是一個無法編輯的產生器 (edit_unsupported).
413這張圖片超過 20 MB (file_too_large), 或整個請求超過 32 MB。
503現在無法託管該圖片 (media_hosting_unavailable).

cURL

curl https://nymbot.ai/api/v1/images/edits \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -F model=nano-banana \
  -F [email protected] \
  -F prompt="Make it a snowy evening"

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("photo.png", "rb") as f:
    result = client.images.edit(model="nano-banana", image=f, prompt="Make it a snowy evening")

with open("edited.png", "wb") as out:
    out.write(base64.b64decode(result.data[0].b64_json))

JavaScript

import fs from "node:fs";
import { writeFile } 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 result = await client.images.edit({
  model: "nano-banana",
  image: fs.createReadStream("photo.png"),
  prompt: "Make it a snowy evening",
});
await writeFile("edited.png", Buffer.from(result.data[0].b64_json, "base64"));

影片

影片需要幾分鐘的時間,因此會在背景執行。你提交影片後會立即獲得一個 ID,並持續詢問該 ID 的狀態直到完成。每個影片生成器都會消耗 Pro 餘額。

POST https://nymbot.ai/api/v1/videos — 需要 API 金鑰,或者 每次請求一次 Lightning 付款. 回傳 202.

領域類型需要描述
model字串是的影片生成器 ID 來自 GET /api/v1/models?type=video,例如 veo.
prompt字串是的應該發生什麼。
duration數字或字串不長度(以秒為單位),大於 0 且最多 60。僅供允許選擇長度的生成器使用;其他生成器則會產生其慣常的長度,也就是... seconds 在回覆中,價格隨後。
aspect_ratio字串不例如 "16:9" 或者 "9:16"; 像這樣的尺寸 "1280x720" 成為最接近的比率。
resolution
quality
字串不其中一個發電機的 resolutions 在模型列表中,例如 "720p" 或者 "1080p"它決定了價格。除此之外的一切都會被拒絕。 unsupported_resolution.
image_url字串不一張作為起點的照片:an https:// 連結或 a data:image/… URL,需先上傳到公開的 Blossom 主機。由具有...的生成器所要求 requires_image_url.

價格在您從產生器提交時即已固定,包含解析度與長度,因此一旦供應商接受任務,便會從您的 Pro 餘額中扣除,並顯示為 cost, estimated_cost 和 nymbot若提供者拒絕工作,則不會收取任何費用。若之後渲染失敗,或完成的剪輯無法儲存且提供者未對其進行計費,則該費用將自動退還一次。若渲染進行超過一小時仍未完成,則視為放棄,並保留該筆費用,因為提供者在接受渲染後即會進行計費。退款會退還點數,但不會降低金鑰的支出次數。

回應 (202)

{
  "id": "vid_3e9a51c07b2f4d86e0a1c4f2",
  "object": "video",
  "model": "veo",
  "status": "in_progress",
  "created": 1790726400,
  "seconds": 8,
  "resolution": "1080p",
  "estimated_cost": 3.18,
  "expires_at": 1790812800,
  "cost": 3.18,
  "nymbot": { "balance": "pro", "charged_credits": 31.8, "charged_sats": 3180, "balance_credits": 378.808, "balance_sats": 37880.8 }
}

status 開始於 in_progress, 或者 completed 隨著影片 已經在 data 當發電機立刻回傳時。

正在檢查一段影片

GET https://nymbot.ai/api/v1/videos/{id} — 需要一個屬於提交該 nym 的金鑰。達到上限的金鑰仍可進行檢查。

它回答了 202 在影片製作期間以及 200 一旦完成或失敗。每 5 到 10 秒詢問一次。每次檢查僅向提供者詢問一次並立即回答;它絕不會等待影片。作業在提交後會保留 24 小時。 GET /api/v1/videos 列出金鑰最後的 50 個工作為 {"object": "list", "data": […]}.

回應 (200)

{
  "id": "vid_3e9a51c07b2f4d86e0a1c4f2",
  "object": "video",
  "model": "veo",
  "status": "completed",
  "created": 1790726400,
  "seconds": 8,
  "resolution": "1080p",
  "estimated_cost": 3.18,
  "expires_at": 1790812800,
  "completed_at": 1790726590,
  "data": { "url": "https://blossom.example/9b41d0c2e7a3f658...1e.mp4", "content_type": "video/mp4" },
  "cost": 3.18,
  "nymbot": { "balance": "pro", "charged_credits": 31.8, "charged_sats": 3180 }
}

status 是 in_progress, completed 或者 failed. A 失敗的工作帶來了 error ({"code": "generation_failed", "message": …}); 如果已退款, cost 是 0 和 nymbot 新增 refunded_credits 和 refunded_sats. 完成後的影片位於公開的 Blossom 主機上,就像生成的圖片一樣。

狀態何時
400無提示;持續時間超出 0 到 60 (invalid_value); 生成器不提供的解析度 (unsupported_resolution); 需要圖片的產生器卻沒有圖片 (image_required); 一個不是影片生成器的模型 (invalid_model).
402Pro balance 無法覆蓋影片。
404無此產生器 (model_not_found), 或找不到該 nym 對應該 id 的工作,或是它已超過 24 小時 (video_not_found).
429你的用戶名已經有 10 個影片正在渲染中 (video_jobs_limit). 檢查一下進度,並在一個完成後提交更多。
502產生器拒絕了該工作。除非供應商已對其計費,否則不會收取任何費用。
503影片目前無法傳送或儲存 (media_hosting_unavailable, service_unavailable).

cURL

curl https://nymbot.ai/api/v1/videos \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "veo", "prompt": "Waves rolling onto a beach at sunrise", "duration": 8, "aspect_ratio": "16:9"}'

curl https://nymbot.ai/api/v1/videos/vid_3e9a51c07b2f4d86 \
  -H "Authorization: Bearer $NYMBOT_API_KEY"

Python

import os, time
import requests

headers = {"Authorization": "Bearer " + os.environ["NYMBOT_API_KEY"]}

job = requests.post(
    "https://nymbot.ai/api/v1/videos",
    headers=headers,
    json={"model": "veo", "prompt": "Waves rolling onto a beach at sunrise", "duration": 8, "aspect_ratio": "16:9"},
).json()

while True:
    time.sleep(8)
    status = requests.get("https://nymbot.ai/api/v1/videos/" + job["id"], headers=headers).json()
    if status["status"] in ("completed", "failed"):
        break

print(status["data"]["url"] if status["status"] == "completed" else status["error"])

JavaScript

const headers = {
  "Authorization": "Bearer " + process.env.NYMBOT_API_KEY,
  "Content-Type": "application/json",
};

const job = await (await fetch("https://nymbot.ai/api/v1/videos", {
  method: "POST",
  headers,
  body: JSON.stringify({ model: "veo", prompt: "Waves rolling onto a beach at sunrise", duration: 8, aspect_ratio: "16:9" }),
})).json();

let status;
do {
  await new Promise((r) => setTimeout(r, 8000));
  status = await (await fetch("https://nymbot.ai/api/v1/videos/" + job.id, { headers })).json();
} while (status.status !== "completed" && status.status !== "failed");

console.log(status.status === "completed" ? status.data.url : status.error);

文字轉語音

朗讀文本並回傳音訊檔案本身,而非連結。這是 OpenAI 的語音端點, 所以 audio.speech.create 在 OpenAI SDKs 中運作。

POST https://nymbot.ai/api/v1/audio/speech — 需要 API 金鑰,或者 每次請求一次 Lightning 付款.

領域類型需要描述
model字串不來自一個語音模型 音訊模型清單. 預設:標準聲音, @cf/myshell-ai/melotts. aura-2 是 Deepgram Aura 2。
input字串是的待讀文字:標準語音最多 800 個字元,Aura 2 最多 2,000 個字元。
voice字串不來自一個聲音 ID 聲音列表:像 Aura 這樣的揚聲器,例如 luna (或 aura-2-luna-en), 或 MeloTTS 語言 (en, es, fr, zh). OpenAI 語音名稱例如 alloy 是被接受的,並提供模型的預設聲音。
language字串不語言代碼,例如 es. 在沒有聲音的情況下,它會為該語言選擇一個聲音。說著另一種語言的聲音會返回 422 voice_language_mismatch,以及一種模型無法發聲的語言 422 unsupported_language.
response_format字串不標準聲音回歸了 mp3 僅僅。Aura 2 回歸 mp3 (預設值), opus, aac, flac, wav 或者 pcm.
speed數字不已接受並被忽略。

標準語音每次請求固定消耗 3 個標準積分 (30 sats),與 App 中相同。Aura 2 是 Pro 版本,按您發送的字元計費 Content-Type; 成本在於 X-Nymbot-Cost-Sats 頁首。如果 語音模型失敗,則不收取任何費用。

回應

HTTP/1.1 200 OK
Content-Type: audio/mpeg
X-Nymbot-Cost-Sats: 4.2
X-Nymbot-Balance-Sats: 41055.6

(audio bytes)
狀態何時
400無輸入;輸入超過模型的限制 (input_too_long); 模型無法產生的格式 (unsupported_response_format); 一個陌生的聲音 (invalid_voice); 一個不是語音模型的模型 (invalid_model).
422該語音不會說所提供的語言,或者該模型沒有對應的語音。
502語音模型失敗。未收取任何費用。

cURL

curl https://nymbot.ai/api/v1/audio/speech \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "aura-2", "voice": "luna", "input": "Your invoice has been paid."}' \
  --output speech.mp3

Python

import os
from openai import OpenAI

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

audio = client.audio.speech.create(
    model="aura-2",
    voice="luna",
    input="Your invoice has been paid.",
)
audio.write_to_file("speech.mp3")

JavaScript

import { writeFile } 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 audio = await client.audio.speech.create({
  model: "aura-2",
  voice: "luna",
  input: "Your invoice has been paid.",
});
await writeFile("speech.mp3", Buffer.from(await audio.arrayBuffer()));

音訊模型與聲音

兩份用於挑選語音模型與聲音,或逐字稿模型的公開清單。共有 41 位 Aura 2 英語說話者與四種 MeloTTS 語言。

GET https://nymbot.ai/api/v1/audio/models — 不需要金鑰。

GET https://nymbot.ai/api/v1/audio/voices?language=en — 不需要金鑰。

領域類型需要描述
language字串 (查詢)不僅限此語言的配音。
model字串 (查詢)不此模型僅限語音。

回應 (聲音)

{
  "object": "list",
  "data": [
    { "id": "luna", "name": "Luna", "provider": "deepgram", "model_id": "aura-2", "models": ["aura-2"], "language": "en", "description": "Aura 2 English voice", "gender": "female", "preview_url": null },
    { "id": "en", "name": "MeloTTS English", "provider": "myshell", "model_id": "@cf/myshell-ai/melotts", "models": ["@cf/myshell-ai/melotts", "melotts"], "language": "en", "description": "English (MeloTTS)", "gender": null, "preview_url": null }
  ]
}

模型列表回答 {"object": "list", "data": {"tts": […], "stt": […]}}. 每個語音模型都提供其平衡、價格, max_input_chars, response_formats, languages 和 default_voice; 轉錄模型給出了它的別名, max_file_bytes, max_seconds, 格式與每分鐘價格。

cURL

curl https://nymbot.ai/api/v1/audio/models
curl "https://nymbot.ai/api/v1/audio/voices?language=en"

Python

import requests

print(requests.get("https://nymbot.ai/api/v1/audio/models").json())
for voice in requests.get("https://nymbot.ai/api/v1/audio/voices", params={"language": "en"}).json()["data"]:
    print(voice["id"], voice["model_id"])

JavaScript

console.log(await (await fetch("https://nymbot.ai/api/v1/audio/models")).json());
const voices = await (await fetch("https://nymbot.ai/api/v1/audio/voices?language=en")).json();
for (const v of voices.data) console.log(v.id, v.model_id);

語音轉文字

使用 Whisper 將錄音轉換為文字。這是 OpenAI 的逐字稿端點,所以 audio.transcriptions.create 有效。

POST https://nymbot.ai/api/v1/audio/transcriptions — 需要 API 金鑰,或者 每次請求一次 Lightning 付款. 身體是 multipart/form-data.

領域類型需要描述
file檔案是的錄音大小從 256 位元組到 25 MB 不等,時長最高可達 30 分鐘:WAV、WebM、MP4 或 M4A、Ogg 或 Opus、MP3 以及其他 Whisper 可讀取的格式。對於 MP3 及其他無法預先讀取時長的格式,大小限制為 1.8 MB。
model字串不預設 whisper,也就是 Whisper Large v3 Turbo。 whisper-1, whisper-large-v3-turbo 和 @cf/openai/whisper-large-v3-turbo 意思相同。
language字串不口語,例如 en若被遺漏則會被偵測到。
prompt字串不預期的單字或拼寫,例如姓名。僅使用前 1,000 個字元。
response_format字串不json (預設值), text, srt, vtt 或者 verbose_json.

對於 WAV、WebM、MP4 和 Ogg 檔案,長度會在任何程序執行前從檔案中讀取,因此超過 30 分鐘的錄音會被直接拒絕(具有 3 秒的緩衝時間)。WAV 檔案的長度取決於其取樣率、聲道數和取樣大小。其他格式(例如 MP3)的長度無法預先讀取,因此它們受到檔案大小的限制:在 Nymbot 假設的最低位元率 8 kbps 下,30 分鐘為 1.8 MB,而此格式中更大的檔案將會被拒絕,其原因為 413 audio_too_long 在任何程序執行前。請將較長的錄音以 WAV、WebM、MP4 或 Ogg 格式傳送。如果 Whisper 仍回報超過 30 分鐘,該請求將會因...而被拒絕。 413 audio_too_long,且由於 Whisper 已運行,因此將收取 30 分鐘的費用。

您支付的費用取決於音訊長度,並以秒為單位無條件進位:取下列三者中的最大值:從檔案讀取的長度、Whisper 回報的長度,以及檔案大小所允許的最小長度;費用按 Whisper 的每分鐘價格加上通常的費用與利潤計算,且每次請求至少為 0.05 credit。若標準餘額足以支付預留款項,則從標準餘額中扣除,否則從 Pro 餘額中扣除;a 402 說明了每種 餘額的需求。在 App 中,轉錄語音訊息可能是免費的;但在 API 上, 則總是會收費。如果 Whisper 失敗,則不會收取任何費用。

回應

{
  "text": "Your invoice has been paid.",
  "usage": { "type": "duration", "seconds": 3 },
  "nymbot": { "balance": "standard", "charged_credits": 0.05, "charged_sats": 0.5, "balance_credits": 120.35, "balance_sats": 1203.5 }
}

text 回傳純文字, srt 和 vtt 回傳字幕,以及 verbose_json 新增語言、時長和定時分段。對於那三個 不是 JSON 的項目,成本會在標頭中。

狀態何時
400沒有檔案,一個沒有可用音訊的檔案 (invalid_audio), 未知的格式,或不是轉錄模型的模型 (invalid_model).
402兩者餘額都無法支付。
413檔案超過 25 MB (file_too_large) 或錄音超過 30 分鐘,或格式無法預先讀取長度,則超過 1.8 MB (audio_too_long).
502Whisper 無法處理該音訊。未收取任何費用。

cURL

curl https://nymbot.ai/api/v1/audio/transcriptions \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -F [email protected] \
  -F model=whisper \
  -F response_format=json

Python

import os
from openai import OpenAI

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

with open("memo.m4a", "rb") as f:
    transcript = client.audio.transcriptions.create(model="whisper", file=f)
print(transcript.text)

JavaScript

import fs from "node:fs";
import OpenAI from "openai";

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

const transcript = await client.audio.transcriptions.create({
  model: "whisper",
  file: fs.createReadStream("memo.m4a"),
});
console.log(transcript.text);

將演講翻譯成英文

POST https://nymbot.ai/api/v1/audio/translations — 需要 API 金鑰,或者 每次請求一次 Lightning 付款. 身體是 multipart/form-data.

與逐字稿相同,除了以下欄位外,其餘欄位皆相同 language, 限制與 價格,但無論說的是哪種語言,文字都會以英文返回。OpenAI SDK 使用 它調用 audio.translations.create.

cURL

curl https://nymbot.ai/api/v1/audio/translations \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -F [email protected] \
  -F model=whisper

Python

import os
from openai import OpenAI

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

with open("nota.m4a", "rb") as f:
    translation = client.audio.translations.create(model="whisper", file=f)
print(translation.text)

JavaScript

import fs from "node:fs";
import OpenAI from "openai";

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

const translation = await client.audio.translations.create({
  model: "whisper",
  file: fs.createReadStream("nota.m4a"),
});
console.log(translation.text);

嵌入

將文本轉換為向量,用於搜尋、分群與去重。模型在 Cloudflare 上執行,並消耗標準餘額。

POST https://nymbot.ai/api/v1/embeddings — 需要 API 金鑰,或者 每次請求一次 Lightning 付款.

領域類型需要描述
model字串是的來自的嵌入模型 GET /api/v1/models?type=embedding.
input字串或字串陣列是的要嵌入的文字,最多 100 個非空字串。拒絕使用 Token 陣列 (token_input_unsupported). 每個輸入都必須符合模型的 context_length,大約計算為每個標記四個位元組。
encoding_format字串不float (預設) 或 base64 (小端序 32 位浮點數)。
dimensions整數不模型本身的大小,或對於一個具有的模型的 supported_dimensions 其中之一;接著將向量縮短並歸一化。除此之外的一切都會被拒絕。
模型尺寸上下文
@cf/baai/bge-m31024,多種語言8,192 個標記
@cf/qwen/qwen3-embedding-0.6b1024,多種語言8,192 個標記
@cf/baai/bge-large-en-v1.51024, 英文512 個 token
@cf/baai/bge-base-en-v1.5768, 英文512 個 token
@cf/baai/bge-small-en-v1.5384, 英文512 個 token

模型列表是關於可用模型及其成本的唯一事實來源;當目錄中包含其價格時,Google 的 EmbeddingGemma(可根據需求提供較短的向量)也會顯示在那裡。 嵌入(Embeddings)按輸入 token 計費,且每次請求適用 0.05 積分的最低消費,而非每次輸入, 因此將大量文本批次處理成一個請求,會比逐一發送便宜得多。

回應

{
  "object": "list",
  "data": [
    { "object": "embedding", "index": 0, "embedding": [0.0213, -0.0487, 0.0112] }
  ],
  "model": "@cf/baai/bge-m3",
  "usage": { "prompt_tokens": 9, "total_tokens": 9 },
  "nymbot": { "balance": "standard", "charged_credits": 0.05, "charged_sats": 0.5, "balance_credits": 1204.35, "balance_sats": 12043.5 }
}
狀態何時
400無輸入或輸入為空;符號陣列 (token_input_unsupported); 超過 100 個輸入 (too_many_inputs); 輸入長度超過模型限制 (input_too_long); 一個模型無法提供的尺寸 (unsupported_dimensions).
402標準餘額太低了。Embeddings 從不使用 Pro 餘額。
404沒有該名稱的嵌入模型。
502模型失敗了。沒有收取任何費用。

cURL

curl https://nymbot.ai/api/v1/embeddings \
  -H "Authorization: Bearer $NYMBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@cf/baai/bge-m3", "input": ["Lightning invoices expire.", "Invoices on Lightning have a time limit."]}'

Python

import os
from openai import OpenAI

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

result = client.embeddings.create(
    model="@cf/baai/bge-m3",
    input=["Lightning invoices expire.", "Invoices on Lightning have a time limit."],
)
print(len(result.data), len(result.data[0].embedding))

JavaScript

import OpenAI from "openai";

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

const result = await client.embeddings.create({
  model: "@cf/baai/bge-m3",
  input: ["Lightning invoices expire.", "Invoices on Lightning have a time limit."],
});
console.log(result.data.length, result.data[0].embedding.length);