---
title: "(Legacy - Not supported by reasoning models) Create a text completion response for a given prompt. Replaced by /v1/chat/completions."
method: POST
path: "/v1/completions"
tags: ["v1"]
---

# (Legacy - Not supported by reasoning models) Create a text completion response for a given prompt. Replaced by /v1/chat/completions.

`POST /v1/completions`

## Request body

- SampleRequest — (Legacy) Request for `/v1/completions` endpoint
  - `best_of` integer, nullable — (Unsupported) Generates multiple completions internally and returns the top-scoring one. Not functional yet.
  - `echo` boolean, nullable — Option to include the original prompt in the response along with the generated completion.
  - `frequency_penalty` number, float, nullable — (Unsupported) 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.
  - `logit_bias` object, nullable — (Unsupported) Accepts a JSON object that maps tokens to an associated bias value from -100 to 100. You can use this tokenizer tool to convert text to token IDs. 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` boolean, 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. Not supported by models `grok-4.20` and newer; the field will be silently ignored if set.
  - `max_tokens` integer, nullable — Limits the number of tokens that can be produced in the output. Ensure the sum of prompt tokens and `max_tokens` does not exceed the model's context limit.
  - `model` string — Specifies the model to be used for the request.
  - `n` integer, nullable — Determines how many completion sequences to produce for each prompt. Be cautious with its use due to high token consumption; adjust `max_tokens` and stop sequences accordingly.
  - `presence_penalty` number, float, nullable — (Not supported by `grok-3` and reasoning models) 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
    - string — Text prompt.
    - string[] — An array of strings, a token list, or an array of token lists.
  - `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, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.
  - `stop` string[], nullable — (Not supported by reasoning models) Up to 4 sequences where the API will stop generating further tokens.
  - `stream` boolean, nullable — Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message.
  - `stream_options` StreamOptions — Options available when using streaming response.
    - `include_usage` boolean, required — Set an additional chunk to be streamed before the `data: [DONE]` message. The other chunks will return `null` in `usage` field.
  - `suffix` string, nullable — (Unsupported) Optional string to append after the generated text.
  - `temperature` number, float, 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, float, 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 xAI to monitor and detect abuse.

## Response `200`

Success

- SampleResponse — (Legacy) Response for `/v1/completions` endpoint
  - `choices` SampleChoice[], required — A list of response choices from the model. The length corresponds to the `n` in request body (default to 1).
    - `finish_reason` string, required — Finish reason. `"stop"` means the inference has reached a model-defined or user-supplied stop sequence in `stop`. `"length"` means the inference result has reached models' maximum allowed token length or user defined value in `max_tokens`. `"end_turn"` or `null` in streaming mode when the chunk is not the last.
    - `index` integer, required — Index of the choice.
    - `text` string, required — Text response.
  - `created` integer, required — The chat completion creation time in Unix timestamp.
  - `id` string, required — ID of the request.
  - `model` string, required — Model to be used.
  - `object` string, required — Object type of the response. This is always `"text_completion"`.
  - `system_fingerprint` string, nullable — System fingerprint, used to indicate xAI system configuration changes.
  - `usage` Usage
    - `completion_tokens` integer, required — Total completion token used.
    - `completion_tokens_details` CompletionUsageDetail, required — Details of completion usage.
      - `accepted_prediction_tokens` integer, required — The number of tokens in the prediction that appeared in the completion.
      - `audio_tokens` integer, required — Audio input tokens generated by the model.
      - `reasoning_tokens` integer, required — Tokens generated by the model for reasoning.
      - `rejected_prediction_tokens` integer, required — The number of tokens in the prediction that did not appear in the completion.
    - `cost_in_usd_ticks` integer, required — Accurate cost of this request in USD ticks, where "tick" is defined as follows: TICKS_IN_USD_CENT: i64 = 100_000_000 which means there is 10'000'000'000 ticks in one *dollar*.
    - `num_sources_used` integer, required — Number of individual live search source used.
    - `prompt_tokens` integer, required — Total prompt token used.
    - `prompt_tokens_details` PromptUsageDetail, required — Details of prompt usage.
      - `audio_tokens` integer, required — Audio prompt token used.
      - `cached_tokens` integer, required — Token cached by xAI from previous requests and reused for this request.
      - `image_tokens` integer, required — Image prompt token used.
      - `text_tokens` integer, required — Total text prompt token used (cached + non-cached text tokens).
    - `total_tokens` integer, required — Total token used, the sum of prompt token and completion token amount.

## Other responses

- `400` — Bad request. The request is invalid or an invalid API key is provided.
- `422` — Unprocessable Entity. There are missing fields in the request body.

---

[API](https://skmtc.net/x/apis/xai-s-rest-api.md) · [All operations](https://skmtc.net/x/apis/xai-s-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/x/xai-s-rest-api/versions/8f6014272113/schema)
