# Completions (Legacy)

Source: https://staging-docs.aiand.com/api/completions/

```http
POST /v1/completions
```

Generate a text completion for a given prompt. Compatible with the [OpenAI Completions API](https://platform.openai.com/docs/api-reference/completions/create).

<Aside type="tip">
This is a legacy endpoint. For new integrations, use [Chat Completions](/api/chat-completions/) instead. Internally, the prompt is converted to a chat message and the response is mapped back to the completions format.
</Aside>

## Request body

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model` | string | Yes | Model ID (see [Models](/api/models/)) |
| `prompt` | string \| string[] | Yes | The prompt(s) to generate completions for |
| `stream` | boolean | No | Stream partial deltas as SSE. Default: `false` |
| `stream_options` | object | No | `{ "include_usage": true }` to include token counts in the final stream event |
| `temperature` | number | No | Sampling temperature, 0–2 |
| `top_p` | number | No | Nucleus sampling threshold, 0–1 |
| `n` | integer | No | Number of completions to generate, 1–128 |
| `max_tokens` | integer | No | Maximum tokens to generate |
| `stop` | string \| string[] | No | Up to 4 stop sequences |
| `frequency_penalty` | number | No | Frequency penalty, -2 to 2 |
| `presence_penalty` | number | No | Presence penalty, -2 to 2 |
| `logprobs` | integer | No | Include log probabilities on the most likely tokens (0–5) |
| `echo` | boolean | No | Echo the prompt in addition to the completion |
| `best_of` | integer | No | Generate `best_of` completions and return the best. Cannot be used with `stream` |
| `suffix` | string | No | Suffix that comes after the completion |
| `seed` | integer | No | Seed for deterministic sampling |
| `user` | string | No | End-user identifier for abuse tracking |

## Response

```json
{
  "id": "cmpl-abc123",
  "object": "text_completion",
  "created": 1700000000,
  "model": "qwen/qwen3.6-27b",
  "choices": [
    {
      "text": "Hello! How can I help you?",
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 7,
    "total_tokens": 12
  }
}
```

### Fields

| Field | Type | Description |
|-------|------|-------------|
| `id` | string | Unique completion ID |
| `object` | string | Always `"text_completion"` |
| `created` | integer | Unix timestamp |
| `model` | string | Model used |
| `choices` | array | Completion choices |
| `choices[].text` | string | Generated text |
| `choices[].index` | integer | Choice index |
| `choices[].logprobs` | object \| null | Log probability info, if requested |
| `choices[].finish_reason` | string | `"stop"` or `"length"` |
| `usage` | object | Token usage statistics |

## Example

```bash
curl https://api.aiand.com/v1/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen/qwen3.6-27b",
    "prompt": "Write a haiku about programming:",
    "max_tokens": 30
  }'
```

## Streaming

Set `stream: true` to receive partial completions as server-sent events.

```bash
curl https://api.aiand.com/v1/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen/qwen3.6-27b",
    "prompt": "Once upon a time",
    "max_tokens": 50,
    "stream": true
  }'
```

Each event contains a `data:` line with a JSON chunk. The stream ends with `data: [DONE]`.
