Login
Back to Blog
Cách truy cập GPT-5 và GPT-5.2 qua API - Hướng dẫn đầy đủ cho nhà phát triển

Cách truy cập GPT-5 và GPT-5.2 qua API - Hướng dẫn đầy đủ cho nhà phát triển

C
Crazyrouter Team
January 23, 2026
19 viewsTiếng ViệtTutorial
Share:

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:

ModelInput ($/1M tokens)Output ($/1M tokens)Best For
gpt-5.2$1.75$14.00Flagship mới nhất, tác vụ phức tạp
gpt-5.2-pro$3.50$28.00Nâng cao khả năng suy luận
gpt-5$1.25$10.00Tác vụ tổng quát
gpt-5-pro$2.50$20.00Phân tích nâng cao
gpt-5-mini$0.25$2.00Tiết kiệm chi phí
gpt-5-nano$0.05$0.40Tác vụ khối lượng lớn
o3-pro$20.00$80.00Suy luận phức tạp
o3-mini$1.10$4.40Suy luận hiệu quả
o4-mini$1.10$4.40Model suy luận mới nhất

Bắt đầu nhanh#

1. Lấy API Key#

  1. Truy cập Crazyrouter Console
  2. Điều hướng đến "Token Management"
  3. Nhấp "Create Token"
  4. 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ị)#

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)

Sử dụng Node.js#

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

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, 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:

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 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:

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

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

  1. 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
  2. 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
  3. Sử dụng streaming: Để cải thiện trải nghiệm người dùng trong các ứng dụng chat
  4. 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#


Nếu có câu hỏi, hãy liên hệ support@crazyrouter.com

Related Articles