认证和基础 URL
使用您的 API 密钥与基础 URL HTTPS://api.grokapinsfw.com/v1。每个请求均需包含 Authorization 头。
curl https://api.grokapinsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Send a message now"}]
}'通过仪表板使用 Google 或邮箱创建密钥。每个账户一个密钥,无需电话验证。
首次聊天完成请求
发送 POST 请求至 /v1/chat/completions。模型 ID 为 "uncensored"。
from openai import OpenAI
client = OpenAI(base_url="https://api.grokapinsfw.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)文本输入,文本输出。不支持嵌入或视觉功能。上下文窗口总计为 100,000 个 token。
Node.js 集成
使用相同的基础 URL 和密钥配置您的 Node 客户端。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.grokapinsfw.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);流式返回 SSE 事件。使用标准的 OpenAI SDK 无需更改。
流式响应
通过 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)适用于实时 UI。每个 token 均准确计费。
函数调用与 JSON 模式
支持工具定义和 JSON 严格模式。将 response_format 设置为 json_object。
from openai import OpenAI
client = OpenAI(base_url="https://api.grokapinsfw.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)温度和 top_p 调整创造性。停止序列按预期工作。
速率限制与错误
每分钟 300 次请求,每个密钥最多 8 个并发请求。最大请求体大小为 8 MB。
401 表示密钥无效。402 表示没有余额。429 表示超出速率限制。
常见问题
这是官方的 grok API NSFW 服务吗?
否。我们是一个独立提供商,运行我们自己的无限制模型。我们使用 OpenAI 兼容格式。
计费是如何运作的?
仅预存余额。使用加密货币支付。错误免费。无月费。
什么是上下文窗口?
100,000 个 token 合计。每个请求最大输出为 16,000 个 token。
获取您的 API 密钥
注册,复制密钥,并更新基础 URL。这是所需的全部。