---
title: "Create completion"
method: POST
path: "/completions"
tags: ["Completion"]
---

# Create completion

`POST /completions`

Generate text completions for a given prompt using a language, code, or image model.

## Request body

- CompletionRequest
  - `prompt` string, required — A string providing context for the model to complete.
  - `model` union, required — The name of the model to query.<br> <br> [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#chat-models)
    - 'meta-llama/Llama-2-70b-hf' | 'mistralai/Mistral-7B-v0.1' | 'mistralai/Mixtral-8x7B-v0.1' | 'Meta-Llama/Llama-Guard-7b'
    - string
  - `max_tokens` integer — The maximum number of tokens to generate.
  - `stop` string[] — A list of string sequences that truncate (stop) inference text output. For example, "</s>" stops generation as soon as the model generates the given token.
  - `temperature` number — A decimal number from 0-1 that determines the degree of randomness in the response. A temperature less than 1 favors more correctness and is appropriate for question answering or summarization. A value closer to 1 introduces more randomness in the output.
  - `top_p` number — A percentage (also called the nucleus parameter) that's used to dynamically adjust the number of choices for each predicted token based on the cumulative probabilities. It specifies a probability threshold below which all less likely tokens are filtered out. This technique helps maintain diversity and generate more fluent and natural-sounding text.
  - `top_k` integer — An integer that's used to limit the number of choices for the next predicted word or token. It specifies the maximum number of tokens to consider at each step, based on their probability of occurrence. This technique helps to speed up the generation process and can improve the quality of the generated text by focusing on the most likely options.
  - `repetition_penalty` number — A number that controls the diversity of generated text by reducing the likelihood of repeated sequences. Higher values decrease repetition.
  - `stream` boolean — If true, stream tokens as Server-Sent Events as the model generates them instead of waiting for the full model response. The stream terminates with `data: [DONE]`. If false, return a single JSON object containing the results.
  - `logprobs` integer — An integer between 0 and 20 of the top k tokens to return log probabilities for at each generation step, instead of only the sampled token. Log probabilities help assess model confidence in token predictions.
  - `echo` boolean — If true, the response contains the prompt. Can be used with `logprobs` to return prompt logprobs.
  - `n` integer — The number of completions to generate for each prompt.
  - `safety_model` union — The name of the moderation model used to validate tokens. Choose from the available moderation models found [here](https://docs.together.ai/docs/inference-models#moderation-models).
    - 'Meta-Llama/Llama-Guard-7b'
    - string
  - `min_p` number — A number between 0 and 1 that can be used as an alternative to top-p and top-k.
  - `presence_penalty` number — A number between -2.0 and 2.0 where a positive value increases the likelihood of a model talking about new topics.
  - `frequency_penalty` number — A number between -2.0 and 2.0 where a positive value decreases the likelihood of repeating tokens that have already been mentioned.
  - `logit_bias` object — Adjusts the likelihood of specific tokens appearing in the generated output.
  - `seed` integer — Seed value for reproducibility.

## Response `200`

200

- CompletionResponse
  - `id` string, required
  - `choices` object[], required
    - `text` string
    - `seed` integer
    - `finish_reason` 'stop' | 'eos' | 'length' | 'tool_calls' | 'function_call'
    - `logprobs` LogprobsPart
      - `token_ids` number[] — List of token IDs corresponding to the logprobs
      - `tokens` string[] — List of token strings
      - `token_logprobs` number[] — List of token log probabilities
      - `top_logprobs` TopLogprobs — Top log probabilities for the tokens.
  - `prompt` object[], required
    - `text` string
    - `logprobs` LogprobsPart
      - `token_ids` number[] — List of token IDs corresponding to the logprobs
      - `tokens` string[] — List of token strings
      - `token_logprobs` number[] — List of token log probabilities
      - `top_logprobs` TopLogprobs — Top log probabilities for the tokens.
  - `usage` UsageData, nullable, required
    - `prompt_tokens` integer, required
    - `completion_tokens` integer, required
    - `total_tokens` integer, required
  - `created` integer, required
  - `model` string, required
  - `object` 'text.completion', required — The object type, which is always `text.completion`.

## Other responses

- `400` — BadRequest
- `401` — Unauthorized
- `404` — NotFound
- `429` — RateLimit
- `503` — Overloaded
- `504` — Timeout

---

[API](https://skmtc.net/together/apis/together-apis.md) · [All operations](https://skmtc.net/together/apis/together-apis/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/together/together-apis/revisions/468edbdc879c/schema)
