---
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. This can be a Palmyra model such as `palmyra-x5` or `palmyra-x4`, or the ID of an [external model](https://dev.writer.com/home/external-models) configured for your organization.
  - `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.

---

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