AAPIHubapi gateway reseller

Tài liệu API

Một API key, hai gateway: OpenAI và Anthropic

APIHub cung cấp gateway non-streaming cho Chat Completions (OpenAI) và Messages (Anthropic). 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

OpenAI dùng Authorization: Bearer; Anthropic dùng x-api-key (Bearer cũng được chấp nhận). 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.dev
GET /v1/modelsPOST /v1/chat/completionsPOST /v1/messagesKhông hỗ trợ stream: true

OpenAI — Chat Completions

Endpoint POST /v1/chat/completions chỉ phục vụ model có endpoint type OpenAI. Response giữ định dạng OpenAI. Thay ah_live_REPLACE_WITH_YOUR_KEY bằng key tạo trong dashboard.

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
  }'

Anthropic — Messages

Endpoint POST /v1/messages chỉ phục vụ model có endpoint type Anthropic. Request và response giữ định dạng Anthropic Messages; usage đọc từ input_tokens / output_tokens.

  • • Gửi key bằng x-api-key hoặc Authorization: Bearer.
  • • Giữ header anthropic-version: 2023-06-01.
  • • Bắt buộc non-streaming: bỏ stream hoặc đặt stream: false.
  • • Có thể gửi Idempotency-Key để retry không bị trừ tiền hai lần.
curl -X POST "https://apihub-api.apihubvn.workers.dev/v1/messages" \
  -H "x-api-key: ah_live_REPLACE_WITH_YOUR_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-haiku",
    "max_tokens": 512,
    "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

HTTPCodeÝ nghĩa
400invalid_request / stream_not_supportedBody sai hoặc dùng streaming.
400model_not_supportedModel không hỗ trợ endpoint bạn đang gọi.
401missing_api_key / invalid_api_keyThiếu, sai hoặc key đã thu hồi.
402insufficient_balanceSố dư phải lớn hơn 0.
403account_bannedTài khoản đang bị khóa.
404model_not_foundModel không tồn tại hoặc đang tắt.
429rate_limit_exceededVượt giới hạn mỗi phút của key.
429daily_cost_limit_exceededVượt hạn mức chi phí trong ngày của key.
502upstream_errorUpstream lỗi; gateway không tự chuyển mock.