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)
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)
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 5 — included with a subscription — no pay-as-you-go price
- Claude Haiku 4 5 — included with a subscription — no pay-as-you-go price
- 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 — included with a subscription — no pay-as-you-go price
- Claude Sonnet 4 6 — included with a subscription — no pay-as-you-go price
- Claude Sonnet 5 — included with a subscription — no pay-as-you-go price
- Clip Vit B 32
- Deepseek — about ۴٬۶۱۰ تومان per typical message
- Deepseek V4 Flash — about ۴٬۶۱۰ تومان per typical message
- Deepseek V4 Pro — 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 3 4B — about ۴٬۶۱۰ تومان per typical message
- Gemma 4 26B A4b — about ۴٬۶۱۰ تومان per typical message
- Gemma 4 31B — about ۴٬۶۱۰ تومان per typical message
- Gemma 4 31B It Ultra — about ۴٬۶۱۰ تومان per typical message
- Gemma 4 31B Turbo — about ۴٬۶۱۰ تومان per typical message
- Gemma 4 E4b — 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
- GPT Oss 20B — 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.5 — about ۴٬۶۱۰ تومان per typical message
- Kimi K2.6 — about ۴٬۶۱۰ تومان per typical message
- Kimi K2.7 Code — about ۴٬۶۱۰ تومان per typical message
- Kimi K3 — about ۶٬۹۱۵ تومان per typical message
- L3 8B Lunaris Turbo — 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.1 8B Turbo — about ۴٬۶۱۰ تومان per typical message
- Llama 3.3 70B Turbo — about ۴٬۶۱۰ تومان per typical message
- Llama 4 Maverick 17B 128E Fp8 — 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
- Mimo V2.5 — about ۴٬۶۱۰ تومان per typical message
- Minimax M2.7 Turbo — about ۴٬۶۱۰ تومان per typical message
- Minimax M3 — about ۴٬۶۱۰ تومان per typical message
- Mistral Nemo Instruct — about ۴٬۶۱۰ تومان per typical message
- Mistral Small 24B 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
- Nova Micro — about ۴٬۶۱۰ تومان per typical message
- Nova Pro — about ۴٬۶۱۰ تومان per typical message
- Nvidia Nemotron 3 Super 120B A12b — about ۴٬۶۱۰ تومان per typical message
- Nvidia Nemotron 3 Ultra 550B A55b — 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 235B A22b Thinking — about ۴٬۶۱۰ تومان per typical message
- Qwen3 30B A3b — about ۴٬۶۱۰ تومان per typical message
- Qwen3 32B — about ۴٬۶۱۰ تومان per typical message
- Qwen3 Coder 480B A35b Turbo — about ۴٬۶۱۰ تومان per typical message
- Qwen3 Embedding 0.6B
- Qwen3 Embedding 4B
- Qwen3 Max — about ۴٬۶۱۰ تومان per typical message
- Qwen3 Max Thinking — about ۴٬۶۱۰ تومان per typical message
- Qwen3 Vl 30B A3b — about ۴٬۶۱۰ تومان per typical message
- Qwen3.5 122B A10b — 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
- Step 3.7 Flash — 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/پروژه یه کلید جدا بسازی (تا دهتا کلید فعال، هر کدوم با اسم و سقف مصرف مخصوص خودش) — از «اتصال به ابزارها».