Skip to main content
Mintlify
current

Search documentation

Type to search this documentation.

On this pageOverview

Create assistant message

Generates a response message from the assistant for the specified domain. Compatible with AI SDK v5+.

Authenticate with an assistant API key.

The useChat hook from Vercel's AI SDK is the recommended way to integrate the assistant API into your application.

  1. Install AI SDK

    Bash
    npm i ai@^6 @ai-sdk/react
  2. Use the hook

    TSX
    import { useState } from "react";
    import { useChat } from "@ai-sdk/react";
    import { DefaultChatTransport } from "ai";
    
    function MyComponent({ domain }) {
      const [input, setInput] = useState("");
    
      const { messages, sendMessage } = useChat({
        transport: new DefaultChatTransport({
          api: `https://api.mintlify.com/discovery/v2/assistant/${domain}/message`,
          headers: {
            Authorization: `Bearer ${process.env.PUBLIC_MINTLIFY_ASSISTANT_KEY}`,
          },
          body: {
            fp: "anonymous",
            retrievalPageSize: 5,
            context: [
              {
                type: "code",
                value: 'const example = "code snippet";',
                elementId: "code-block-1",
              },
            ],
          },
        }),
      });
    
      return (
        <div>
          {messages.map((message) => (
            <div key={message.id}>
              {message.role === "user" ? "User: " : "Assistant: "}
              {message.parts
                .filter((part) => part.type === "text")
                .map((part) => part.text)
                .join("")}
            </div>
          ))}
          <form
            onSubmit={(e) => {
              e.preventDefault();
              if (input.trim()) {
                sendMessage({ text: input });
                setInput("");
              }
            }}
          >
            <input value={input} onChange={(e) => setInput(e.target.value)} />
            <button type="submit">Send</button>
          </form>
        </div>
      );
    }

    Required configuration:

    • transport - Use DefaultChatTransport to configure the API connection.
    • body.fp - Fingerprint identifier (use 'anonymous' or a unique user identifier).
    • body.retrievalPageSize - Number of search results to use (recommended: 5).

    Optional configuration:

    • body.context - Array of contextual information to provide to the assistant. Each context object contains:
      • type - Either 'code' or 'textSelection'.
      • value - The code snippet or selected text content.
      • path (optional) - Path to the source file or page.
      • elementId (optional) - Identifier for the UI element containing the context.
    • body.currentPath - The path of the page the user is currently viewing. When provided, the assistant uses this context to provide more relevant answers. Maximum length: 200 characters.

See useChat and Transport in the AI SDK documentation for more details.

The assistant API has the following limits:

  • 10,000 requests per Mintlify organization per hour
  • 10,000 requests per IP per day

Related topics

POST /v2/assistant/{domain}/message

cURL
curl --request POST \
  --url https://api.mintlify.com/discovery/v2/assistant/{domain}/message \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "fp": "<string>",
  "threadId": "<string>",
  "messages": [
    {
      "id": "<string>",
      "role": "system",
      "createdAt": "<string>",
      "parts": [
        null
      ],
      "metadata": {}
    }
  ],
  "retrievalPageSize": 123,
  "filter": {
    "version": "<string>",
    "language": "<string>",
    "groups": [
      "<string>"
    ]
  },
  "context": [
    {
      "type": "code",
      "value": "<string>",
      "path": "<string>",
      "elementId": "<string>"
    }
  ],
  "currentPath": "<string>"
}'
Python
import requests

url = "https://api.mintlify.com/discovery/v2/assistant/{domain}/message"

