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

ParameterTypeRequiredMô tả
modelstringYesModel ID (ví dụ: ~openai/gpt-latest)
messagesarrayYesDanh sách messages
streambooleanNoBật streaming (SSE)
temperaturenumberNoSampling temperature (0-2)
max_tokensintegerNoSố token tối đa trong response
top_pnumberNoNucleus sampling
stopstring/arrayNoStop sequences
toolsarrayNoDanh sách tools cho function calling
response_formatobjectNoFormat 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}