驗證與 base URL
在儀表板生成您的金鑰。
使用此基礎 URL 發送所有請求:
HTTPS://api.nsfwia.com/v1
將您的金鑰傳入 Authorization 標頭。該端點支援標準的 OpenAI-compatible 客戶端。
發送您的第一個請求
向 /v1/chat/completions 發送 POST 請求以取得回應。
對於文本生成使用模型 ID "uncensored"
輸入是文本,輸出是文本。無圖像或影片。
這是一個基本 curl 範例:
curl https://api.nsfwia.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the API endpoints and their HTTP methods"}]
}'
串流回應
透過將 stream 設為 true 來啟用串流。
接收即時生成的 token。
使用 SSE 進行實時輸出。
這非常適合角色扮演。
串流程式碼範例:
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)
函式呼叫與 JSON 模式
使用函式呼叫進行結構化輸出。
設定 response_format 為 json_object 以獲得嚴格的 JSON。
在請求主體中定義工具。
這可確保可靠的解析。
Python SDK 範例:
from openai import OpenAI
client = OpenAI(base_url="https://api.nsfwia.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)
參數:temperature、top_p 與更多選項
調整溫度以獲得創意。
設定 top_p 進行核心採樣。
使用停止序列來終止生成。
種子確保可重現性。
Node SDK 範例:
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.nsfwia.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);
理解 token 成本
定價為每 1M 輸入 token $0.15,每 1M 輸出 token $0.50。
錯誤免費。拒絕(Refusals)也免費。
上下文窗口總計為 100,000 token。
每個請求的最大輸出為 16,000 個 Token。
限制:每分鐘 300 次請求,8 個併發請求。
錯誤包含 401(無效金鑰)、402(無餘額)、429(速率限制)。