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

# Completions(旧版)

> POST /v1/completions —— 传统文本补全接口

<Warning>
  传统的文本补全接口,主要用于历史兼容。
  **新项目请使用 [Chat Completions](/api-reference/openai/chat-completions)**。
</Warning>

## 请求

```bash theme={null}
curl https://openp.ai/v1/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Once upon a time",
    "max_tokens": 64,
    "temperature": 0.7
  }'
```

### 主要参数

| 字段                                       | 类型              | 说明                                      |
| ---------------------------------------- | --------------- | --------------------------------------- |
| `model`                                  | string          | 模型 ID(`gpt-3.5-turbo-instruct` 等少数模型支持) |
| `prompt`                                 | string \| array | 输入 prompt                               |
| `max_tokens`                             | integer         | 最大输出                                    |
| `temperature` / `top_p`                  | number          | 采样                                      |
| `n`                                      | integer         | 候选数量                                    |
| `stream`                                 | boolean         | SSE 流                                   |
| `stop`                                   | string \| array | 停止序列                                    |
| `presence_penalty` / `frequency_penalty` | number          | 惩罚                                      |
| `echo`                                   | boolean         | 在输出中包含 prompt                           |
| `best_of`                                | integer         | 服务端生成多个后挑最优                             |
| `logprobs`                               | integer         | 返回 logprobs                             |

## 响应

```json theme={null}
{
  "id": "cmpl-...",
  "object": "text_completion",
  "created": 1715750400,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "text": ", there was a small castle...",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {"prompt_tokens": 4, "completion_tokens": 64, "total_tokens": 68}
}
```

## 与 Chat 的迁移

把 `prompt` 改成 `messages` 即可:

```diff theme={null}
- "prompt": "Once upon a time"
+ "messages": [{"role": "user", "content": "Continue: Once upon a time"}]
```

并把模型 ID 换成 `gpt-5.5` 等。
