Chat Completions
Tạo phản hồi từ mô hình cho một cuộc hội thoại trên các mô hình OpenAI, Anthropic, Gemini, DeepSeek và Qwen bằng lược đồ OpenAI phổ quát.
POST
https://api.vanix.io/v1/chat/completionsYêu cầu được gửi trực tiếp từ trình duyệt tới https://api.vanix.io. Khóa chỉ lưu trong bộ nhớ phiên.
Nhập API Key Vanix AI và nhấn "Gửi yêu cầu" để gọi trực tiếp tới https://api.vanix.io.
Tham số thân yêu cầu (Request Body)
modelstringbắt buộc Mã mô hình đích trả về từ
GET /v1/models (ví dụ: gpt-4o, gpt-4o-mini, claude-sonnet-4-5, gemini-2.5-pro, deepseek-chat). messagesarray<object>bắt buộc Lịch sử hội thoại theo đúng thứ tự. Mỗi phần tử gồm
role (system, developer, user, assistant hoặc tool) và content dạng chuỗi hoặc mảng đa phương thức. streambooleantùy chọnmặc định: false Khi đặt
true, các token được trả về dần dưới dạng Server-Sent Events và kết thúc bằng data: [DONE]. stream_optionsobjecttùy chọn Truyền
{"include_usage": true} cùng với stream: true để nhận số liệu sử dụng token cuối cùng. temperaturenumbertùy chọnmặc định: 1.0 Độ ngẫu nhiên khi lấy mẫu trong khoảng
0.0 đến 2.0. Bỏ qua đối với các mô hình suy luận không chấp nhận tham số temperature. max_completion_tokensintegertùy chọn Số lượng token sinh tối đa (bao gồm cả token suy luận trên các mô hình suy luận). Tham số cũ
max_tokens vẫn được hỗ trợ cho các mô hình không suy luận. toolsarray<object>tùy chọn Danh sách lược đồ hàm/công cụ mà mô hình có thể gọi. Kết hợp cùng
tool_choice ("auto", "none", "required" hoặc chỉ định một hàm cụ thể). response_formatobjecttùy chọn Ràng buộc đầu ra phải là JSON hợp lệ qua
{"type": "json_object"} hoặc tuân thủ lược đồ nghiêm ngặt qua {"type": "json_schema", "json_schema": {...}}. reasoning_effortstringtùy chọn Độ sâu suy luận cho các mô hình được hỗ trợ:
"low", "medium" hoặc "high". Ví dụ mã nguồn
bash
curl https://api.vanix.io/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VANIX_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "Be concise."},
{"role": "user", "content": "Reply with OK"}
],
"max_completion_tokens": 32
}'python
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["VANIX_API_KEY"], base_url="https://api.vanix.io/v1")
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Reply with OK"}],
)
print(resp.choices[0].message.content)ts
import OpenAI from 'openai'
const client = new OpenAI({ apiKey: process.env.VANIX_API_KEY, baseURL: 'https://api.vanix.io/v1' })
const resp = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Reply with OK' }],
})
console.log(resp.choices[0].message.content)Ví dụ phản hồi (200 OK)
json
{
"id": "chatcmpl-9xK2mP",
"object": "chat.completion",
"created": 1764576000,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "OK" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 1,
"total_tokens": 13,
"prompt_tokens_details": { "cached_tokens": 0 }
}
}