mirror of
https://github.com/mintlify/docs.git
synced 2026-09-14 13:35:46 +08:00
731ca85682
title
118 lines
3.1 KiB
Plaintext
118 lines
3.1 KiB
Plaintext
---
|
|
tag: "Latest"
|
|
openapi: /discovery-openapi.json POST /v2/assistant/{domain}/message
|
|
keywords:
|
|
[
|
|
"assistant message",
|
|
"embed",
|
|
"chat",
|
|
"integrate",
|
|
"v2",
|
|
"ai sdk v5",
|
|
"ai sdk v6",
|
|
]
|
|
---
|
|
|
|
<Info>
|
|
The assistant message v2 endpoint is compatible with **AI SDK v5+**. If you
|
|
use AI SDK v4, use the [assistant message v1
|
|
endpoint](/api-reference/assistant/create-assistant-message) instead.
|
|
</Info>
|
|
|
|
## Integration with `useChat`
|
|
|
|
The `useChat` hook from Vercel's AI SDK is the recommended way to integrate the assistant API into your application.
|
|
|
|
<Steps>
|
|
<Step title="Install AI SDK">
|
|
|
|
```bash
|
|
npm i ai@^6 @ai-sdk/react
|
|
```
|
|
|
|
</Step>
|
|
<Step title="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.
|
|
|
|
</Step>
|
|
</Steps>
|
|
|
|
See [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) and [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) in the AI SDK documentation for more details.
|
|
|
|
## Rate limits
|
|
|
|
The assistant API has the following limits:
|
|
|
|
- 10,000 uses per key per month
|
|
- 10,000 requests per Mintlify organization per hour
|
|
- 10,000 requests per IP per day
|