---
title: "Completions"
method: POST
path: "/v1/completions"
---

# Completions

`POST /v1/completions`

## Headers

- `X-Amz-Cf-Id` string, nullable
- `CF-RAY` string, nullable
- `X-delay-time` number, nullable

## Request body

- CompletionRequest — Request for completions endpoint
  - `best_of` integer, nullable — Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`
  - `echo` boolean, nullable — Echo back the prompt in addition to the completion
  - `frequency_penalty` number, nullable — Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
  - `grammar_root` string, nullable — The grammar root used for structured output generation.
  - `logit_bias` object, nullable — Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
  - `logprobs` integer, nullable — Include the log probabilities on the logprobs most likely output tokens, as well the chosen tokens. For example, if logprobs is 5, the API will return a list of the 5 most likely tokens. The API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response.
  - `max_tokens` integer, nullable — The maximum number of tokens that can be generated in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length.
  - `min_tokens` integer, nullable — The minimum number of tokens to generate for a completion. If not specified or set to 0, the model will generate as many tokens as it deems necessary. Setting to -1 sets to max sequence length.
  - `model` string, required
  - `n` integer, nullable — How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
  - `presence_penalty` number, nullable — Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
  - `prompt` union, required — The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.
    - string
    - string[]
    - integer[]
    - array[]
      - integer[]
  - `prompt_cache_key` string, nullable — An optional opaque string. The requests with the same prompt cache key would highly likely share the same prompt prefixes. Examples would be IDs of chat conversations, IDs of users, the hashes of system prompts, etc.
  - `reasoning_format` 'none' | 'parsed' | 'text_parsed' | 'raw' | 'hidden'
  - `return_raw_tokens` boolean, nullable — Return raw tokens instead of text
  - `seed` integer, nullable — If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. Determinism is not guaranteed.
  - `stop` union — Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
    - string
    - string[]
  - `stream` boolean, nullable
  - `stream_options` StreamOptions — Options for streaming.
    - `include_usage` boolean, nullable
  - `suffix` string, nullable — The suffix that comes after a completion of inserted text. (OpenAI feature, not supported)
  - `temperature` number, nullable — What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
  - `top_p` number, nullable — An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
  - `user` string, nullable — A unique identifier representing your end-user, which can help Cerebras to monitor and detect abuse.

## Response `200`

Successful Response

- union
  - CompletionResponse
    - `choices` CompletionChoice[], required
      - `finish_reason` 'stop' | 'length' | 'content_filter' | 'tool_calls', nullable
      - `index` integer, required
      - `logprobs` CompletionLogProbs
        - `text_offset` integer[], nullable
        - `token_logprobs` number[], nullable
        - `tokens` string[], nullable
        - `top_logprobs` object[], nullable
      - `text` string, nullable
      - `tokens` integer[], nullable
    - `created` integer, required
    - `id` string, required
    - `model` string, required
    - `object` 'text_completion', required
    - `system_fingerprint` string, required
    - `time_info` TimeInfo — Time information for different phases of request processing. All times are measured in seconds.
      - `completion_time` number, nullable
      - `created` number, nullable
      - `prompt_time` number, nullable
      - `queue_time` number, nullable
      - `total_time` number, nullable
    - `usage` Usage
      - `completion_tokens` integer
      - `completion_tokens_details` CompletionTokensDetails
        - `accepted_prediction_tokens` integer, nullable
        - `reasoning_tokens` integer, nullable
        - `rejected_prediction_tokens` integer, nullable
      - `image_tokens` integer, nullable
      - `prompt_tokens` integer
      - `prompt_tokens_details` PromptTokensDetails
        - `cached_tokens` integer
      - `total_tokens` integer
  - ErrorChunkResponse
    - `error` ErrorChunkContent, required
      - `code` string, nullable
      - `id` string, nullable
      - `message` string, nullable
      - `param` string, nullable
      - `type` string, nullable
    - `status_code` integer, required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/cerebras/apis/cerebras-cloud-api.md) · [All operations](https://skmtc.net/cerebras/apis/cerebras-cloud-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/cerebras/cerebras-cloud-api/versions/130749c46caf/schema)
