v4
latestOpenAPI 3.1.02026-08-0143190206.8 KB(Legacy - Not supported by reasoning models) Create a text completion response for a given prompt. Replaced by /v1/chat/completions.
Request body
(Unsupported) Generates multiple completions internally and returns the top-scoring one. Not functional yet.
Option to include the original prompt in the response along with the generated completion.
(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.
(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.
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.
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.
Specifies the model to be used for the request.
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.
(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.
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.
(Not supported by reasoning models) Up to 4 sequences where the API will stop generating further tokens.
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.
(Unsupported) Optional string to append after the generated text.
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.
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.
A unique identifier representing your end-user, which can help xAI to monitor and detect abuse.
Example request
{
"temperature": 0.2
}Response
Success
The chat completion creation time in Unix timestamp.
ID of the request.
Model to be used.
Object type of the response. This is always "text_completion".
System fingerprint, used to indicate xAI system configuration changes.
Example response
{
"model": "latest"
}