
Cách truy cập GPT-5 và GPT-5.2 qua API - Hướng dẫn đầy đủ cho nhà phát triển
OpenAI đã phát hành các model mạnh mẽ nhất từ trước đến nay: GPT-5, GPT-5.2 và o3-pro tập trung vào suy luận. Hướng dẫn này sẽ chỉ cho bạn cách truy cập những model tiên tiến này thông qua API hợp nhất của Crazyrouter.
Các model OpenAI được hỗ trợ#
Crazyrouter cung cấp quyền truy cập vào toàn bộ danh mục model của OpenAI:
| Model | Input ($/1M tokens) | Output ($/1M tokens) | Best For |
|---|---|---|---|
| gpt-5.2 | $1.75 | $14.00 | Flagship mới nhất, tác vụ phức tạp |
| gpt-5.2-pro | $3.50 | $28.00 | Nâng cao khả năng suy luận |
| gpt-5 | $1.25 | $10.00 | Tác vụ tổng quát |
| gpt-5-pro | $2.50 | $20.00 | Phân tích nâng cao |
| gpt-5-mini | $0.25 | $2.00 | Tiết kiệm chi phí |
| gpt-5-nano | $0.05 | $0.40 | Tác vụ khối lượng lớn |
| o3-pro | $20.00 | $80.00 | Suy luận phức tạp |
| o3-mini | $1.10 | $4.40 | Suy luận hiệu quả |
| o4-mini | $1.10 | $4.40 | Model suy luận mới nhất |
Bắt đầu nhanh#
1. Lấy API Key#
- Truy cập Crazyrouter Console
- Điều hướng đến "Token Management"
- Nhấp "Create Token"
- Sao chép API key của bạn (bắt đầu với
sk-)
2. Gửi request đầu tiên của bạn#
Sử dụng Python (Khuyến nghị)#
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)
Sử dụng 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();
Sử dụng 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 Responses#
Để nhận kết quả theo thời gian thực, hãy bật chế độ 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)
Sử dụng các model suy luận (o3-pro)#
Model o3-pro nổi bật trong các tác vụ suy luận phức tạp:
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)
Các model GPT-5 Codex#
Đối với các tác vụ sinh mã, hãy sử dụng các model codex chuyên biệt:
response = client.chat.completions.create(
model="gpt-5-codex",
messages=[
{"role": "user", "content": "Write a Python function to implement binary search"}
]
)
Các biến thể codex có sẵn: gpt-5-codex, gpt-5-codex-high, gpt-5-codex-medium, gpt-5-codex-low, gpt-5.2-codex
Thực hành tốt nhất#
- Chọn đúng model: Dùng gpt-5-nano cho các tác vụ đơn giản, gpt-5.2 cho các tác vụ phức tạp
- Thiết lập temperature phù hợp: Thấp (0.1-0.3) cho các tác vụ cần tính chính xác, cao (0.7-1.0) cho các tác vụ sáng tạo
- Sử dụng streaming: Để cải thiện trải nghiệm người dùng trong các ứng dụng chat
- Xử lý lỗi một cách hợp lý: Triển khai logic retry cho các giới hạn tần suất (rate limit)
Bước tiếp theo#
- Xem Model Pricing để biết chi phí chi tiết
- Đọc API Documentation cho các tính năng nâng cao
- Tham gia Discord Community của chúng tôi để được hỗ trợ
Nếu có câu hỏi, hãy liên hệ support@crazyrouter.com