payload = {
  "fp": "<string>",
  "threadId": "<string>",
  "messages": [
    {
      "id": "<string>",
      "role": "system",
      "createdAt": "<string>",
      "parts": [
        None
      ],
      "metadata": {}
    }
  ],
  "retrievalPageSize": 123,
  "filter": {
    "version": "<string>",
    "language": "<string>",
    "groups": [
      "<string>"
    ]
  },
  "context": [
    {
      "type": "code",
      "value": "<string>",
      "path": "<string>",
      "elementId": "<string>"
    }
  ],
  "currentPath": "<string>"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
JavaScript
const options = {method: "POST", headers: {"Authorization": "Bearer <token>", "Content-Type": "application/json"}, body: JSON.stringify({
  "fp": "<string>",
  "threadId": "<string>",
  "messages": [
    {
      "id": "<string>",
      "role": "system",
      "createdAt": "<string>",
      "parts": [
        null
      ],
      "metadata": {}
    }
  ],
  "retrievalPageSize": 123,
  "filter": {
    "version": "<string>",
    "language": "<string>",
    "groups": [
      "<string>"
    ]
  },
  "context": [
    {
      "type": "code",
      "value": "<string>",
      "path": "<string>",
      "elementId": "<string>"
    }
  ],
  "currentPath": "<string>"
})};

fetch("https://api.mintlify.com/discovery/v2/assistant/{domain}/message", options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.mintlify.com/discovery/v2/assistant/{domain}/message",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"fp\":\"<string>\",\"threadId\":\"<string>\",\"messages\":[{\"id\":\"<string>\",\"role\":\"system\",\"createdAt\":\"<string>\",\"parts\":[null],\"metadata\":{}}],\"retrievalPageSize\":123,\"filter\":{\"version\":\"<string>\",\"language\":\"<string>\",\"groups\":[\"<string>\"]},\"context\":[{\"type\":\"code\",\"value\":\"<string>\",\"path\":\"<string>\",\"elementId\":\"<string>\"}],\"currentPath\":\"<string>\"}",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.mintlify.com/discovery/v2/assistant/{domain}/message"

	payload := strings.NewReader("{\"fp\":\"<string>\",\"threadId\":\"<string>\",\"messages\":[{\"id\":\"<string>\",\"role\":\"system\",\"createdAt\":\"<string>\",\"parts\":[null],\"metadata\":{}}],\"retrievalPageSize\":123,\"filter\":{\"version\":\"<string>\",\"language\":\"<string>\",\"groups\":[\"<string>\"]},\"context\":[{\"type\":\"code\",\"value\":\"<string>\",\"path\":\"<string>\",\"elementId\":\"<string>\"}],\"currentPath\":\"<string>\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
Java
HttpResponse<String> response = Unirest.post("https://api.mintlify.com/discovery/v2/assistant/{domain}/message")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\"fp\":\"<string>\",\"threadId\":\"<string>\",\"messages\":[{\"id\":\"<string>\",\"role\":\"system\",\"createdAt\":\"<string>\",\"parts\":[null],\"metadata\":{}}],\"retrievalPageSize\":123,\"filter\":{\"version\":\"<string>\",\"language\":\"<string>\",\"groups\":[\"<string>\"]},\"context\":[{\"type\":\"code\",\"value\":\"<string>\",\"path\":\"<string>\",\"elementId\":\"<string>\"}],\"currentPath\":\"<string>\"}")
  .asString();
Ruby
require 'uri'
require 'net/http'

url = URI("https://api.mintlify.com/discovery/v2/assistant/{domain}/message")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\"fp\":\"<string>\",\"threadId\":\"<string>\",\"messages\":[{\"id\":\"<string>\",\"role\":\"system\",\"createdAt\":\"<string>\",\"parts\":[null],\"metadata\":{}}],\"retrievalPageSize\":123,\"filter\":{\"version\":\"<string>\",\"language\":\"<string>\",\"groups\":[\"<string>\"]},\"context\":[{\"type\":\"code\",\"value\":\"<string>\",\"path\":\"<string>\",\"elementId\":\"<string>\"}],\"currentPath\":\"<string>\"}"

response = http.request(request)
puts response.read_body
200
{}
Authorizationstringrequired

The Authorization header expects a Bearer token. Use an assistant API key. Generate one on the API keys page in your dashboard. In production, proxy requests through your backend rather than embedding the key in client-side code.

domainstringrequired

The domain identifier from your domain.mintlify.site URL. Can be found at the end of your dashboard URL. For example, app.mintlify.com/organization/domain has a domain identifier of domain.

Typestring
fpstringrequired

Fingerprint identifier for tracking conversation sessions. Use anonymous for anonymous users or provide a unique user identifier.

Typestring
threadId?string

An optional identifier used to maintain conversation continuity across multiple messages. When provided, it allows the system to associate follow-up messages with the same conversation thread. The threadId is returned in the response as event.threadId when event.type === 'finish'.

Typestring
Defaultnull
messagesobject[]required

Array of messages in the conversation. Use the handleSubmit function from the @ai-sdk/react package's useChat hook to manage messages and streaming responses.

Typeobject[]
Default['id':'foobar','role':'user','parts':['type':'text','text':'How do I get started']]
Show child attributes
idstringrequired

Unique identifier for the message.

Typestring
roleenum<string>required

The role of the message sender.

Available options: system, assistant, user

Typeenum<string>
createdAt?string

Timestamp when the message was created.

Typestring
partsobject[]required

Array of message parts. Each part has a type and type-specific fields.

Typeobject[]
Show child attributes
typeenum<string>required

Available options: text

Typeenum<string>
textstringrequired
metadata?object

Optional metadata associated with the message.

Typeobject
retrievalPageSize?number

Number of documentation search results to use for generating the response. Higher values provide more context but may increase response time. Recommended: 5.

Typenumber
Default5
filter?object

Optional filter criteria for the search.

Typeobject
Defaultnull
Show child attributes
version?string

Optional version filter.

Typestring
language?string

Optional language filter.

Typestring
groups?string[]

Optional array of group identifiers to filter results.

Typestring[]
context?object[]

Optional array of contextual information to provide to the assistant.

Typeobject[]
Show child attributes
typeenum<string>required

The type of context being provided.

Available options: code, textSelection

Typeenum<string>
valuestringrequired

The code snippet or selected text content.

Typestring
path?string

Optional path to the source file or page.

Typestring
elementId?string

Optional identifier for the UI element containing the context.

Typestring
currentPath?string

The path of the page the user is currently viewing. When provided, the assistant uses this context to provide more relevant answers. Maximum length: 200 characters.

Typestring

200 — Message generated successfully

response?object

Streaming response compatible with AI SDK v5. Use the useChat hook from @ai-sdk/react to handle the response stream.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu