Create Chat Completion
Creates a model response for the given chat conversation.
Request Headers
Enum: application/json
Bearer authentication format, for example: Bearer {{API Key}}.
Request Body
The name of the model to use.
A list of messages comprising the conversation so far.
The maximum number of tokens to generate in the completion.
If the token count of your prompt (previous messages) plus max_tokens exceed the model’s context length, the behavior is depends on context_length_exceeded_behavior. By default, max_tokens will be lowered to fit in the context window instead of returning an error.
Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events (SSE) as they become available, with the stream terminated by a data: [DONE]
message.
How many completions to generate for each prompt.
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.
Required range: 1 < x < 128
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.
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.
Reasonable value is around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition.
See also presence_penalty for penalizing tokens that have at least one appearance at a fixed rate.
Required range: -2 < x < 2
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.
Reasonable value is around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition.
See also frequency_penalty
for penalizing tokens at an increasing rate depending on how often they appear.
Required range: -2 < x < 2
Applies a penalty to repeated tokens to discourage or encourage repetition. A value of 1.0 means no penalty, allowing free repetition. Values above 1.0 penalize repetition, reducing the likelihood of repeating tokens. Values between 0.0 and 1.0 reward repetition, increasing the chance of repeated tokens. For a good balance, a value of 1.2 is often recommended. Note that the penalty is applied to both the generated output and the prompt in decoder-only models.
Required range: 0 < x < 2
Up to 4 sequences where the API will stop generating further tokens. The returned text will contain the stop sequence.
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.
Required range: 0 < x < 2
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.
Required range: 0 < x <= 1
Top-k sampling is another sampling method where the k most probable next tokens are filtered and the probability mass is redistributed among only those k next tokens. The value of k controls the number of candidates for the next token at each step during text generation.
Required range: 1 < x < 128
float that represents the minimum probability for a token to be considered, relative to the probability of the most likely token.
Required range: 0 <= x <= 1
Defaults to null. Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens to an associated bias value from -100 to 100.
Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.
An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs
must be set to true if this parameter is used.
Required range: 0 <= x <= 20
Allows to force the model to produce specific output format.
Setting to { “type”: “json_object” } enables JSON mode, which guarantees the message the model generates is valid JSON.
Optional JSON schema can be provided as response_format = {“type”: “json_object”, “schema”: <json_schema>}.
Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly “stuck” request. Also note that the message content may be partially cut off if finish_reason=“length”, which indicates the generation exceeded max_tokens or the conversation exceeded the max context length.
Response
The list of chat completion choices.
The Unix time in seconds when the response was generated.
A unique identifier of the response.
The model used for the chat completion.
The object type, which is always chat.completion
.
Usage statistics.
For streaming responses, usage field is included in the very last response chunk returned.
Was this page helpful?