v1

latestOpenAPI 3.0.32026-07-172892106.1 KB
chat

Chat Completion

post/chat/completions

Request body

random_seedinteger nullable

The seed to use for random sampling. If set, different calls will generate deterministic results.

safe_promptboolean

Whether to inject a safety prompt before all conversations.

max_tokensinteger nullable

The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length.

presence_penaltynumber

presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.

ninteger nullable

Number of completions to return for each request, input tokens are only billed once.

top_pnumber

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.

frequency_penaltynumber

frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.

streamboolean

Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.

temperaturenumber nullable

What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 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. The default value varies depending on the model you are targeting. Call the /models endpoint to retrieve the appropriate value.

modelstring required

ID of the model to use. You can use the List Available Models API to see all of your available models, or see our Model overview for model descriptions.

Example request

{
  "messages": [
    [
      {
        "role": "user",
        "content": "Who is the best French painter? Answer in one short sentence."
      }
    ]
  ],
  "model": "[\"mistral-small-latest\"]"
}

Response

Successful Response

modelstring required
idstring required
objectstring required
createdinteger

Example response

{
  "usage": {
    "completion_tokens": 34,
    "prompt_tokens": 16,
    "total_tokens": 50
  },
  "model": "mistral-small-latest",
  "id": "cmpl-e5cc70bb28c444948073e77776eb30ef",
  "object": "chat.completion",
  "created": 1702256327,
  "choices": [
    {
      "finish_reason": "stop"
    }
  ]
}