> For the complete documentation index, see [llms.txt](https://docs.avis.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avis.xyz/api-reference/endpoints/text-completion.md).

# Text Completion

`POST /api/v1/text/completions`

Streams chat-style text completion chunks as Server-Sent Events.

### Request Fields

| Field                | Type      | Required | Validation                       | Description                                             |
| -------------------- | --------- | -------- | -------------------------------- | ------------------------------------------------------- |
| `model`              | string    | Yes      | Non-empty string                 | User-facing model identifier from `/ai/models`.         |
| `messages`           | object\[] | Yes      | Array with at least one item     | Chat messages in conversation order.                    |
| `messages[].role`    | string    | Yes      | `system`, `user`, or `assistant` | Message role.                                           |
| `messages[].content` | string    | Yes      | Non-empty string                 | Message text content.                                   |
| `temperature`        | number    | No       | Minimum `0`, maximum `2`         | Sampling temperature. Higher values increase variation. |
| `maxTokens`          | integer   | No       | Minimum `1`                      | Maximum number of tokens to generate.                   |

Additional optional fields (model-dependent) are supported and forwarded when applicable: `topP`, `stop`, `tools`, `toolChoice`, `responseFormat`, `seed`, `presencePenalty`, `frequencyPenalty`, `topK`, `repetitionPenalty`, `minP`, `topA`, `logprobs`, `topLogprobs`, `logitBias`, `structuredOutputs`, `parallelToolCalls`, `includeReasoning`, `reasoningEffort`, `webSearchOptions`, `verbosity`, `thinking`. Which of these a given model actually accepts is listed in `capabilities.text.supportedParameters` from `GET /ai/models` — check there per model rather than assuming a field is supported.

### Request Example

```json
{
  "model": "seed-2-0-lite",
  "messages": [
    { "role": "system", "content": "Answer clearly and briefly." },
    { "role": "user", "content": "Explain UUIDv7 in one paragraph." }
  ],
  "temperature": 0.7,
  "maxTokens": 512
}
```

### Response Stream

Response headers:

```http
Content-Type: text/event-stream
Cache-Control: no-cache, no-transform
Connection: keep-alive
X-Accel-Buffering: no
```

Each chunk is emitted as:

```
data: <TextChunk JSON>

```

The stream ends with:

```
data: [DONE]

```

### TextChunk Fields

| Field                    | Type   | Required | Description                                                                             |
| ------------------------ | ------ | -------- | --------------------------------------------------------------------------------------- |
| `delta`                  | string | Yes      | Incremental text fragment for this chunk.                                               |
| `finishReason`           | string | No       | Stop reason, usually present on the final model chunk.                                  |
| `usage`                  | object | No       | Usage details, usually present only on the final chunk when the provider reports usage. |
| `usage.promptTokens`     | number | No       | Tokens consumed by the prompt.                                                          |
| `usage.completionTokens` | number | No       | Tokens generated by the model.                                                          |
| `usage.totalTokens`      | number | No       | Sum of prompt and completion tokens.                                                    |

Provider errors after the stream starts are emitted as an SSE JSON object with `error`, then the stream closes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.avis.xyz/api-reference/endpoints/text-completion.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
