基础 URL & 认证
使用我们的专用 base URL 将请求路由到我们的无审查模型。您的 API key 对每次调用进行身份验证,请妥善保管。该端点接受大多数 SDK 中找到的标准 headers。
- 基础 URL:
https://api.mistralapidocs.com/v1 - 标头:
Authorization: Bearer YOUR_API_KEY
在 获取 API 密钥 页面,通过 Google 或电子邮件登录。您无需电话验证即可立即获得密钥。
聊天完成端点
发送简单的文本提示以获取直接回复。模型 ID 为 uncensored 并处理文本输入、文本输出任务。错误和拒绝不会消耗额度,因此您可以自由测试。
这可通过更新base URL与任何OpenAI兼容的客户端配合使用。
curl https://api.mistralapidocs.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Set the log level to debug in the config file"}]
}'
Python SDK 集成
使用官方 Python 库快速集成。覆盖 base URL 指向我们的服务器。这使您的现有代码结构保持不变,同时获得对我们 uncensored 模型的访问权限。
from openai import OpenAI
client = OpenAI(base_url="https://api.mistralapidocs.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 SDK 集成
使用 Node.js SDK 集成到服务器端应用程序中。在客户端配置中设置 base URL 和 API 键。此方法确保与标准 JavaScript 工作流的兼容性。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.mistralapidocs.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)
限制、错误 & 上下文窗口
我们的 API 支持 100,000 token 的上下文窗口。每次请求最多可输出 16,000 token。速率限制为每分钟 300 次请求,每个密钥最多 8 个并发请求。处理 HTTP 401(无效密钥)、402(信用不足)和 429(速率限制)。预付费信用永不过期,因此你可以随时暂停和恢复。