基礎 URL 與驗證
聊天機器人 API 位於 https://api.chatterbotapi.com/v1. 使用 Authorization 標題。您的金鑰在透過 Google 或電子郵件註冊後立即顯示。
- 基礎 URL:
https://api.chatterbotapi.com/v1 - 標頭:
Authorization: Bearer YOUR_API_KEY
更換金鑰時,舊金鑰會立即被替換。請妥善保管。
首次請求
向以下網址發送 POST 請求 /v1/chat/completions 使用模型 uncensored. API 會回傳文字,針對合法成人內容不會有標準的拒絕機制。
這是一個最小的 cURL 範例:
curl https://api.chatterbotapi.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "What is the capital city of France"}]
}'驗證回應包含 choices[0].message.content.
Python SDK 集成
使用官方 OpenAI Python 庫。將其指向我們的 base URL 並注入您的金鑰。客戶端會自動處理 JSON 序列化。
from openai import OpenAI
client = OpenAI(base_url="https://api.chatterbotapi.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)此方法同時適用於串流和非串流呼叫。模型 ID 保持 uncensored.
Node.js SDK 設置
使用自訂基礎 URL 初始化 OpenAI npm 套件。這確保了與現有 OpenAI 客戶端的相容性。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.chatterbotapi.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);配置環境變數或直接傳遞金鑰。API 的行為與任何標準的 chat-completions 端點相同。
串流回應
在請求主體中將 stream: true. API 會傳送伺服器發送事件(SSE)。Token 使用資料僅出現在最後一個區塊中。
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)隨到隨處理每個數據塊。這減少了長達 16,000 token 的長輸出的感知延遲。
Limits and Errors
若金鑰無效,預期 401 錯誤。402 錯誤表示您的預付額度已耗盡。錯誤與拒絕不會消耗 token。您受限於每分鐘 300 次請求。上下文視窗總計 100,000 個 token。請求主體必須低於 8 MB。