v4

latestOpenAPI 3.1.02026-08-0143190206.8 KB
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

best_ofinteger nullable

(Unsupported) Generates multiple completions internally and returns the top-scoring one. Not functional yet.

echoboolean nullable

Option to include the original prompt in the response along with the generated completion.

frequency_penaltynumber 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_biasobject 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.

logprobsboolean 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_tokensinteger 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.

modelstring

Specifies the model to be used for the request.

ninteger 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_penaltynumber 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.

seedinteger 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.

stopstring[] nullable

(Not supported by reasoning models) Up to 4 sequences where the API will stop generating further tokens.

streamboolean 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.

suffixstring nullable

(Unsupported) Optional string to append after the generated text.

temperaturenumber 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_pnumber 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.

userstring nullable

A unique identifier representing your end-user, which can help xAI to monitor and detect abuse.

Example request

{
  "temperature": 0.2
}

Response

Success

createdinteger required

The chat completion creation time in Unix timestamp.

idstring required

ID of the request.

modelstring required

Model to be used.

objectstring required

Object type of the response. This is always "text_completion".

system_fingerprintstring nullable

System fingerprint, used to indicate xAI system configuration changes.

Example response

{
  "model": "latest"
}