Contract ngắn gọn
Model ID không được hard-code từ danh sách tĩnh. Gọi GET /v1/models bằng key của user để lấy danh sách đã lọc theo subscription, plan, permission, capability và route đang sẵn sàng.
Bearer key
Header Authorization duy nhất.
Quota-aware
Rate và quota theo subscription.
Bounded SSE
Delta tăng dần, kết thúc bằng [DONE].
Xác thực
Authorization: Bearer YOUR_API_KEYFull API key chỉ xuất hiện khi create hoặc rotate. Danh sách key sau đó chỉ trả prefix đã mask; không có endpoint đọc lại secret.
Endpoints
/v1/chat/completionsTạo chat completion tương thích với OpenAI.
/v1/comboBáo giá, gọi song song và tổng hợp một yêu cầu qua nhiều model.
/v1/modelsLiệt kê các model mà API key hiện tại có quyền sử dụng.
/v1/models/:modelLấy thông tin một model mà API key hiện tại có quyền sử dụng.
/v1/embeddingsTạo vector embedding từ văn bản đầu vào.
/v1/messagesTạo message theo đặc tả tương thích với Anthropic.
/v1/completionsTạo text completion theo đặc tả cũ.
/v1/images/generationsSinh ảnh từ lời nhắc văn bản.
/v1/images/editsChỉnh sửa ảnh từ ảnh đầu vào và lời nhắc.
/v1/audio/speechSinh âm thanh giọng nói từ văn bản.
/v1/audio/transcriptionsChuyển âm thanh thành văn bản.
/v1/audio/translationsDịch nội dung âm thanh sang văn bản tiếng Anh.
/v1/rerankXếp hạng lại tài liệu theo mức độ phù hợp với truy vấn.
/v1/moderationsPhân loại nội dung đầu vào có nguy cơ không an toàn.
/v1beta/modelsLiệt kê model qua đặc tả tương thích với Gemini.
/v1beta/models/*pathTạo nội dung qua đặc tả tương thích với Gemini.
/v1/responsesTạo response theo đặc tả OpenAI Responses.
/v1/responses/compactRút gọn ngữ cảnh hội thoại của Responses.
Code explorer
Chuyển endpoint, chế độ stream và client; code luôn dùng environment variable.
POST /v1/chat/completionscurl https://api.xpncore.com/v1/chat/completions \
-H 'Authorization: Bearer $XPNCORE_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Hello"}]}'Thử trực tiếp
Trình duyệt gọi thẳng gateway; secret chỉ nằm trong bộ nhớ của tab này.
Response sẽ xuất hiện tại đây.Response và lỗi
200
OpenAI-compatible JSON với choices, usage và model.
200 SSE
Mỗi data event mang choices[].delta.content; marker [DONE] xác nhận hoàn tất.
4xx / 5xx
Envelope lỗi có message rõ cho auth, scope, quota, validation hoặc upstream.
{
"id": "chatcmpl_...",
"object": "chat.completion",
"model": "provider/model",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "Hello" },
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 12, "completion_tokens": 4, "total_tokens": 16 }
}data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hel"}}]}
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"lo"}}]}
data: [DONE]Nếu stream phát error hoặc kết nối ngắt sau khi đã có delta, hãy giữ phần output đã nhận và không tự động retry: request mới có thể tạo nội dung trùng lặp.
Giới hạn và vận hành
Sẵn sàng gửi request?
Setup Wizard tạo key và cấu hình; Playground gọi trực tiếp gateway với giới hạn phía client.