This article hasn't been translated into this language yet; showing the Persian version.

Basic

وصل کردن هر SDK یا کتابخونه‌ی سازگار با OpenAI

الگوی کلی برای وصل‌کردن هر SDK یا کتابخونه‌ای که فرمت OpenAI رو می‌فهمه — پایتون، Node، یا هر زبون دیگه‌ای.

اگه api-quickstart رو با curl امتحان کردی و حالا می‌خوای همون کار رو از داخل کد پایتون، Node، یا هر SDK دیگه‌ای که با فرمت OpenAI کار می‌کنه انجام بدی — این مقاله برای توئه. تا آخرش، یه SDK رسمی سازگار با OpenAI رو مستقیم به بنفش وصل می‌کنی، بدون این‌که چیزی از خود SDK رو دستکاری کنی.

قاعده‌ی کلی

هر SDK که رسماً از OpenAI پشتیبانی می‌کنه، یه راه برای override کردن base_url (یا اسم مشابهش) داره. همون‌جا آدرس سرویس بنفش رو بذار، api_key رو هم کلید خودت بذار — همین. بقیه‌ی SDK دقیقاً همون‌طوری کار می‌کنه که با OpenAI کار می‌کرد.

هم آدرس و هم کلید رو از صفحه‌ی «اتصال به ابزارها» بگیر — همیشه از همون‌جا، هیچ‌وقت یه آدرس رو جایی هاردکد نکن؛ این آدرس بین محیط‌های مختلف فرق می‌کنه.

پایتون (SDK رسمی openai)

python
from openai import OpenAI

client = OpenAI(
    base_url="YOUR_SERVICE_URL",
    api_key="YOUR_API_KEY",
)

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "سلام، خودت رو معرفی کن"}],
)
print(response.choices[0].message.content)

Node / TypeScript (SDK رسمی openai)

ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "YOUR_SERVICE_URL",
  apiKey: "YOUR_API_KEY",
});

const response = await client.chat.completions.create({
  model: "YOUR_MODEL_ID",
  messages: [{ role: "user", content: "سلام، خودت رو معرفی کن" }],
});
console.log(response.choices[0].message.content);

