# Định dạng ChatCompletions

Nguồn: https://docs.aicentos.com/vi/api/chat/openai/chat-completions

Language: vi

Chat — định dạng OpenAI gốc

`POST /chat/completions`

## Xác thực

Lưu API Key vào biến môi trường `AICENTOS_API_KEY`; các ví dụ shell dùng giá trị của biến trong header `Authorization: Bearer`.

API Key lấy từ mục "Quản lý token" trong Console

Vị trí: `header`

## Nội dung yêu cầu

`application/json`

Định nghĩa kiểu TypeScript

Sử dụng kiểu request body trong TypeScript

## Nội dung phản hồi

###

`application/json`

###

`application/json`

###

`application/json`

###

`application/json`

```bash
export AICENTOS_API_KEY="sk-your-aicentos-api-key"

curl -X POST "https://aicentos.com/v1/chat/completions" \
  -H "Authorization: Bearer $AICENTOS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{    "model": "gpt-4o-mini",    "messages": [      {        "role": "user",        "content": "Giới thiệu bản thân trong một câu"      }    ]  }'
```

```bash
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 0,
  "model": "string",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "system",
        "content": "string",
        "name": "string"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}
```

```bash
{
  "error": {
    "message": "Incorrect API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}
```

```bash
{
  "error": {
    "message": "Incorrect API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}
```

```bash
{
  "error": {
    "message": "Incorrect API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}
```