شروع سریع
در 2 دقیقه به API Aize متصل شوید
شروع سریع
Aize درخواست گفتوگو را با قالب سازگار با OpenAI میپذیرد. SDK خود را به https://api.aize.dev/v1 متصل کنید و نام دقیق مدل را از فهرست فعلی مدلها بردارید. حسابهای جهانی و ایران هر دو از همین نشانی پایه استفاده میکنند.
پیش از ارسال درخواست، وارد شوید و کلید API بسازید. ساخت کلید در حال حاضر دستکم ۵ دلار موجودی کیفپول میخواهد. نمونههای زیر از GLM 5.3 Flash استفاده میکنند؛ این مدل در فهرست درگاه و مجموعهٔ پیشفرض مدلهای API است.
احراز هویت
همه درخواستهای API نیاز به احراز هویت با استفاده از کلید API شما دارند.
Authorization: Bearer YOUR_API_KEY
Content-Type: application/jsonاستفاده از SDK رسمی OpenAI
سادهترین راه برای یکپارچهسازی، استفاده از SDKهای رسمی OpenAI است.
Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.aize.dev/v1"
)
response = client.chat.completions.create(
model="GLM 5.3 Flash",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! Can you help me?"}
]
)
print(response.choices[0].message.content)TypeScript / JavaScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.aize.dev/v1',
});
async function main() {
const response = await client.chat.completions.create({
model: 'GLM 5.3 Flash',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello! Can you help me?' }
]
});
console.log(response.choices[0].message.content);
}
main();استفاده مستقیم از API
میتوانید از درخواستهای خام HTTP برای تعامل با API استفاده کنید.
curl https://api.aize.dev/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "GLM 5.3 Flash",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello! Can you help me?"
}
]
}'پاسخهای استریم
ما از رویدادهای سمت سرور (SSE) برای استریم لحظهای پشتیبانی میکنیم.
استریم در Python
stream = client.chat.completions.create(
model="GLM 5.3 Flash",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")استریم با cURL
curl -N https://api.aize.dev/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "GLM 5.3 Flash",
"stream": true,
"messages": [{"role":"user","content":"Stream a 2-line poem"}]
}'استفاده پیشرفته
حالت JSON
مدل را مجبور کنید خروجی JSON معتبر تولید کند.
const completion = await client.chat.completions.create({
model: "GLM 5.3 Flash",
response_format: { type: "json_object" },
messages: [{ role: "user", content: "Give a todo list as JSON" }],
});فراخوانی تابع (Tools)
ابزارها و توابع خارجی را متصل کنید.
response = client.chat.completions.create(
model="GLM 5.3 Flash",
messages=[{"role": "user", "content": "What's the weather in SF?"}],
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {"location": {"type": "string"}}
}
}
}]
)
tool_calls = response.choices[0].message.tool_callsتحلیل تصویر (Vision)
تصاویر را با استفاده از مدلهای سازگار تحلیل کنید.
curl https://api.aize.dev/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "GLM 5.3 Flash",
"messages": [{
"role": "user",
"content": [
{"type":"text","text":"What is in this image?"},
{"type":"image_url","image_url":{"url":"https://example.com/cat.jpg"}}
]
}]
}'