基础 URL 和认证
向基础 URL https://api.codexapipricing.com/v1 使用您的 API 密钥。此端点兼容标准 OpenAI SDK,因此您只需更新 base URL 并提供您的密钥即可。通过传递请求头进行身份验证 Authorization: Bearer YOUR_API_KEY 每次请求都会生成此密钥。您可以通过使用 Google 或电子邮件和密码登录立即生成密钥。密钥在创建后显示一次,因此请安全保存。您的提示词不用于训练,确保您的数据隐私。
聊天完成端点
使用 POST /v1/chat/completions 用于生成文本的端点。这是发送提示和接收响应的主要接口。模型 ID 始终为 uncensored, 无论服务器上运行的是哪个模型版本。您可以通过 GET /v1/models. 在 messages
支持的参数和 JSON 模式
使用 temperature 等参数进行生成。 temperature, top_p,以及 stop. 使用 response_format 设置为 {"type": "json_object"} 以强制 JSON 输出。这对于结构化数据提取或函数调用非常有用。您还可以设置 max_tokens 限制输出长度,如果省略则默认为 2,048。上下文窗口支持最多 100,000 个令牌(提示和补全合计)。传递 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)