---
title: "Text generation"
method: POST
path: "/v1/completions"
tags: ["Generation API"]
---

# Text generation

`POST /v1/completions`

Generate text completions using the specified model and prompt. This endpoint is useful for text generation tasks that don't require conversational context.

## Request body

- CompletionsRequest
  - `model` string, required — The [ID of the model](https://dev.writer.com/home/models) to use for generating text. Supports `palmyra-x5`, `palmyra-x4`, `palmyra-fin`, `palmyra-med`, `palmyra-creative`, and `palmyra-x-003-instruct`.
  - `prompt` string, required — The input text that the model will process to generate a response.
  - `max_tokens` integer — The maximum number of tokens that the model can generate in the response.
  - `temperature` number, double — Controls the randomness of the model's outputs. Higher values lead to more random outputs, while lower values make the model more deterministic.
  - `top_p` number, double — Used to control the nucleus sampling, where only the most probable tokens with a cumulative probability of top_p are considered for sampling, providing a way to fine-tune the randomness of predictions.
  - `stop` union — Specifies stopping conditions for the model's output generation. This can be an array of strings or a single string that the model will look for as a signal to stop generating further tokens.
    - string[]
    - string
  - `best_of` integer — Specifies the number of completions to generate and return the best one. Useful for generating multiple outputs and choosing the best based on some criteria.
  - `random_seed` integer — A seed used to initialize the random number generator for the model, ensuring reproducibility of the output when the same inputs are provided.
  - `stream` boolean — Determines whether the model's output should be streamed. If true, the output is generated and sent incrementally, which can be useful for real-time applications.

## Response `200`

Successful response

- CompletionsResponse
  - `choices` CompletionsChoice[], required — A list of choices generated by the model, each containing the text of the completion and associated metadata such as log probabilities.
    - `text` string, required — The generated text output from the model, which forms the main content of the response.
    - `log_probs` Logprobs, nullable
      - `content` LogprobsToken[], nullable, required
        - `token` string, required
        - `logprob` number, double, required
        - `bytes` integer[]
        - `top_logprobs` TopLogProb[], required
          - `token` string, required
          - `logprob` number, double, required
          - `bytes` integer[]
      - `refusal` LogprobsToken[], nullable, required
        - `token` string, required
        - `logprob` number, double, required
        - `bytes` integer[]
        - `top_logprobs` TopLogProb[], required
          - `token` string, required
          - `logprob` number, double, required
          - `bytes` integer[]
  - `model` string — The identifier of the model that was used to generate the responses in the 'choices' array.

## Changes

- **2025-02-25** `3d3b2fe43375` — 1 breaking
  - the response property `choices/items/log_probs` became nullable for the status `200`
- **2024-10-04** `2ad4cffb18a0` — 2 info
  - the response property `choices/items/log_probs/content` became required for the status `200`
  - the response property `choices/items/log_probs/refusal` became required for the status `200`
- **2024-10-03** `4a11c63c7cb5` — 1 breaking, 4 warning, 3 info
  - removed the required property `items/data` from the response with the `200` status (media type: text/event-stream)
  - removed the optional property `choices/items/log_probs/text_offset` from the response with the `200` status (media type: application/json)
  - removed the optional property `choices/items/log_probs/token_log_probs` from the response with the `200` status (media type: application/json)
  - removed the optional property `choices/items/log_probs/tokens` from the response with the `200` status (media type: application/json)
  - …4 more
- **2024-09-24** `5d34056e0e74` — 1 warning, 1 info
  - removed the optional property `items/data/choices/items/message/tool_calls` from the response with the `200` status
  - removed the `tool_calls` enum value from the `items/data/choices/items/finish_reason` response property for the response status `200`
- …earlier changes not shown

[Full history](https://skmtc.dev/writer/apis/api/changes/v1/completions/post.md)

---

[API](https://skmtc.dev/writer/apis/api.md) · [All operations](https://skmtc.dev/writer/apis/api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/writer/api/revisions/ae230e1d8c09/schema)
