Tree BG 1
Tree
Tree
TreeLeaves
TreeLeaves
Cat IdleGrassGrassRockRock

Chat Endpoints

Chat Completion API.

Chat Completion

POST /v1/chat/completions

Chat Completion

200 (application/json)

200 (text/event-stream)

Successful Response

created
*integer
id
*string
model
*string
object
*string
usage
*UsageInfo

Playground

Test the endpoints live

import { Mistral } from "@mistralai/mistralai";

const client = new Mistral({ apiKey: process.env.MISTRAL_API_KEY });

const response = await client.chat.complete({
  model: "mistral-large-latest",
  messages: [
    {
      role: "user",
      content: "Who is the best French painter? Answer in one short sentence.",
    },
  ],
});

console.log(response.choices[0].message.content);
import os
from mistralai.client import Mistral

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

response = client.chat.complete(
    model="mistral-large-latest",
    messages=[
        {
            "role": "user",
            "content": "Who is the best French painter? Answer in one short sentence.",
        }
    ],
)

print(response.choices[0].message.content)
curl https://api.mistral.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MISTRAL_API_KEY" \
  -d '{
    "model": "mistral-large-latest",
    "messages": [
      {
        "role": "user",
        "content": "Who is the best French painter? Answer in one short sentence."
      }
    ]
  }'

200 (application/json)

200 (text/event-stream)

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": "<to fill>"
    }
  ],
  "created": "1702256327",
  "id": "cmpl-e5cc70bb28c444948073e77776eb30ef",
  "model": "mistral-small-latest",
  "object": "chat.completion",
  "usage": {}
}