Chat Completions
POST /v1/chat/completions
Tạo chat completion. Tương thích hoàn toàn với OpenAI Chat Completions API.
Request
$ curl https://api.staging.tram.ai.vn/v1/chat/completions \ > -H "Content-Type: application/json" \ > -H "Authorization: Bearer $TRAM_AI_API_KEY" \ > -d '{ > "model": "~openai/gpt-latest", > "messages": [ > {"role": "system", "content": "You are a helpful assistant."}, > {"role": "user", "content": "Hello!"} > ] > }'
Parameters
| Parameter | Type | Required | Mô tả |
|---|---|---|---|
model | string | Yes | Model ID (ví dụ: ~openai/gpt-latest) |
messages | array | Yes | Danh sách messages |
stream | boolean | No | Bật streaming (SSE) |
temperature | number | No | Sampling temperature (0-2) |
max_tokens | integer | No | Số token tối đa trong response |
top_p | number | No | Nucleus sampling |
stop | string/array | No | Stop sequences |
tools | array | No | Danh sách tools cho function calling |
response_format | object | No | Format response (JSON mode) |
Response
1 { 2 "id": "chatcmpl-...", 3 "object": "chat.completion", 4 "choices": [ 5 { 6 "index": 0, 7 "message": { 8 "role": "assistant", 9 "content": "Hello! How can I help you today?" 10 }, 11 "finish_reason": "stop" 12 } 13 ], 14 "usage": { 15 "prompt_tokens": 15, 16 "completion_tokens": 9, 17 "total_tokens": 24 18 } 19 }