Skip to main content
POST
/
v1
/
assistant
/
{domain}
/
message
AI 助手消息 v1
curl --request POST \
  --url https://api.mintlify.com/discovery/v1/assistant/{domain}/message \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "fp": "<string>",
  "messages": [
    {
      "id": "foobar",
      "role": "user",
      "content": "how do i get started",
      "parts": [
        {
          "type": "text",
          "text": "How do I get started"
        }
      ]
    }
  ],
  "threadId": null,
  "retrievalPageSize": 5,
  "filter": null,
  "context": [
    {
      "value": "<string>",
      "path": "<string>",
      "elementId": "<string>"
    }
  ],
  "currentPath": "<string>"
}
'
import requests

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

payload = {
    "fp": "<string>",
    "messages": [
        {
            "id": "foobar",
            "role": "user",
            "content": "how do i get started",
            "parts": [
                {
                    "type": "text",
                    "text": "How do I get started"
                }
            ]
        }
    ],
    "threadId": None,
    "retrievalPageSize": 5,
    "filter": None,
    "context": [
        {
            "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)
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    fp: '<string>',
    messages: [
      {
        id: 'foobar',
        role: 'user',
        content: 'how do i get started',
        parts: [{type: 'text', text: 'How do I get started'}]
      }
    ],
    threadId: null,
    retrievalPageSize: 5,
    filter: null,
    context: [{value: '<string>', path: '<string>', elementId: '<string>'}],
    currentPath: '<string>'
  })
};

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

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.mintlify.com/discovery/v1/assistant/{domain}/message",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'fp' => '<string>',
    'messages' => [
        [
                'id' => 'foobar',
                'role' => 'user',
                'content' => 'how do i get started',
                'parts' => [
                                [
                                                                'type' => 'text',
                                                                'text' => 'How do I get started'
                                ]
                ]
        ]
    ],
    'threadId' => null,
    'retrievalPageSize' => 5,
    'filter' => null,
    'context' => [
        [
                '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;
}
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"fp\": \"<string>\",\n  \"messages\": [\n    {\n      \"id\": \"foobar\",\n      \"role\": \"user\",\n      \"content\": \"how do i get started\",\n      \"parts\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"How do I get started\"\n        }\n      ]\n    }\n  ],\n  \"threadId\": null,\n  \"retrievalPageSize\": 5,\n  \"filter\": null,\n  \"context\": [\n    {\n      \"value\": \"<string>\",\n      \"path\": \"<string>\",\n      \"elementId\": \"<string>\"\n    }\n  ],\n  \"currentPath\": \"<string>\"\n}")

	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))

}
HttpResponse<String> response = Unirest.post("https://api.mintlify.com/discovery/v1/assistant/{domain}/message")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"fp\": \"<string>\",\n  \"messages\": [\n    {\n      \"id\": \"foobar\",\n      \"role\": \"user\",\n      \"content\": \"how do i get started\",\n      \"parts\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"How do I get started\"\n        }\n      ]\n    }\n  ],\n  \"threadId\": null,\n  \"retrievalPageSize\": 5,\n  \"filter\": null,\n  \"context\": [\n    {\n      \"value\": \"<string>\",\n      \"path\": \"<string>\",\n      \"elementId\": \"<string>\"\n    }\n  ],\n  \"currentPath\": \"<string>\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.mintlify.com/discovery/v1/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 = "{\n  \"fp\": \"<string>\",\n  \"messages\": [\n    {\n      \"id\": \"foobar\",\n      \"role\": \"user\",\n      \"content\": \"how do i get started\",\n      \"parts\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"How do I get started\"\n        }\n      ]\n    }\n  ],\n  \"threadId\": null,\n  \"retrievalPageSize\": 5,\n  \"filter\": null,\n  \"context\": [\n    {\n      \"value\": \"<string>\",\n      \"path\": \"<string>\",\n      \"elementId\": \"<string>\"\n    }\n  ],\n  \"currentPath\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{}
已废弃
assistant message v1 端点与 AI SDK v4 兼容。若你使用 AI SDK v5 或更高版本,请改用 assistant message v2 端点

useChat 集成

将 AI 助手 API 集成到你的应用中的推荐方式是使用 Vercel 的 AI SDK 提供的 useChat 钩子。
1

安装 AI SDK v4

npm i ai@^4.1.15
2

使用该钩子

import { useChat } from 'ai/react';

function MyComponent({ domain }) {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
    api: `https://api.mintlify.com/discovery/v1/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',
        },
      ],
    },
    streamProtocol: 'data',
    sendExtraMessageFields: true,
  });

  return (
    <div>
      {messages.map((message) => (
        <div key={message.id}>
          {message.role === 'user' ? 'User: ' : 'Assistant: '}
          {message.content}
        </div>
      ))}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={handleInputChange} />
        <button type="submit">Send</button>
      </form>
    </div>
  );
}
Mintlify 的必备配置:
  • streamProtocol: 'data' - 流式响应所必需。
  • sendExtraMessageFields: true - 发送消息 metadata 所必需。
  • body.fp - 指纹标识符 (使用 'anonymous' 或某个用户标识符) 。
  • body.retrievalPageSize - 要使用的搜索结果数量 (推荐:5) 。
可选配置:
  • body.context - 提供给 AI 助手的上下文信息数组。每个 context 对象包含:
    • type - 'code''textSelection' 之一。
    • value - 代码片段或选中的文本内容。
    • elementId (可选) - 包含该 context 的 UI 元素的标识符。
  • body.currentPath - 用户当前正在查看页面的路径。提供后,AI 助手会利用该上下文提供更相关的回答。最大长度:200 个字符。
在 AI SDK 文档中查看 useChat 以了解更多详情。

速率限制

AI 助手 API 的限制如下:
  • 每个 Mintlify 组织每小时最多 10,000 次请求
  • 每个 IP 每日最多 10,000 次请求

Authorizations

Authorization
string
header
required

Authorization 请求头需要携带 Bearer 令牌。请使用以 mint_dsc_ 为前缀的 AI 助手 API 密钥。它是一个可以安全用于客户端代码的公用密钥。你可以在控制台的 API 密钥页面 中生成它。

Path Parameters

domain
string
required

在你的 domain.mintlify.app URL 中使用的 domain 标识符。你可以在控制台 URL 的末尾找到它。例如,在 dashboard.mintlify.com/organization/domain 中,domain 标识符为 domain

Body

application/json
fp
string
required

用于会话跟踪的指纹标识符。对匿名用户使用 anonymous,或提供唯一的用户标识符。

messages
object[]
required

会话中的消息数组。在前端,你通常会希望使用 @ai-sdk 包中 useChat 钩子提供的 handleSubmit 函数来追加用户消息并处理流式响应,而不是在这个数组里手动定义对象,因为这些对象包含的参数非常多。

threadId
string

一个可选的标识符,用于在多条消息之间保持会话的连续性。提供该标识符后,系统可以将后续消息关联到同一个会话线程。当 event.type === 'finish' 时,响应中会通过 event.threadId 字段返回该 threadId。

retrievalPageSize
number
default:5

用于生成回复的文档搜索结果数量。数值越高可提供的上下文越多,但可能增加响应时间。推荐值:5。

filter
object

用于搜索的可选筛选条件。

context
object[]

用于传递给 AI 助手的可选上下文信息数组。

currentPath
string

用户当前正在查看的页面路径。若提供,AI 助手会利用该上下文给出更相关的回答。最大长度:200 个字符。

Response

200 - application/json

消息生成成功。

响应对象,其中的数据流部分会根据指定的状态码、响应头和内容进行格式化。更多信息请参阅 AI SDK 文档:ai-sdk.dev/docs/ai-sdk-ui/streaming-data。使用 AI SDK 提供的 useChat Hook 来处理响应流。