# Cipta pelengkapan chat

**API:** Model API

**Endpoint:** `POST /api/v1/chat/completions`

API Chat Completions serasi OpenAI. Tetapkan stream=true untuk menerima Server-Sent Events. Respons dan sampul ralat mengikut bentuk Chat Completions/serasi OpenAI.

## Base URL

- `https://openapi.felo.ai` — Pengeluaran

## Authentication

- `FeloBearerAuth` (http bearer) — Kunci API Felo dihantar sebagai `Authorization: Bearer <key>`.
- `FeloApiKey` (apiKey in header `X-API-Key`) — Kunci API Felo dihantar sebagai `X-API-Key: <key>`.

## Parameters

| Name | In | Required | Type | Description |
| --- | --- | --- | --- | --- |
| `X-Felo-Channel` | header | no | string, default: "default" | Kod saluran awam yang dipisahkan koma dan tersusun. Tinggalkan pengepala ini untuk menggunakan default; default mesti digunakan secara bersendirian. Dalam mod dompet, default mengimbas susunan saluran awam berkesan model secara terbalik, melangkau saluran yang tidak diterbitkan atau tidak tersedia, dan memilih penyedia saluran pertama yang tersedia. Ia merangkumi endpoint tersedia daripada penyedia itu dengan ID model huluan dan tahap perkhidmatan yang sama. Saluran eksplisit disahkan mengikut susunan yang ditetapkan klien; hanya kumpulan penyedia saluran pertama yang dihantar. Tiada sandaran automatik kepada penyedia lain. Pengepala penyedia legasi tidak boleh mengatasi penghalaan saluran. |

## Request body

Required: **yes**

### application/json

Schema: `ChatCompletionRequest` (`#/components/schemas/ChatCompletionRequest`)

```json
{
  "type": "object",
  "required": [
    "model",
    "messages"
  ],
  "properties": {
    "model": {
      "type": "string"
    },
    "messages": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/components/schemas/ChatMessage"
      }
    },
    "stream": {
      "type": "boolean",
      "default": false
    },
    "temperature": {
      "type": "number",
      "minimum": 0
    },
    "top_p": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "n": {
      "type": "integer",
      "minimum": 1
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 1
    },
    "max_completion_tokens": {
      "type": "integer",
      "minimum": 1
    },
    "stop": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    },
    "tool_choice": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "object",
          "additionalProperties": true
        }
      ]
    },
    "response_format": {
      "type": "object",
      "additionalProperties": true
    },
    "user": {
      "type": "string"
    },
    "service_tier": {
      "type": [
        "string",
        "null"
      ],
      "default": "default",
      "description": "Pada masa ini hanya default (standard) disokong. Nilai yang ditinggalkan, null, alias dan rentetan tidak disokong akan kembali kepada default; jenis lain memulangkan HTTP 400. Saluran dan harga yang dikonfigurasikan kekal tidak berubah. API teks menghantar nilai standard penyedia; API Decisions dan penjanaan meninggalkan medan huluan."
    }
  },
  "additionalProperties": true
}
```

Example:

```json
{
  "model": "gpt-5.5",
  "messages": [
    {
      "role": "user",
      "content": "Write a one-sentence greeting."
    }
  ],
  "stream": false
}
```

## Responses

### 200 — Pelengkapan chat atau respons penstriman

**application/json**

Schema: `ChatCompletionResponse` (`#/components/schemas/ChatCompletionResponse`)

**text/event-stream**

Schema: string

```json
{
  "type": "string",
  "description": "Serpihan SSE yang mengandungi peristiwa data chat.completion.chunk."
}
```

### 400 — Permintaan, model atau pemetaan penyedia tidak sah

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

### 401 — Kunci API Felo tidak sah atau tiada

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

### 402 — Baki tidak mencukupi

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

### 403 — Akaun tidak dibenarkan menggunakan model ini. Model yang dilumpuhkan juga ditolak sebelum panggilan huluan. Permintaan dan tugas yang telah diterima terus berjalan.

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

### 429 — Had perbelanjaan atau permintaan telah dicapai

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

### 502 — Permintaan kepada penyedia huluan gagal

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

### 503 — Penyedia atau perkhidmatan pengebilan tidak tersedia

**application/json**

Schema: `OpenAIErrorResponse` (`#/components/schemas/OpenAIErrorResponse`)

## Schema definitions

### ChatChoice

`#/components/schemas/ChatChoice`

```json
{
  "type": "object",
  "properties": {
    "index": {
      "type": "integer"
    },
    "message": {
      "$ref": "#/components/schemas/ChatMessage"
    },
    "finish_reason": {
      "type": [
        "string",
        "null"
      ]
    },
    "logprobs": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
```

### ChatCompletionResponse

`#/components/schemas/ChatCompletionResponse`

```json
{
  "type": "object",
  "required": [
    "id",
    "object",
    "choices"
  ],
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "type": "string",
      "description": "Biasanya chat.completion untuk respons tanpa penstriman."
    },
    "created": {
      "type": "integer",
      "format": "int64"
    },
    "model": {
      "type": "string"
    },
    "choices": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/ChatChoice"
      }
    },
    "usage": {
      "$ref": "#/components/schemas/Usage"
    },
    "system_fingerprint": {
      "type": "string"
    }
  },
  "additionalProperties": true
}
```

### ChatMessage

`#/components/schemas/ChatMessage`

```json
{
  "type": "object",
  "required": [
    "role",
    "content"
  ],
  "properties": {
    "role": {
      "type": "string",
      "enum": [
        "system",
        "developer",
        "user",
        "assistant",
        "tool"
      ]
    },
    "content": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": true
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "name": {
      "type": "string"
    },
    "tool_call_id": {
      "type": "string"
    },
    "tool_calls": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    }
  },
  "additionalProperties": true
}
```

### OpenAIErrorResponse

`#/components/schemas/OpenAIErrorResponse`

```json
{
  "type": "object",
  "description": "Sampul ralat serasi OpenAI. Router mungkin menyertakan code dan message tanpa semua medan huluan pilihan.",
  "required": [
    "error"
  ],
  "properties": {
    "error": {
      "type": "object",
      "required": [
        "message"
      ],
      "properties": {
        "message": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "description": "Jenis ralat serasi OpenAI apabila dibekalkan."
        },
        "param": {
          "type": [
            "string",
            "null"
          ]
        },
        "code": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
```

### Usage

`#/components/schemas/Usage`

```json
{
  "type": "object",
  "description": "Objek penggunaan penyedia. Medan berbeza mengikut endpoint dan penyedia.",
  "additionalProperties": true
}
```
