Mafdet AI 帮助中心English

Chat Completions

POST https://api.mafdet.ai/v1/chat/completions

OpenAI 兼容的对话补全接口,是 Mafdet AI 最核心的调用方式。

请求字段

字段类型说明
modelstring模型 ID,如 gemini-3-flash-litedeepseek-v4-flash(见 模型总览
messagesarray对话消息数组,每条含 rolesystem/user/assistant)和 content
temperaturenumber采样温度,越高越随机(可选)
max_tokensnumber生成的最大 token 数(可选;不传则用模型默认值)
streamboolean是否流式返回,见 流式调用

响应字段

字段说明
id本次补全的唯一 ID
model实际使用的模型
choices候选回复数组,正文在 choices[0].message.content
usagetoken 用量:prompt_tokens / completion_tokens / total_tokens

Node.js 示例

const res = await fetch("https://api.mafdet.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MAFDET_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gemini-3-flash-lite",
    messages: [
      { role: "system", content: "你是一个简洁的助手。" },
      { role: "user", content: "你好" },
    ],
  }),
});
const data = await res.json();
console.log(data.choices[0].message.content);

Python 示例

from openai import OpenAI

client = OpenAI(
    base_url="https://api.mafdet.ai/v1",
    api_key="sk-mafdet-xxxxxxxxxxxxxxxx",
)
resp = client.chat.completions.create(
    model="gemini-3-flash-lite",
    messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)

下一步