认证与基础 URL
在仪表板生成您的密钥。
使用此基础 URL 发送所有请求:
HTTPS://api.nsfwia.com/v1
将密钥放入 Authorization 请求头中。该端点接受标准的 OpenAI 兼容客户端。
发送你的第一次请求
向 /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 来启用流式传输。
接收生成的令牌。
使用 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 及更多
调整 temperature 以获取创意。
设置 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);
理解令牌成本
定价为每 100 万输入令牌 $0.15,每 100 万输出令牌 $0.50。
错误免费。拒绝(Refusals)也免费。
上下文窗口总共 100,000 token。
每次请求最大输出为 16,000 个 Token。
限制:每分钟 300 次请求,8 个并发请求。
错误包括 401(密钥无效)、402(无余额)、429(速率限制)。