Rest API Documentation for Mistral

Below is the documentation for integrating Reconify with Mistral via REST API.

Currently we support Chat actions with Mistral via REST API. Try our Node NPM or Python PIP modules as well.

Get started - Create an account

The first step is to create an account at app.reconify.com.

Generate API and APP Keys

In the Reconify console, add an Application to your account. This will generate both an API_KEY and an APP_KEY which will be used in the code below to send data to Reconify.

Rest API Integration

Below are instructions on integrating with the REST API.

At a high level, you will send a copy of the JSON input into Mistral (i.e. the prompts) and the response from Mistral, along with your Reconify API and APP keys. There are additional optional parameters for tracking users and sessions.

Endpoint

Sign up for an account to get the endpoint url.

JSON Payload structure

{
"reconify": {},
"timestamps": {},
"session": "",
"sessionTimeOut": null,
"user": {},
"request": {},
"response": {}
}

Reconify parameters (required)

{
"reconify": {
 "format": "mistral",
 "type": "chat",
 "version": "2.4.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
}
}
  • "format" is required and should be set to "mistral"
  • "type" should be "chat"
  • "version" is the version of the Reconify REST API
  • "appKey" and "apiKey" are the Reconify values generated when creating the app

Timestamp parameters (optional)

{
"timestamps": {
 "request": 1704758189001,
 "response": 1704758196343
}
}
  • Timestamps are optional, if not passed in, the time the API receives the payload will be used.
  • "request" timestamp when Mistral request made in millisecond format
  • "response" timestamp when Mistral response received in millisecond format. If not present, request will be used for both

Session parameters (optional)

{
"session": "ABCDEF123456",
"sessionTimeout": 10
}
  • Both session parameters are optional
  • "session" an alphanumeric string to indicate the session for grouping interactions
  • "sessionTimeout" is the length of time in minutes to wait for an interaction before ending the current session. The default is 10.

User parameters (optional)

{
"user: {
 "userId": "ABC123",
 "isAuthenticated": 1,
 "firstName": "Jane",
 "lastName": "Doe",
 "email": "some_email",
 "phone": "555-555-5555",
 "gender": "female"
}
}
  • The user object is optional
  • Either "userId" or "email" is required if a user object is sent to track unique users, otherwise users will all be new
  • "userId" is an alphanumeric string unique for the user
  • "isAuthenticated" is optional and can be 1 or 0 to track logged in users
  • "firstName" and "lastName" are optional alphanumeric strings
  • "email" is an optional alphanumeric string, it is used to identify a user if a userId is not present
  • "phone" is optional
  • "gender" is optional

Request parameters (required)

{
"request": {
 "model": "mistral-tiny",
 "messages": [
   { "role": "user", "content" : "tell me a cat joke" }
  ],
 "max_tokens": 200
}
}
  • The request object is the complete JSON sent to Mistral for a Chat
  • Include all the same fields sent to Mistral

Response parameters (required)

{
"response": {
 "id": "cmpl-abcdef1234",
 "object": "chat.completion",
 "created": 1704758196,
 "model": "mistral-tiny",
 "choices": [{
  "index": 0,
  "message" : {
      "role" : "assistant",
      "content" : "Why did the cat sit on the computer keyboard?\n\nHe wanted to purr-use the internet!"
  },
  "finish_reason": "stop"
 }],
 "usage": {
  "prompt_tokens": 13,
  "completion_tokens": 22,
  "total_tokens": 35
 }
  • The response object is the exact JSON data returned from Mistral
  • Include all the same fields received from Mistral

Chat Example

Below is an example JSON to post to the endpoint for a Chat.

{
"reconify": {
 "format": "mistral",
 "type": "chat",
 "version": "2.4.0",
 "appKey": "RECONIFY_APP_KEY",
 "apiKey": "RECONIFY_API_KEY"
},
"timestamps": {
 "request": 1704748161152,
 "response": 1704748168536
},
"user": {
 "userId": "ABC123",
 "firstName": "Jane",
 "lastName": "Doe"
},
"request": {
 "model": "mistral-tiny",
 "messages": [
  { "role" : "user", "content": "Tell me a cat joke" }
 ]
},
"response": {
 "id": "chatcmpl-abcdef",
 "object": "chat.completion",
 "created": 1704748168,
 "model": "mistral-tiny",
 "choices": [{
  "index": 0,
  "message": {
   "role" : "assistant",
   "content" : "Why did the cat sit on the ventilation duct?\n\nTo become a cat-alogue!'' (This one is for the cat lovers who also appreciate a good pun!)",
  },
   "finish_reason": "stop"
 }],
 "usage": {
  "prompt_tokens": 13,
  "completion_tokens": 38,
  "total_tokens": 51
  }
 }
}