API Reference
Tài liệu tham chiếu đầy đủ cho tất cả các endpoint của AISieure API.
Tổng quan
AISieure API tương thích với cả hai định dạng OpenAI và Anthropic. Tất cả các endpoint yêu cầu xác thực bằng API key (trừ GET /v1/models).
Base URL:
https://aisieure.com
Xác thực:
Authorization: Bearer key_your_api_key_here
key_. Bạn có thể tạo key từ Dashboard.
| Method | Endpoint | Mô tả |
|---|---|---|
POST |
/v1/chat/completions |
Chat Completions (OpenAI format, streaming) |
POST |
/v1/messages |
Messages (Anthropic format, streaming) |
POST |
/v1/messages/count_tokens |
Đếm token cho messages |
POST |
/v1/embeddings |
Text Embeddings |
POST |
/v1/responses |
Responses API (Codex models) |
GET |
/v1/models |
Danh sách models |
GET |
/v1/balance |
Số dư credit và trạng thái key |
POST /v1/chat/completions
Tạo chat completion theo định dạng OpenAI. Hỗ trợ cả streaming và non-streaming.
Request Body
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
model |
string |
Có | Mã model (vd: claude-sonnet-4.6, gpt-4o) |
messages |
array |
Có | Danh sách messages với role và content |
max_tokens |
integer |
Không | Số token tối đa cho output (tự động điều chỉnh nếu không truyền) |
stream |
boolean |
Không | Bật streaming SSE (true/false) |
temperature |
number |
Không | Điều chỉnh độ ngẫu nhiên (0-2) |
top_p |
number |
Không | Nucleus sampling (0-1) |
tools |
array |
Không | Danh sách tool/function definitions |
tool_choice |
string|object |
Không | Chiến lược chọn tool (auto, none, required) |
Ví dụ Request
curl https://aisieure.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer key_your_api_key_here" \
-d '{
"model": "claude-sonnet-4.6",
"messages": [
{"role": "system", "content": "Bạn là một trợ lý hữu ích."},
{"role": "user", "content": "Hello!"}
],
"max_tokens": 1024
}'
Response (non-streaming)
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1709000000,
"model": "claude-sonnet-4.6",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Xin chào! Tôi có thể giúp gì cho bạn?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 18,
"total_tokens": 43
}
}
Response (streaming)
Khi stream: true, phản hồi sẽ là Server-Sent Events:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Xin"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" chào!"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
POST /v1/messages
Tạo message theo định dạng Anthropic. Hỗ trợ cả streaming và non-streaming. Request sẽ được tự động dịch sang OpenAI format nội bộ.
Request Body
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
model |
string |
Có | Mã model Claude (vd: claude-sonnet-4-20250514) |
messages |
array |
Có | Danh sách messages theo Anthropic format (content blocks) |
max_tokens |
integer |
Có | Số token tối đa cho output |
system |
string|array |
Không | System prompt |
stream |
boolean |
Không | Bật streaming SSE |
temperature |
number |
Không | Độ ngẫu nhiên (0-1) |
tools |
array |
Không | Tool definitions theo Anthropic format |
tool_choice |
object |
Không | {"type": "auto"}, {"type": "any"}, hoặc {"type": "tool", "name": "..."} |
Ví dụ Request
curl https://aisieure.com/v1/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer key_your_api_key_here" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"system": "Bạn là một trợ lý hữu ích.",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'
Response (non-streaming)
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Xin chào! Tôi có thể giúp gì cho bạn?"
}
],
"model": "claude-sonnet-4-20250514",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 25,
"output_tokens": 18
}
}
Response (streaming)
Khi stream: true, phản hồi sẽ là chuỗi Anthropic SSE events:
event: message_start
data: {"type":"message_start","message":{"id":"msg_abc123","type":"message","role":"assistant","model":"claude-sonnet-4-20250514","usage":{"input_tokens":25,"output_tokens":0}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Xin chào!"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":18}}
event: message_stop
data: {"type":"message_stop"}
-20250514) sẽ được tự động strip nội bộ. Bạn có thể truyền với hoặc không có suffix.
POST /v1/messages/count_tokens
Đếm số input tokens cho một request theo Anthropic format. Hữu ích để ước lượng chi phí trước khi gửi request thực tế.
Request Body
Giống với POST /v1/messages — truyền cùng payload bạn sẽ gửi đến endpoint messages.
Ví dụ Request
curl https://aisieure.com/v1/messages/count_tokens \
-H "Content-Type: application/json" \
-H "Authorization: Bearer key_your_api_key_here" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello, how are you?"}
]
}'
Response
{
"input_tokens": 12
}
POST /v1/embeddings
Tạo vector embeddings cho văn bản. Sử dụng để tìm kiếm ngữ nghĩa, phân loại, và các tác vụ NLP khác.
Request Body
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
input |
string|array |
Có | Văn bản cần tạo embedding (một hoặc nhiều) |
model |
string |
Có | Mã model embedding |
Ví dụ Request
curl https://aisieure.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer key_your_api_key_here" \
-d '{
"model": "text-embedding-3-small",
"input": "AISieure là nền tảng AI giá rẻ"
}'
Response
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [0.0023064255, -0.009327292, ...],
"index": 0
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
POST /v1/responses
Tạo response qua Responses API — endpoint dành riêng cho các model Codex (vd: codex-mini). Hỗ trợ cả streaming và non-streaming.
Request Body
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
model |
string |
Có | Mã model (vd: codex-mini) |
input |
string|array |
Có | Prompt hoặc danh sách input items/messages |
instructions |
string |
Không | Hướng dẫn cho model (tương tự system prompt) |
max_output_tokens |
integer |
Không | Số token tối đa cho output (tự động nếu không truyền) |
stream |
boolean |
Không | Bật streaming SSE |
temperature |
number |
Không | Điều chỉnh độ ngẫu nhiên (0-2) |
tools |
array |
Không | Danh sách tool/function definitions |
reasoning |
object |
Không | Cấu hình reasoning: {"effort": "low"|"medium"|"high"} |
Ví dụ Request
curl https://aisieure.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer key_your_api_key_here" \
-d '{
"model": "codex-mini",
"input": "Viết hàm Python tính số Fibonacci",
"instructions": "Bạn là một trợ lý lập trình.",
"stream": true
}'
Response (non-streaming)
{
"id": "resp_abc123",
"object": "response",
"created_at": 1709000000,
"model": "codex-mini",
"output": [
{
"type": "message",
"id": "msg_001",
"role": "assistant",
"status": "completed",
"content": [
{
"type": "output_text",
"text": "def fibonacci(n):\n ..."
}
]
}
],
"status": "completed",
"usage": {
"input_tokens": 25,
"output_tokens": 42,
"total_tokens": 67
}
}
Response (streaming)
Khi stream: true, phản hồi là Server-Sent Events với các event types:
event: response.created
data: {"type":"response.created","response":{"id":"resp_abc123","status":"in_progress"}}
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"def "}
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"fibonacci(n):"}
event: response.completed
data: {"type":"response.completed","response":{"id":"resp_abc123","status":"completed","usage":{"input_tokens":25,"output_tokens":42,"total_tokens":67}}}
data: [DONE]
input_tokens/output_tokens thay vì prompt_tokens/completion_tokens như Chat Completions.
GET /v1/models
Trả về danh sách các model đang khả dụng. Endpoint này không yêu cầu xác thực.
Ví dụ Request
curl https://aisieure.com/v1/models
Response
{
"object": "list",
"data": [
{
"id": "claude-sonnet-4.6",
"object": "model",
"created": 0,
"owned_by": "anthropic",
"display_name": "Claude Sonnet 4.6",
"context_window": 128000,
"max_output_tokens": 16384
},
{
"id": "gpt-4o",
"object": "model",
"created": 0,
"owned_by": "openai",
"display_name": "GPT-4o",
"context_window": 128000,
"max_output_tokens": 16384
}
],
"has_more": false
}
GET /v1/balance
Kiểm tra số dư credit, trạng thái API key và thông tin gói sử dụng.
Query Parameters
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
model |
string |
Không | Model ID để lấy giới hạn context/output cụ thể |
Ví dụ Request
curl https://aisieure.com/v1/balance \
-H "Authorization: Bearer key_your_api_key_here"
Response
{
"object": "balance",
"key_name": "My API Key",
"status": "active",
"package_type": "monthly",
"total_credits": 100000,
"remaining_credits": 85000,
"used_credits": 15000,
"daily_credits": null,
"cycle_started_at": "2026-02-01T00:00:00.000Z",
"expires_at": "2026-03-01T00:00:00.000Z",
"last_daily_reset_at": null,
"total_requests": 142,
"last_used_at": "2026-02-25T10:30:00.000Z"
}
total_credits, remaining_credits, used_credits sẽ trả về null.
Thêm query param model để lấy giới hạn cụ thể:
curl "https://aisieure.com/v1/balance?model=claude-sonnet-4.6" \
-H "Authorization: Bearer key_your_api_key_here"
Response sẽ có thêm trường:
{
...
"model_limits": {
"max_context_tokens": 128000,
"max_output_tokens": 16384
}
}
Xử lý lỗi
API trả về lỗi theo format chuẩn với HTTP status code tương ứng:
| Status | Ý nghĩa | Nguyên nhân thường gặp |
|---|---|---|
400 |
Bad Request | Request body không hợp lệ, thiếu tham số bắt buộc |
401 |
Unauthorized | API key không hợp lệ hoặc thiếu |
402 |
Payment Required | Hết credit hoặc gói đã hết hạn |
404 |
Not Found | Model không tồn tại hoặc chưa được kích hoạt |
429 |
Too Many Requests | Vượt quá rate limit |
500 |
Internal Error | Lỗi server nội bộ |
Error Response Format
{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"code": 401
}
}
429, hãy chờ vài giây rồi thử lại. Nếu server được cấu hình RATE_LIMIT_WAIT=true, request sẽ tự động chờ thay vì trả lỗi.
Compatibility Aliases
Ngoài prefix /v1/, API cũng hỗ trợ các alias không có prefix để tương thích với một số client:
| Alias | Tương đương |
|---|---|
/chat/completions |
/v1/chat/completions |
/embeddings |
/v1/embeddings |
/responses |
/v1/responses |
/models |
/v1/models |
/v1/ cho tất cả các request để đảm bảo tương thích trong tương lai.