基础 URL 和认证
首先使用基础 URL 进行身份验证 https://api.googlegeminiuncensored.com/v1. 您会在通过 Google 或电子邮件注册后立即获得一个活跃的 API 密钥。将此密钥用于 Authorization 页眉作为所有后续请求的 Bearer 令牌。
- 基础 URL:
https://api.googlegeminiuncensored.com/v1 - 标头:
Authorization: Bearer YOUR_API_KEY
curl https://api.googlegeminiuncensored.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the top five open source LLMs for local deployment"}]
}'
聊天完成端点
向 POST /v1/chat/completions. 此端点接受标准消息数组并返回无内容过滤的原始文本响应,适用于合法的成人用途。
from openai import OpenAI
client = OpenAI(base_url="https://api.googlegeminiuncensored.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它是一个在我们服务器上运行的开源权重模型,不同于 GPT 或 Gemini。它不在供应商之间路由,也不提供嵌入。
流式响应(SSE)
通过将 stream: true 在您的请求正文中。API 返回服务器发送事件 (SSE),其中 Token 使用数据出现在最后一个数据块中。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.googlegeminiuncensored.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);流式传输降低了长输出的感知延迟。每个块包含部分文本增量。解析最后一个事件以获取总令牌消耗量,以实现计费透明。
流式传输
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)