
Hướng dẫn nhanh CrazyRouter API
Chào mừng bạn sử dụng Crazyrouter! Hướng dẫn này sẽ giúp bạn hoàn thành việc tích hợp API trong 5 phút và bắt đầu sử dụng các mô hình AI hàng đầu thế giới.
Tại sao chọn Crazyrouter?#
- Giao diện thống nhất: Một API Key truy cập hơn 300+ mô hình AI
- Tương thích OpenAI: Không cần sửa mã, chỉ cần thay
base_urllà dùng được - Giá thấp hơn: Ưu đãi hơn giá chính thức, trả theo mức dùng, không cần đăng ký gói
- Tính sẵn sàng cao: Định tuyến thông minh, tự động chuyển đổi khi gặp sự cố
1. Lấy API Key#
- Truy cập Trang chủ Crazyrouter
- Đăng ký tài khoản và đăng nhập bảng điều khiển
- Vào trang "Quản lý token"
- Nhấp "Tạo token"
- Sao chép API Key được tạo (bắt đầu bằng
sk-)
Gợi ý: Hãy giữ kín API Key của bạn, không để lộ ở nơi công khai.
2. Gửi yêu cầu đầu tiên#
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, how are you?"}],
"temperature": 0.7
}'
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": "Hello, how are you?"}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
Dùng Node.js#
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://crazyrouter.com/v1'
});
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: 'Hello,Please introduce yourself' }
],
temperature: 0.7
});
console.log(response.choices[0].message.content);
}
main();
Xuất kết quả dạng 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 poem about spring"}],
stream=True
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
3. Các mô hình được hỗ trợ#
Crazyrouter hỗ trợ hơn 300+ mô hình AI, dưới đây là một số mô hình phổ biến:
| 厂商 | 模型示例 | 特点 |
|---|---|---|
| OpenAI | gpt-5.2, gpt-5, gpt-4o, o3-pro, o3-mini | 综合能力强,支持多模态 |
| Anthropic | claude-opus-4.5, claude-4, claude-sonnet-4 | 长上下文,代码能力强 |
| gemini-3.0-pro, gemini-3-flash, gemini-2.5-pro | 多模态,推理能力强 | |
| xAI | grok-3, grok-3-mini, grok-3-vision | 实时信息,深度搜索 |
| DeepSeek | deepseek-r1, deepseek-v3 | 性价比高,中文优秀 |
Xem danh sách mô hình đầy đủ: 模型广场
4. Giải thích các tham số thường dùng#
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | Tên mô hình, ví dụ gpt-5.2 |
messages | array | Danh sách tin nhắn hội thoại |
temperature | number | Mức độ ngẫu nhiên, 0-2, mặc định 1 |
max_tokens | integer | Số lượng token đầu ra tối đa |
stream | boolean | Có dùng xuất kết quả dạng streaming hay không |
top_p | number | Tham số nucleus sampling, 0-1 |
5. Xử lý lỗi#
from openai import OpenAI, APIError, RateLimitError
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"
}
)
try:
response = client.chat.completions.create(
model="gpt-5.2",
messages=[{"role": "user", "content": "Hello!"}]
)
except RateLimitError:
print("请求过于频繁,请稍后重试")
except APIError as e:
print(f"API 错误: {e}")
6. Bước tiếp theo#
- Xem 模型定价 để biết giá của từng mô hình
- Truy cập 控制台 để quản lý tài khoản của bạn
- Đọc API 文档 để tìm hiểu thêm các tính năng
- Tham gia Discord 社区 để nhận hỗ trợ
-20260122082015-vi-0aa29b.webp)

-vi-e1e75c.webp)