Tài liệu API
API tương thích chuẩn OpenAI Chat Completions. Mọi thư viện OpenAI đều dùng được.
Base URL
https://api.npgsoftwave.com/v1
Bắt đầu nhanh
- 1. Tạo tài khoản và nạp tiền.
- 2. Tạo API key trong trang API key.
- 3. Gọi API bằng đoạn code bên dưới.
from openai import OpenAI
client = OpenAI(
base_url="https://api.npgsoftwave.com/v1",
api_key="sk-...",
)
resp = client.chat.completions.create(
model="claude-sonnet-4.6",
messages=[{"role": "user", "content": "Xin chào"}],
)
print(resp.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.npgsoftwave.com/v1',
apiKey: 'sk-...',
});
const resp = await client.chat.completions.create({
model: 'claude-sonnet-4.6',
messages: [{ role: 'user', content: 'Xin chào' }],
});
console.log(resp.choices[0].message.content);
$resp = Http::withToken('sk-...')
->post('https://api.npgsoftwave.com/v1/chat/completions', [
'model' => 'claude-sonnet-4.6',
'messages' => [['role' => 'user', 'content' => 'Xin chào']],
]);
echo $resp->json('choices.0.message.content');
curl https://api.npgsoftwave.com/v1/chat/completions \
-H "Authorization: Bearer sk-..." \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4.6",
"messages": [{"role": "user", "content": "Xin chào"}]
}'
Xác thực
Gửi API key trong header Authorization. Key chỉ hiện một lần khi tạo; nếu lộ key, hãy thu hồi và tạo key mới ngay.
Authorization: Bearer sk-...
Endpoint
GET
/v1/models
Danh sách model đang bán
POST
/v1/chat/completions
Tạo câu trả lời từ hội thoại
Streaming
Thêm "stream": true để nhận câu trả lời từng phần qua Server-Sent Events. Chi phí vẫn tính theo số token thực dùng, kể cả khi bạn ngắt kết nối giữa chừng.
data: {"choices":[{"delta":{"content":"Xin"}}],"model":"claude-sonnet-4.6"}
data: {"choices":[{"delta":{"content":" chào"}}],"model":"claude-sonnet-4.6"}
data: [DONE]
Tham số hỗ trợ
Các tham số khác ngoài danh sách dưới đây sẽ bị bỏ qua.
model
messages
stream
max_tokens
max_completion_tokens
temperature
top_p
stop
presence_penalty
frequency_penalty
tools
tool_choice
parallel_tool_calls
response_format
seed
reasoning_effort
max_tokens có mức trần riêng theo từng model; nếu không gửi, hệ thống dùng mức trần đó.
Mã lỗi
| HTTP | Mã | Ý nghĩa |
|---|---|---|
| 400 | invalid_request | Body không hợp lệ hoặc model từ chối request |
| 401 | invalid_api_key | API key sai hoặc đã bị thu hồi |
| 402 | insufficient_balance | Số dư không đủ cho request này |
| 403 | account_suspended | Tài khoản đang bị tạm khoá |
| 404 | model_not_found | Model không tồn tại hoặc đã tắt |
| 413 | request_too_large | Body vượt quá giới hạn cho phép |
| 429 | rate_limit_exceeded | Vượt giới hạn request/phút hoặc số request đồng thời |
| 502 | upstream_error | Model tạm thời không phản hồi, hãy thử lại |
Bảng giá
| Model | Input / 1 triệu token | Output / 1 triệu token | Ước tính 1 lượt hỏi đáp* |
|---|---|---|---|
| claude-sonnet-4.6 | 80.000đ | 400.000đ | ~280đ |
| gemini-3.8-flash | 10.000đ | 60.000đ | ~40đ |
* Ước tính cho 1.000 token vào và 500 token ra. Bạn chỉ trả theo số token thực dùng.