AiFO مستندات AiFO

Endpoint

POST /v1/chat/completions — سازگار با OpenAI Chat Completions API. مدل‌های CHAT، VISION و REASONING از این endpoint استفاده می‌کنند.

POST https://api.haftominhonar.ir/v1/chat/completions

Schema پیام‌ها و پارامترها

آرایه messages شامل role (system, user, assistant) و content است. پارامترهای اختیاری بسته به مدل متفاوت است — جزئیات در صفحه هر مدل.

پارامترتوضیح
modelشناسه provider/modelId
messagesتاریخچه مکالمه
temperatureخلاقیت پاسخ (0–2)
max_tokensحداکثر token خروجی
streamtrue برای پاسخ SSE chunk به chunk

نمونه non-stream

curl https://api.haftominhonar.ir/v1/chat/completions \
  -H "Authorization: Bearer aifo_sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5-mini",
    "messages": [{"role": "user", "content": "سلام! یک جمله درباره AiFO بنویس."}]
  }'
import requests

response = requests.post(
    "https://api.haftominhonar.ir/v1/chat/completions",
    headers={"Authorization": "Bearer aifo_sk_live_YOUR_API_KEY"},
    json={
        "model": "openai/gpt-5-mini",
        "messages": [{"role": "user", "content": "سلام! یک جمله درباره AiFO بنویس."}],
    },
)
print(response.json()["choices"][0]["message"]["content"])
const response = await fetch("https://api.haftominhonar.ir/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer aifo_sk_live_YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "openai/gpt-5-mini",
    messages: [{ role: "user", content: "سلام! یک جمله درباره AiFO بنویس." }],
  }),
});
const data = await response.json();
console.log(data.choices[0].message.content);
const OpenAI = require("openai");

const client = new OpenAI({
  baseURL: "https://api.haftominhonar.ir/v1",
  apiKey: "aifo_sk_live_YOUR_API_KEY",
});

async function main() {
  const completion = await client.chat.completions.create({
    model: "openai/gpt-5-mini",
    messages: [{ role: "user", content: "سلام! یک جمله درباره AiFO بنویس." }],
  });
  console.log(completion.choices[0].message.content);
}

main();

Streaming (SSE)

با stream: true پاسخ به صورت Server-Sent Events ارسال می‌شود. هر chunk شامل delta محتوا در choices[0].delta.content است. خط آخر data: [DONE] است.

curl https://api.haftominhonar.ir/v1/chat/completions \
  -H "Authorization: Bearer aifo_sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"openai/gpt-5-mini","stream":true,"messages":[{"role":"user","content":"سلام"}]}'

Vision (تصویر در پیام)

برای مدل‌های vision، content می‌تواند آرایه‌ای از partهای text و image_url باشد. URL باید publicly accessible باشد یا از base64 data URL استفاده کنید.

{
  "model": "openai/gpt-4o",
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "این تصویر چیست؟"},
      {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
    ]
  }]
}