AI 助手
创建 assistant 消息
针对指定的 domain,从 AI 助手生成一条回复消息。适用于 AI SDK v5 及更高版本。
POST
/
v2
/
assistant
/
{domain}
/
message
AI 助手的消息
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>",
"messages": [
{
"id": "foobar",
"role": "user",
"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/v2/assistant/{domain}/message"
payload = {
"fp": "<string>",
"messages": [
{
"id": "foobar",
"role": "user",
"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',
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/v2/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/v2/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',
'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/v2/assistant/{domain}/message"
payload := strings.NewReader("{\n \"fp\": \"<string>\",\n \"messages\": [\n {\n \"id\": \"foobar\",\n \"role\": \"user\",\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/v2/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 \"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/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 = "{\n \"fp\": \"<string>\",\n \"messages\": [\n {\n \"id\": \"foobar\",\n \"role\": \"user\",\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 消息 v2 端点兼容 AI SDK v5+。如果你正在使用 AI SDK v4,请改用 assistant 消息 v1 端点。
与 useChat 集成
useChat hook 是在你的应用程序中集成 assistant API 的推荐方式。
使用 hook
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>
);
}
transport- 使用DefaultChatTransport来配置 API 连接。body.fp- 指纹标识符 (使用'anonymous'或唯一的用户标识符) 。body.retrievalPageSize- 要使用的搜索结果数量 (推荐:5) 。
body.context- 提供给 AI 助手的上下文信息数组。每个 context 对象包含:type-'code'或'textSelection'之一。value- 代码片段或选中的文本内容。path(可选) - 源文件或页面的路径。elementId(可选) - 包含该 context 的 UI 元素标识符。
body.currentPath- 用户当前正在查看页面的路径。提供该字段时,AI 助手会利用此 context 提供更相关的回答。最大长度:200 个字符。
速率限制
- 每个 Mintlify 组织每小时最多 10,000 个请求
- 每个 IP 地址每天最多 10,000 个请求
授权
路径参数
来自你的 domain.mintlify.site URL 中的 domain 标识符。你可以在控制台 URL 的末尾找到它。例如,在 dashboard.mintlify.com/organization/domain 中,domain 标识符是 domain。
请求体
application/json
用于跟踪会话的指纹标识符。对匿名用户使用 anonymous,或提供一个唯一的用户标识符。
会话中的消息数组。使用 @ai-sdk/react 包中的 useChat 钩子提供的 handleSubmit 函数来管理消息和流式响应。
Show child attributes
Show child attributes
一个可选的标识符,用于在多条消息之间保持会话的连续性。提供该值后,系统会将后续消息关联到同一个会话线程。当 event.type === 'finish' 时,响应中会在 event.threadId 字段返回该 threadId。
用于生成回答时检索的文档搜索结果数量。数值越高,可用的上下文越多,但可能增加响应时间。推荐值:5。
用于搜索的可选筛选条件。
Show child attributes
Show child attributes
提供给 AI 助手的可选上下文信息数组。
Show child attributes
Show child attributes
用户当前正在查看的页面路径。若提供,AI 助手会利用该上下文给出更相关的回答。最大长度:200 个字符。
响应
200 - application/json
消息已成功生成
与 AI SDK v5 兼容的流式响应。使用 @ai-sdk/react 中的 useChat 钩子 来处理响应流。
⌘I
AI 助手的消息
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>",
"messages": [
{
"id": "foobar",
"role": "user",
"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/v2/assistant/{domain}/message"
payload = {
"fp": "<string>",
"messages": [
{
"id": "foobar",
"role": "user",
"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',
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/v2/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/v2/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',
'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/v2/assistant/{domain}/message"
payload := strings.NewReader("{\n \"fp\": \"<string>\",\n \"messages\": [\n {\n \"id\": \"foobar\",\n \"role\": \"user\",\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/v2/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 \"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/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 = "{\n \"fp\": \"<string>\",\n \"messages\": [\n {\n \"id\": \"foobar\",\n \"role\": \"user\",\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{}