基礎 URL 與驗證
向基礎 URL 發送請求 https://api.codexapipricing.com/v1 使用您的 API 金鑰。此端點與標準 OpenAI SDK 相容,因此您只需更新基礎 URL 並提供您的金鑰即可。透過傳遞標頭進行身份驗證 Authorization: Bearer YOUR_API_KEY 每個請求都會產生。您可以立即透過使用 Google 或電子郵件密碼登入來生成金鑰。金鑰在建立後僅顯示一次,因此請妥善保存。您的提示詞不會用於訓練,確保您的資料隱私。
聊天完成端點
使用 POST /v1/chat/completions 用於產生文字的端點。這是傳送提示並接收回應的主要介面。模型 ID 始終為 uncensored無論我們的伺服器上運行的是哪個模型版本。您可以透過檢查可用模型 GET /v1/models. 在 messages
支援的參數與 JSON 模式
使用類似 temperature, top_p,以及 stop. 使用 response_format 設定為 {"type": "json_object"} 以強制輸出 JSON。這非常適合結構化資料擷取或函式呼叫。您也可以設定 max_tokens 以限制輸出長度,若未指定則預設為 2,048。上下文視窗支援最多 100,000 個 token,包含提示與完成部分。傳入 seed 用於確定性結果或 presence_penalty 和 frequency_penalty 調整重複。這些參數允許在不複雜配置的情況下微調模型行為。JSON 模式確保嚴格的格式,以便在您的應用程式中進行可靠解析。
透過 SSE 的串流回應
在請求主體中將 stream: true 在你的請求中。API 在生成 Token 時返回伺服器發送的事件 (SSE)。這降低了長回應的感知延遲。Token 使用詳情出現在串流的最後一個區塊中。你可以增量處理 Token 以即時顯示文字。此功能與所有 OpenAI 相容的 SDK 配合使用。串流非常適合期望即時回饋的聊天介面。最後一個區塊包含用於準確計費的總 Token 計數。使用此方法優雅地處理大輸出,而無需等待完整回應。
速率限制與請求主體
每個 API 金鑰限制為每分鐘 300 次請求和 8 個並行請求。最大請求主體大小為 8 MB。若超出這些限制,您將收到 429 錯誤。您可以生成新金鑰以取代現有金鑰,但每個帳戶僅有一個金鑰處於啟用狀態。錯誤與拒絕不計入您的速率限制。100,000 個 token 的上下文視窗允許大量的對話歷史。保持請求主體精簡以符合大小限制。監控您的使用量以避免在高峰時段中斷。這些限制確保所有預付客戶的公平使用。
錯誤處理與故障排除
透過檢查 HTTP 狀態碼來處理錯誤。401 錯誤表示 API 金鑰無效或缺失。402 錯誤表示您的預付信用額度已耗盡。429 錯誤表示您已超過速率限制。使用 error field in the response to get details. Mistakes like double charges are fixed via the Support page. Credit never expires, so you can top up later. Refusals for content policy violations are free. This predictable error structure helps you debug integration issues quickly without guessing the cause.
cURL
curl https://api.codexapipricing.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the hourly rates for the large model."}]
}'Python
from openai import OpenAI
client = OpenAI(base_url="https://api.codexapipricing.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)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.codexapipricing.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)