Using Mistral AI with Flowstack

Mistral AI can be integrated with Flowstack using various methods. The following documentation provides details for using Mistral AI with Curl, Python, and Node.js.

1. Using Curl

To make a request to Mistral AI using the REST API, use the following Curl command. Remember to replace YOUR_MISTRAL_API_KEY and YOUR_FLOWSTACK_KEY with your actual Mistral API key and Flowstack key.

curl --request POST \
  --url 'http://mistral.flowstack.ai/v1/chat/completions' \
  --header 'Authorization: Bearer YOUR_MISTRAL_API_KEY' \
  --header 'Content-Type: application/json' \
  --header 'Flowstack-Auth: Bearer YOUR_FLOWSTACK_KEY' \
  --data '{
    "model": "mistral-tiny",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'

2. Using Python

For integrating Mistral AI with Python, use the script below. Replace YOUR_MISTRAL_API_KEY and YOUR_FLOWSTACK_KEY with your Mistral API key and Flowstack key, respectively.

import requests
import json

url = "http://mistral.flowstack.ai/v1/chat/completions"

headers = {
    "Authorization": "Bearer YOUR_MISTRAL_API_KEY",
    "Content-Type": "application/json",
    "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY"
}
payload = {
    "model": "mistral-tiny",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)

3. Using Node.js

For Node.js integration with Mistral AI, follow the example below. Don’t forget to replace YOUR_MISTRAL_API_KEY and YOUR_FLOWSTACK_KEY with your respective credentials.

const axios = require("axios");

const url = "http://mistral.flowstack.ai/v1/chat/completions";

const headers = {
  Authorization: "Bearer YOUR_MISTRAL_API_KEY",
  "Content-Type": "application/json",
  "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY",
};

const payload = {
  model: "mistral-tiny",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello!" },
  ],
};

axios
  .post(url, payload, { headers: headers })
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error("Error:", error);
  });