身份驗證與基礎 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)溫度(Temperature)和 top_p 調整創造力。停止序列(Stop sequences)運作正常。
速率限制與錯誤
每分鐘 300 次請求,每支金鑰 8 個併發請求。最大請求體大小為 8 MB。
401 表示金鑰無效。402 表示沒有額度。429 表示超過速率限制。
常見問題
這是官方的 grok API NSFW 服務嗎?
否。我們是獨立供應商,運行我們自己的無審查模型。我們使用 OpenAI 相容格式。
計費方式為何?
僅限預付額度。使用加密貨幣付費。錯誤免費。無月費。
什麼是上下文窗口?
合計 100,000 tokens。每次請求最大輸出為 16,000 tokens。
取得您的 API 金鑰
註冊、複製您的金鑰、更新基礎網址。這就是所需的全部。