YOUR_MODEL_ID رو با شناسه‌ی یکی از مدل‌های فعال عوض کن — «auto» که تو داکیومنت خودِ OpenAI دیده باشی، مخصوص چت خودِ بنفش تو مرورگره و اینجا کار نمی‌کنه. لیست زنده‌ی مدل‌های فعال:

  • All Minilm L6
  • All Mpnet Base
  • Bge Base En V1.5
  • Bge En Icl
  • Bge Large En V1.5
  • Bge M3
  • Bge M3 Multi
  • Claude Fable 5included with a subscription — no pay-as-you-go price
  • Claude Haiku 4 5included with a subscription — no pay-as-you-go price
  • Claude Opus 4 6included with a subscription — no pay-as-you-go price
  • Claude Opus 4 7included with a subscription — no pay-as-you-go price
  • Claude Opus 4 8included with a subscription — no pay-as-you-go price
  • Claude Opus 5included with a subscription — no pay-as-you-go price
  • Claude Sonnet 4 6included with a subscription — no pay-as-you-go price
  • Claude Sonnet 5included with a subscription — no pay-as-you-go price
  • Clip Vit B 32
  • Deepseekabout ۴٬۶۱۰ تومان per typical message
  • Deepseek V4 Flashabout ۴٬۶۱۰ تومان per typical message
  • Deepseek V4 Proabout ۴٬۶۱۰ تومان per typical message
  • E5 Base
  • E5 Large
  • Embed Multilingual V3
  • Gemini 2.5 Flashabout ۴٬۶۱۰ تومان per typical message
  • Gemini 2.5 Proabout ۴٬۶۱۰ تومان per typical message
  • Gemini 3.1 Flash Liteabout ۴٬۶۱۰ تومان per typical message
  • Gemini 3.1 Proabout ۴٬۶۱۰ تومان per typical message
  • Gemini 3.5 Flashabout ۴٬۶۱۰ تومان per typical message
  • Gemma 3 12Babout ۴٬۶۱۰ تومان per typical message
  • Gemma 3 12B Itabout ۴٬۶۱۰ تومان per typical message
  • Gemma 3 27Babout ۴٬۶۱۰ تومان per typical message
  • Gemma 3 4Babout ۴٬۶۱۰ تومان per typical message
  • Gemma 4 26B A4babout ۴٬۶۱۰ تومان per typical message
  • Gemma 4 31Babout ۴٬۶۱۰ تومان per typical message
  • Gemma 4 31B It Ultraabout ۴٬۶۱۰ تومان per typical message
  • Gemma 4 31B Turboabout ۴٬۶۱۰ تومان per typical message
  • Gemma 4 E4babout ۴٬۶۱۰ تومان per typical message
  • Glm 4 7about ۴٬۶۱۰ تومان per typical message
  • Glm 4 7 Flashabout ۴٬۶۱۰ تومان per typical message
  • Glm 4.6about ۴٬۶۱۰ تومان per typical message
  • Glm 4.7about ۴٬۶۱۰ تومان per typical message
  • Glm 5about ۴٬۶۱۰ تومان per typical message
  • GPT Oss 120Babout ۴٬۶۱۰ تومان per typical message
  • GPT Oss 120B 1 0about ۴٬۶۱۰ تومان per typical message
  • GPT Oss 120B Turboabout ۴٬۶۱۰ تومان per typical message
  • GPT Oss 120B Ultraabout ۴٬۶۱۰ تومان per typical message
  • GPT Oss 20Babout ۴٬۶۱۰ تومان per typical message
  • Gte Base
  • Gte Large
  • Hermes 3 Llama 3.1 405Babout ۴٬۶۱۰ تومان per typical message
  • Hermes 3 Llama 3.1 70Babout ۴٬۶۱۰ تومان per typical message
  • Hy3about ۴٬۶۱۰ تومان per typical message
  • Inklingabout ۴٬۶۱۰ تومان per typical message
  • Kimi K2 5about ۴٬۶۱۰ تومان per typical message
  • Kimi K2 Thinkingabout ۴٬۶۱۰ تومان per typical message
  • Kimi K2.5about ۴٬۶۱۰ تومان per typical message
  • Kimi K2.6about ۴٬۶۱۰ تومان per typical message
  • Kimi K2.7 Codeabout ۴٬۶۱۰ تومان per typical message
  • Kimi K3about ۶٬۹۱۵ تومان per typical message
  • L3 8B Lunaris Turboabout ۴٬۶۱۰ تومان per typical message
  • L3.1 70B Euryale V2.2about ۴٬۶۱۰ تومان per typical message
  • Ling 3.0 Flashabout ۴٬۶۱۰ تومان per typical message
  • Llama 3.1 70B Turboabout ۴٬۶۱۰ تومان per typical message
  • Llama 3.1 8B Turboabout ۴٬۶۱۰ تومان per typical message
  • Llama 3.3 70B Turboabout ۴٬۶۱۰ تومان per typical message
  • Llama 4 Maverick 17B 128E Fp8about ۴٬۶۱۰ تومان per typical message
  • Llama 4 Scout 17B 16Eabout ۴٬۶۱۰ تومان per typical message
  • Llama Nemotron Embed Vl 1B
  • Llama3 70B Instructabout ۴٬۶۱۰ تومان per typical message
  • Mimo V2.5about ۴٬۶۱۰ تومان per typical message
  • Minimax M2.7 Turboabout ۴٬۶۱۰ تومان per typical message
  • Minimax M3about ۴٬۶۱۰ تومان per typical message
  • Mistral Nemo Instructabout ۴٬۶۱۰ تومان per typical message
  • Mistral Small 24B Instructabout ۴٬۶۱۰ تومان per typical message
  • Mistral Small 3.2 24B Instructabout ۴٬۶۱۰ تومان per typical message
  • Multi Qa Mpnet Base Dot
  • Multilingual E5 Large
  • Muse Glimmer 30Babout ۴٬۶۱۰ تومان per typical message
  • Mythomax L2 13Babout ۴٬۶۱۰ تومان per typical message
  • Nemotron 3 Nano 30B A3babout ۴٬۶۱۰ تومان per typical message
  • Nova Microabout ۴٬۶۱۰ تومان per typical message
  • Nova Proabout ۴٬۶۱۰ تومان per typical message
  • Nvidia Nemotron 3 Super 120B A12babout ۴٬۶۱۰ تومان per typical message
  • Nvidia Nemotron 3 Ultra 550B A55babout ۴٬۶۱۰ تومان per typical message
  • Nvidia Nemotron 3.5 Lightningabout ۴٬۶۱۰ تومان per typical message
  • Paraphrase Minilm L6
  • Phi 4about ۴٬۶۱۰ تومان per typical message
  • Qwen2.5 72Babout ۴٬۶۱۰ تومان per typical message
  • Qwen3 14Babout ۴٬۶۱۰ تومان per typical message
  • Qwen3 235B A22b Instructabout ۴٬۶۱۰ تومان per typical message
  • Qwen3 235B A22b Thinkingabout ۴٬۶۱۰ تومان per typical message
  • Qwen3 30B A3babout ۴٬۶۱۰ تومان per typical message
  • Qwen3 32Babout ۴٬۶۱۰ تومان per typical message
  • Qwen3 Coder 480B A35b Turboabout ۴٬۶۱۰ تومان per typical message
  • Qwen3 Embedding 0.6B
  • Qwen3 Embedding 4B
  • Qwen3 Maxabout ۴٬۶۱۰ تومان per typical message
  • Qwen3 Max Thinkingabout ۴٬۶۱۰ تومان per typical message
  • Qwen3 Vl 30B A3babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.5 122B A10babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.5 27Babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.5 35B A3babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.5 397B A17babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.5 9Babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.6 27Babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.6 35B A3babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.7 Maxabout ۴٬۶۱۰ تومان per typical message
  • Qwen3.8 2.4T A95babout ۴٬۶۱۰ تومان per typical message
  • Qwen3.8 Maxabout ۴٬۶۱۰ تومان per typical message
  • Seed 1.8about ۴٬۶۱۰ تومان per typical message
  • Seed 2.0 Codeabout ۴٬۶۱۰ تومان per typical message
  • Seed 2.0 Miniabout ۴٬۶۱۰ تومان per typical message
  • Seed 2.0 Proabout ۴٬۶۱۰ تومان per typical message
  • Step 3.7 Flashabout ۴٬۶۱۰ تومان per typical message
  • Text2vec Base Chinese
  • Titan Embed Text V2

