> ## 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 (legacy)

> POST /v1/completions — the legacy text completion endpoint

<Warning>
  The legacy text completion endpoint, mainly for backward compatibility.
  **For new projects, use [Chat Completions](/en/api-reference/openai/chat-completions)**.
</Warning>

## Request

```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
  }'
```

### Main parameters

| Field                                    | Type            | Description                                                        |
| ---------------------------------------- | --------------- | ------------------------------------------------------------------ |
| `model`                                  | string          | Model ID (a few models like `gpt-3.5-turbo-instruct` support this) |
| `prompt`                                 | string \| array | The input prompt                                                   |
| `max_tokens`                             | integer         | Maximum output                                                     |
| `temperature` / `top_p`                  | number          | Sampling                                                           |
| `n`                                      | integer         | Number of candidates                                               |
| `stream`                                 | boolean         | SSE stream                                                         |
| `stop`                                   | string \| array | Stop sequences                                                     |
| `presence_penalty` / `frequency_penalty` | number          | Penalties                                                          |
| `echo`                                   | boolean         | Include the prompt in the output                                   |
| `best_of`                                | integer         | Generate several server-side and pick the best                     |
| `logprobs`                               | integer         | Return logprobs                                                    |

## Response

```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}
}
```

## Migrating to Chat

Change `prompt` to `messages`:

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

And switch the model ID to something like `gpt-5.5`.
