Login
Back to Blog
Hướng dẫn nhanh CrazyRouter API

Hướng dẫn nhanh CrazyRouter API

C
Crazyrouter Team
January 22, 2026
10 viewsTiếng Việt
Share:

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_url là 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#

  1. Truy cập Trang chủ Crazyrouter
  2. Đăng ký tài khoản và đăng nhập bảng điều khiển
  3. Vào trang "Quản lý token"
  4. Nhấp "Tạo token"
  5. 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#

bash
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ị)#

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": "Hello, how are you?"}
    ],
    temperature=0.7,
    max_tokens=1000
)

print(response.choices[0].message.content)

Dùng Node.js#

javascript
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#

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"
    }
)

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:

厂商模型示例特点
OpenAIgpt-5.2, gpt-5, gpt-4o, o3-pro, o3-mini综合能力强,支持多模态
Anthropicclaude-opus-4.5, claude-4, claude-sonnet-4长上下文,代码能力强
Googlegemini-3.0-pro, gemini-3-flash, gemini-2.5-pro多模态,推理能力强
xAIgrok-3, grok-3-mini, grok-3-vision实时信息,深度搜索
DeepSeekdeepseek-r1, deepseek-v3性价比高,中文优秀

Xem danh sách mô hình đầy đủ: 模型广场

4. Giải thích các tham số thường dùng#

参数类型说明
modelstringTên mô hình, ví dụ gpt-5.2
messagesarrayDanh sách tin nhắn hội thoại
temperaturenumberMức độ ngẫu nhiên, 0-2, mặc định 1
max_tokensintegerSố lượng token đầu ra tối đa
streambooleanCó dùng xuất kết quả dạng streaming hay không
top_pnumberTham số nucleus sampling, 0-1

5. Xử lý lỗi#

python
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ợ

Related Articles