← Back to API List

Create Chat Completion with Mistral Large

POST/v1/chat/completionsMistral AI

Creates a model response for the given chat conversation using Mistral Large.

text generationmistrallargemultilingualreasoningapi
Official Documentation

Headers

Content-TypestringRequired

Set to `application/json`.

AuthorizationstringRequired

Bearer token authentication with your Mistral API key.

Request Body

modelstringRequired

ID of the model to use.

Example: mistral-large-latest

top_pnumber

Nucleus sampling parameter.

Defaults to: 1

Example: 1

streamboolean

Whether to stream back partial progress.

Defaults to: false

messagesarray of objectRequired

The list of messages in the chat.

max_tokensinteger

The maximum number of tokens to generate.

Example: 150

temperaturenumber

Controls randomness in the response.

Defaults to: 0.7

Example: 0.7

Response Body

idstring

A unique identifier for the chat completion.

modelstring

The model used for the chat completion.

usageobject

objectstring

The object type, which is always "chat.completion".

choicesarray of object

createdinteger

The Unix timestamp (in seconds) of when the chat completion was created.

Code Examples

cURL

cURL
curl https://api.mistral.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_MISTRAL_API_KEY" \
  -d '{
    "model": "mistral-large-latest",
    "messages": [
      {"role": "user", "content": "What is the best French cheese?"}
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'

Python

Python
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage

api_key = "YOUR_MISTRAL_API_KEY"
model = "mistral-large-latest"

client = MistralClient(api_key=api_key)

messages = [
    ChatMessage(role="user", content="What is the best French cheese?")
]

chat_response = client.chat(
    model=model,
    messages=messages,
    temperature=0.7,
    max_tokens=150
)

print(chat_response.choices[0].message.content)

Example Response

JSON

JSON
{
  "id": "cmpl-e5cc70bb28c444948073e77776eb30ef",
  "object": "chat.completion",
  "created": 1702256327,
  "model": "mistral-large-latest",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "There are many excellent French cheeses, each with its own unique characteristics. Some of the most renowned include Roquefort (a blue cheese), Camembert (soft and creamy), Brie (mild and buttery), Comté (hard aged cheese), and Chèvre (goat cheese). The 'best' really depends on personal taste preferences!"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 65,
    "total_tokens": 80
  }
}