
วิธีเข้าถึง GPT-5 และ GPT-5.2 ผ่าน API - คู่มือฉบับสมบูรณ์สำหรับนักพัฒนา
OpenAI ได้เปิดตัวโมเดลที่ทรงพลังที่สุดในปัจจุบัน: GPT-5, GPT-5.2 และ o3-pro ที่เน้นด้านการให้เหตุผล คู่มือนี้จะแสดงวิธีเข้าถึงโมเดลล้ำสมัยเหล่านี้ผ่าน Crazyrouter ซึ่งให้บริการ API แบบ unified
โมเดล OpenAI ที่รองรับ#
Crazyrouter ให้คุณเข้าถึงโมเดลทั้งหมดในไลน์ผลิตภัณฑ์ของ OpenAI:
| Model | Input ($/1M tokens) | Output ($/1M tokens) | Best For |
|---|---|---|---|
| gpt-5.2 | $1.75 | $14.00 | รุ่นเรือธงล่าสุด เหมาะกับงานซับซ้อน |
| gpt-5.2-pro | $3.50 | $28.00 | การให้เหตุผลขั้นสูง |
| gpt-5 | $1.25 | $10.00 | งานทั่วไป |
| gpt-5-pro | $2.50 | $20.00 | การวิเคราะห์ขั้นสูง |
| gpt-5-mini | $0.25 | $2.00 | คุ้มค่า ประหยัดต้นทุน |
| gpt-5-nano | $0.05 | $0.40 | งานปริมาณมาก |
| o3-pro | $20.00 | $80.00 | การให้เหตุผลที่ซับซ้อน |
| o3-mini | $1.10 | $4.40 | การให้เหตุผลที่มีประสิทธิภาพ |
| o4-mini | $1.10 | $4.40 | โมเดล reasoning รุ่นล่าสุด |
เริ่มต้นอย่างรวดเร็ว#
1. รับ API Key ของคุณ#
- ไปที่ Crazyrouter Console
- ไปที่เมนู "Token Management"
- คลิก "Create Token"
- คัดลอก API key ของคุณ (ขึ้นต้นด้วย
sk-)
2. ส่งคำร้องขอครั้งแรกของคุณ#
ใช้ Python (แนะนำ)#
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://crazyrouter.com/v1",
default_headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}
)
response = client.chat.completions.create(
model="gpt-5.2",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
ใช้ Node.js#
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://crazyrouter.com/v1',
defaultHeaders: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
});
async function main() {
const response = await client.chat.completions.create({
model: 'gpt-5.2',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain quantum computing in simple terms.' }
],
temperature: 0.7
});
console.log(response.choices[0].message.content);
}
main();
ใช้ curl#
curl https://crazyrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
-d '{
"model": "gpt-5.2",
"messages": [{"role": "user", "content": "Hello, GPT-5.2!"}],
"temperature": 0.7
}'
การรับคำตอบแบบสตรีมมิ่ง#
หากต้องการเอาต์พุตแบบเรียลไทม์ ให้เปิดใช้งานโหมด streaming:
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://crazyrouter.com/v1",
default_headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}
)
stream = client.chat.completions.create(
model="gpt-5.2",
messages=[{"role": "user", "content": "Write a short story about AI."}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
การใช้โมเดล Reasoning (o3-pro)#
โมเดล o3-pro เหมาะอย่างยิ่งสำหรับงานที่ต้องใช้การให้เหตุผลซับซ้อน:
response = client.chat.completions.create(
model="o3-pro",
messages=[
{"role": "user", "content": "Solve this step by step: If a train travels 120 miles in 2 hours, then stops for 30 minutes, then travels another 90 miles in 1.5 hours, what is the average speed for the entire journey including the stop?"}
]
)
print(response.choices[0].message.content)
โมเดล GPT-5 Codex#
สำหรับงานสร้างโค้ด ให้ใช้โมเดล codex แบบเฉพาะทาง:
response = client.chat.completions.create(
model="gpt-5-codex",
messages=[
{"role": "user", "content": "Write a Python function to implement binary search"}
]
)
เวอร์ชัน codex ที่มีให้ใช้: gpt-5-codex, gpt-5-codex-high, gpt-5-codex-medium, gpt-5-codex-low, gpt-5.2-codex
แนวทางปฏิบัติที่ดีที่สุด#
- เลือกโมเดลให้เหมาะสม: ใช้ gpt-5-nano สำหรับงานง่าย ๆ และใช้ gpt-5.2 สำหรับงานที่ซับซ้อน
- ตั้งค่า temperature ให้เหมาะกับงาน: ค่าต่ำ (0.1-0.3) เหมาะกับงานเชิงข้อเท็จจริง ค่าสูง (0.7-1.0) เหมาะกับงานเชิงสร้างสรรค์
- ใช้การสตรีม (streaming): เพื่อประสบการณ์ผู้ใช้ที่ดียิ่งขึ้นในแอปพลิเคชันแชท
- จัดการข้อผิดพลาดอย่างเหมาะสม: ใช้กลไก retry เมื่อเจอ rate limit
ขั้นตอนถัดไป#
- ดูหน้า Model Pricing เพื่อรายละเอียดค่าใช้จ่าย
- อ่าน API Documentation สำหรับฟีเจอร์ขั้นสูง
- เข้าร่วม Discord Community ของเราเพื่อรับการสนับสนุน
หากมีคำถาม ติดต่อได้ที่ support@crazyrouter.com


