Chat Completions
راهنمای کامل chat API
Endpoint
POST /v1/chat/completions — سازگار با OpenAI Chat Completions API. مدلهای CHAT، VISION و REASONING از این endpoint استفاده میکنند.
POST https://api.haftominhonar.ir/v1/chat/completionsSchema پیامها و پارامترها
آرایه messages شامل role (system, user, assistant) و content است. پارامترهای اختیاری بسته به مدل متفاوت است — جزئیات در صفحه هر مدل.
| پارامتر | توضیح |
|---|---|
model | شناسه provider/modelId |
messages | تاریخچه مکالمه |
temperature | خلاقیت پاسخ (0–2) |
max_tokens | حداکثر token خروجی |
stream | true برای پاسخ 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 بنویس."}]
}' 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"}}
]
}]
}