认证和基础 URL
首先将基础 URL 和 API 密钥设置在您的环境中。我们的 API 位于 HTTPS://api.aiwithnofilter.com/v1,接受任何标准的 OpenAI 兼容客户端。在仪表板上使用 Google 或邮箱生成密钥,然后将其作为 Bearer Token 传递。这确保每个请求都能正确认证,无需额外请求头。
curl https://api.aiwithnofilter.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "generate a python function to parse json logs"}]
}'
发送您的第一个补全请求
向 /v1/chat/completions 发起 POST 请求,模型 id 为 "uncensored"。以标准 JSON 格式发送您的系统提示和用户消息。API 立即返回文本响应,准备好用于您的应用程序逻辑。这适用于角色扮演、创意写作或任何不受限制的文本生成任务。
from openai import OpenAI
client = OpenAI(base_url="https://api.aiwithnofilter.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)
使用 SSE 的流式响应
通过在请求体中将 stream 设置为 true 启用流式传输。API 在生成令牌时发送服务器发送事件(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 模式
使用 tools 参数定义模型可以调用的函数。传递 tool_choice 以强制执行特定行为或让模型自行决定。通过将 response_format 设置为 json_object 启用 JSON 模式,以严格符合 schema。这确保为您的后端服务集成提供结构化输出。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.aiwithnofilter.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);
参数:温度、Top P、Seed
使用 temperature 控制创造力,使用 top_p 控制多样性。使用 seed 在调试期间生成可重复的输出。设置 stop sequences 以在特定标记处停止生成。这些参数让您精确控制模型行为,而无需切换模型。
应用每分钟 300 次请求限制。
理解 Token 使用与限制
您的上下文窗口总计 100,000 个令牌,包括提示和完成。每次请求的最大输出为 16,000 个令牌,除非您另行指定。错误和拒绝不消耗令牌,因此您只为实际使用付费。优雅处理 401(无效密钥)、402(余额不足)和 429(速率限制)错误。
余额永不过期,确保不浪费资金。