⚠️ این دو نمونه هنوز مستقیم روی SDKهای واقعی اجرا و تست نشدن. ساختارشون دقیقاً همون override استانداردیه که این SDKها مستند کردن، ولی قبل از قراردادنشون تو کد production خودت، یه بار محلی امتحانشون کن. اگه جواب نگرفتی، «رفع اشکال اتصال» رو ببین.

نکته برای هر SDK دیگه

اگه از یه زبون یا کتابخونه‌ی دیگه استفاده می‌کنی که مستقیماً از OpenAI پشتیبانی نمی‌کنه ولی می‌گه «سازگار با OpenAI»، دنبال یکی از این دو الگو بگرد:

  • یه پارامتر صریح مثل base_url / baseURL / endpoint موقع ساختن کلاینت.
  • یه متغیر محیطی مثل OPENAI_BASE_URL که SDK خودش می‌خونه.

اگه هیچ‌کدوم رو نداره — یعنی آدرس OpenAI رو تو خودِ کتابخونه هاردکد کرده — نمی‌تونی وصلش کنی.

چی کار نمی‌کنه

  • SDKهای رسمی provider‌های دیگه (مثلاً SDK رسمی Anthropic) کار نمی‌کنن — اون‌ها فرمت درخواست/پاسخ متفاوتی دارن که بنفش امروز پیاده نکرده.
  • این مسیر (SDK مستقیم به gateway) هم به کیف پولت گیت شده — با یه سقف روی gateway، نه چک لحظه‌ای مثل چت. جزئیاتش تو «کنترل مصرف و هزینه» هست.
  • می‌تونی برای این SDK/پروژه یه کلید جدا بسازی (تا ده‌تا کلید فعال، هر کدوم با اسم و سقف مصرف مخصوص خودش) — از «اتصال به ابزارها».