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 L12
  • 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 Haiku 4 5 — included with a subscription — no pay-as-you-go price
  • Claude Haiku 4 5 20251001 — about ۱٬۱۸۳ تومان per typical message
  • Claude Opus 4 6 — included with a subscription — no pay-as-you-go price
  • Claude Opus 4 7 — included with a subscription — no pay-as-you-go price
  • Claude Opus 4 8 — included with a subscription — no pay-as-you-go price
  • Claude Opus 5 — about ۵٬۹۱۵ تومان per typical message
  • Claude Opus 5 5 — about ۴٬۷۳۲ تومان per typical message
  • Claude Sonnet 4 6 — about ۳٬۵۴۹ تومان per typical message
  • Claude Sonnet 5 — about ۲٬۳۶۶ تومان per typical message
  • Claude Sonnet 5 5 — about ۲٬۳۶۶ تومان per typical message
  • Clip Vit B 32
  • Deepseek V4 Flash — about ۶۷ تومان per typical message
  • E5 Base
  • E5 Large
  • Embed Multilingual V3
  • Gemini 2.5 Flash — about ۵۰۳ تومان per typical message
  • Gemini 2.5 Pro — about ۲٬۰۳۵ تومان per typical message
  • Gemini 3.1 Flash Lite — about ۳۳۵ تومان per typical message
  • Gemini 3.1 Pro — about ۲٬۶۶۲ تومان per typical message
  • Gemini 3.5 Flash — about ۱٬۹۹۶ تومان per typical message
  • Gemma 3 12B — about ۴۷ تومان per typical message
  • Gemma 3 12B It — about ۸۳ تومان per typical message
  • Gemma 3 27B — about ۶۱ تومان per typical message
  • Gemma 4 26B A4b — about ۸۲ تومان per typical message
  • Gemma 4 31B — about ۱۱۳ تومان per typical message
  • Gemma 4 31B Turbo — about ۹۰ تومان per typical message
  • Glm 4 7 — about ۵۹۱ تومان per typical message
  • Glm 4 7 Flash — about ۹۱ تومان per typical message
  • Glm 4.6 — about ۵۱۸ تومان per typical message
  • Glm 4.7 — about ۴۳۷ تومان per typical message
  • Glm 5 — about ۹۱۷ تومان per typical message
  • GPT Oss 120B — about ۴۲ تومان per typical message
  • GPT Oss 120B 1 0 — about ۱۵۷ تومان per typical message
  • GPT Oss 120B Turbo — about ۱۵۷ تومان per typical message
  • GPT Oss 120B Ultra — about ۲۳۰ تومان per typical message
  • Gte Base
  • Gte Large
  • Hermes 3 Llama 3.1 405B — about ۵۹۱ تومان per typical message
  • Hermes 3 Llama 3.1 70B — about ۴۱۴ تومان per typical message
  • Hy3 — about ۱۳۴ تومان per typical message
  • Inkling — about ۱٬۰۲۳ تومان per typical message
  • Kimi K2 5 — about ۸۵۱ تومان per typical message
  • Kimi K2 Thinking — about ۶۳۶ تومان per typical message
  • Kimi K2.6 — about ۸۵۲ تومان per typical message
  • Kimi K3 — about ۳٬۳۷۴ تومان per typical message
  • L3.1 70B Euryale V2.2 — about ۵۰۵ تومان per typical message
  • Ling 3.0 Flash — about ۵۵ تومان per typical message
  • Llama 3.1 70B Turbo — about ۲۳۷ تومان per typical message
  • Llama 3.3 70B Turbo — about ۹۱ تومان per typical message
  • Llama 4 Scout 17B 16E — about ۸۹ تومان per typical message
  • Llama Nemotron Embed Vl 1B
  • Llama3 70B Instruct — about ۲٬۰۳۲ تومان per typical message
  • Mistral Small 3.2 24B Instruct — about ۶۶ تومان per typical message
  • Multi Qa Mpnet Base Dot
  • Multilingual E5 Large
  • Muse Glimmer 30B — about ۳۱۱ تومان per typical message
  • Mythomax L2 13B — about ۲۳۷ تومان per typical message
  • Nemotron 3 Nano 30B A3b — about ۵۴ تومان per typical message
  • Nvidia Nemotron 3 Super 120B A12b — about ۱۰۰ تومان per typical message
  • Nvidia Nemotron 3.5 Lightning — about ۵۲ تومان per typical message
  • Paraphrase Minilm L6
  • Phi 4 — about ۵۲ تومان per typical message
  • Qwen2.5 72B — about ۲۲۰ تومان per typical message
  • Qwen3 14B — about ۸۸ تومان per typical message
  • Qwen3 235B A22b Instruct — about ۱۲۲ تومان per typical message
  • Qwen3 30B A3b — about ۱۲۶ تومان per typical message
  • Qwen3 32B — about ۱۵۷ تومان per typical message
  • Qwen3 Embedding 0.6B
  • Qwen3 Embedding 4B
  • Qwen3 Embedding 8B
  • Qwen3 Max — about ۱٬۴۱۹ تومان per typical message
  • Qwen3 Vl 30B A3b — about ۱۵۷ تومان per typical message
  • Qwen3.5 27B — about ۵۰۲ تومان per typical message
  • Qwen3.5 35B A3b — about ۲۰۸ تومان per typical message
  • Qwen3.5 397B A17b — about ۶۴۵ تومان per typical message
  • Qwen3.5 9B — about ۶۷ تومان per typical message
  • Qwen3.6 27B — about ۶۱۴ تومان per typical message
  • Qwen3.6 35B A3b — about ۱۸۶ تومان per typical message
  • Qwen3.7 Max — about ۲٬۲۱۸ تومان per typical message
  • Qwen3.8 2.4T A95b — about ۱٬۷۷۴ تومان per typical message
  • Qwen3.8 Max — about ۱٬۴۶۷ تومان per typical message
  • Seed 1.8 — about ۴۰۹ تومان per typical message
  • Seed 2.0 Code — about ۶۶۵ تومان per typical message
  • Seed 2.0 Mini — about ۱۰۴ تومان per typical message
  • Seed 2.0 Pro — about ۶۶۵ تومان 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/پروژه یه کلید جدا بسازی (تا ده‌تا کلید فعال، هر کدوم با اسم و سقف مصرف مخصوص خودش) — از «اتصال به ابزارها».