Tài liệu API
Một API key, endpoint tương thích OpenAI
APIHub cung cấp gateway non-streaming cho chat completions. Tài liệu và danh sách model bên dưới lấy trực tiếp từ database; key trong ví dụ chỉ là placeholder.
Base URL
Mọi request gateway dùng Bearer API key. Không gửi key thật trong tài liệu hoặc mã nguồn công khai.
https://apihub-api.apihubvn.workers.devGET /v1/modelsPOST /v1/chat/completionsKhông hỗ trợ stream: true
Ví dụ curl
Thay ah_live_REPLACE_WITH_YOUR_KEY bằng key tạo trong dashboard. Không dùng key thật trong tài liệu.
curl -X POST "https://apihub-api.apihubvn.workers.dev/v1/chat/completions" \
-H "Authorization: Bearer ah_live_REPLACE_WITH_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model",
"messages": [
{"role": "user", "content": "Xin chào APIHub"}
],
"stream": false
}'Response mock và live
Mock mode
- • Nội dung có nhãn [MOCK].
- • Header
X-ApiHub-Mode: mock. - • Token ước lượng, lưu tokenSource ESTIMATED.
Live mode
- • Chuyển tiếp tới upstream bằng key server-side.
- • Header
X-ApiHub-Mode: live. - • Upstream lỗi trả 502, không fallback mock.
Danh sách model
Dùng đúng slug trong trường model. Giá chi tiết xem tại bảng giá.
Lỗi thường gặp
| HTTP | Code | Ý nghĩa |
|---|---|---|
| 400 | invalid_request / stream_not_supported | Body sai hoặc dùng streaming. |
| 401 | missing_api_key / invalid_api_key | Thiếu, sai hoặc key đã thu hồi. |
| 402 | insufficient_balance | Số dư phải lớn hơn 0. |
| 403 | account_banned | Tài khoản đang bị khóa. |
| 404 | model_not_found | Model không tồn tại hoặc đang tắt. |
| 429 | rate_limit_exceeded | Vượt giới hạn mỗi phút của key. |
| 502 | upstream_error | Upstream lỗi; gateway không tự chuyển mock. |