Mafdet AI Help Center中文

Chat Completions

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

The OpenAI-compatible chat completion endpoint — the core way to call Mafdet AI.

Request fields

FieldTypeDescription
modelstringModel ID, e.g. gemini-3-flash-lite, deepseek-v4-flash (see Models overview)
messagesarrayConversation messages, each with role (system/user/assistant) and content
temperaturenumberSampling temperature; higher is more random (optional)
max_tokensnumberMax tokens to generate (optional; the model default is used if omitted)
streambooleanStream the response — see Streaming

Response fields

FieldDescription
idUnique ID for this completion
modelThe model actually used
choicesCandidate replies; the text is in choices[0].message.content
usageToken usage: prompt_tokens / completion_tokens / total_tokens

Node.js example

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: "You are a concise assistant." },
      { role: "user", content: "Hello" },
    ],
  }),
});
const data = await res.json();
console.log(data.choices[0].message.content);

Python example

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": "Hello"}],
)
print(resp.choices[0].message.content)

Next steps