AiFO AiFO مستندات AiFO

Endpoint

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

POST https://api.aifoapp.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.aifoapp.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.aifoapp.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.aifoapp.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.aifoapp.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.aifoapp.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 و multimodal (تصویر و فایل)

برای مدل‌هایی که در پروفایل مؤثر (effective profile) ورودی تصویر/فایل دارند، content می‌تواند آرایه‌ای از partهای کنونیکال باشد: text، image_url، و در صورت پشتیبانی adapter/مدل: file. قابلیت واقعی = تقاطع modelProfile × adapter × سقف platform است — نه همهٔ مدل‌ها و نه همهٔ providerها. فیلد attachment_url وجود ندارد؛ استخراج متن/OCR هم انجام نمی‌شود.

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

برای فایل‌های قابل‌استفادهٔ مجدد، ابتدا با POST /v1/files آپلود کنید و در Chat فقط file_id متعلق به AiFO را بفرستید. این شناسه شناسهٔ OpenAI/OpenRouter نیست و هرگز به‌صورت خام به provider پاس داده نمی‌شود. OpenAI Chat همچنان فقط text + image_url را می‌پذیرد؛ مدل‌های OpenRouter با پشتیبانی file در پروفایل مؤثر می‌توانند از file_id استفاده کنند.

{
  "model": "google/gemini-2.5-flash-lite",
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "خلاصه این PDF را بگو"},
      {
        "type": "file",
        "file": {
          "file_id": "file_..."
        }
      }
    ]
  }]
}

نمونهٔ inline file_data (بدون آپلود قبلی) برای مدل/adapterهایی که از data URL پشتیبانی می‌کنند:

{
  "model": "google/gemini-2.5-pro",
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "خلاصه این PDF را بگو"},
      {
        "type": "file",
        "file": {
          "filename": "doc.pdf",
          "file_data": "data:application/pdf;base64,..."
        }
      }
    ]
  }]
}