> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ominiapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 补全文本

# 补全 (Completions) - 原生 OpenAI 格式

基于给定提示 (prompt) 创建文本补全。完全兼容 OpenAI 的 Completions API 格式。

* **接口地址**: `POST /v1/completions`
* **请求格式 (Content-Type)**: `application/json`

## 认证与请求头 (Headers)

* `Authorization` (**必选**): 使用 Bearer Token 认证。格式: `Bearer <token>` 或 `Bearer sk-xxxxxx`

## 请求参数 (Request Body - JSON)

| 参数名           | 类型             | 必选    | 说明                                   |
| :------------ | :------------- | :---- | :----------------------------------- |
| `model`       | String         | **是** | 模型名称（例如 `gpt-3.5-turbo-instruct` 等）。 |
| `prompt`      | String / Array | **是** | 生成文本的提示词，可以是单个字符串或字符串数组。             |
| `max_tokens`  | Integer        | 否     | 生成补全文本的最大 Token 数量。                  |
| `temperature` | Number         | 否     | 采样温度，控制生成内容的随机性。                     |
| `top_p`       | Number         | 否     | 核采样参数（Nucleus sampling）。             |
| `n`           | Integer        | 否     | 为每个提示生成的补全选项数量。                      |
| `stream`      | Boolean        | 否     | 是否启用流式输出（Server-Sent Events）。        |
| `stop`        | String / Array | 否     | API 将停止生成后续 Token 的字符串序列（最多 4 个）。    |
| `suffix`      | String         | 否     | 插入到生成文本末尾的后缀字符串。                     |
| `echo`        | Boolean        | 否     | 是否在补全的开头回显提示词 (prompt)。              |

## 示例代码 (cURL)

```bash theme={null}
curl -X POST "[https://www.ominiapi.com/v1/completions](https://www.ominiapi.com/v1/completions)" \
  -H "Authorization: Bearer <您的_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Say this is a test",
    "max_tokens": 7,
    "temperature": 0
  }'
```

## 响应体结构 (Response - 200 OK)

成功请求将返回 JSON 格式结果。

```bash theme={null}
{
  "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWiTgIRlc",
  "object": "text_completion",
  "created": 1589478378,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "text": "\n\nThis is indeed a test",
      "index": 0,
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 7,
    "total_tokens": 12,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "text_tokens": 5,
      "audio_tokens": 0,
      "image_tokens": 0
    },
    "completion_tokens_details": {
      "text_tokens": 7,
      "audio_tokens": 0,
      "reasoning_tokens": 0
    }
  }
}
```
