mirror of
https://github.com/mintlify/docs.git
synced 2026-09-14 13:35:46 +08:00
2dac5dd1ab
Generated-By: mintlify-agent Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com>
93 lines
2.8 KiB
Plaintext
93 lines
2.8 KiB
Plaintext
---
|
|
title: "Create assistant message (v1)"
|
|
openapi: /discovery-openapi.json POST /v1/assistant/{domain}/message
|
|
tag: "Deprecated"
|
|
keywords: [ "assistant message", "embed", "chat", "integrate", "ai sdk v4" ]
|
|
|
|
---
|
|
<Badge color="orange">Deprecated</Badge>
|
|
|
|
<Info>
|
|
The assistant message v1 endpoint is compatible with **AI SDK v4**. If you use AI SDK v5 or later, use the [assistant message v2 endpoint](/api/assistant/create-assistant-message-v2) 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 v4">
|
|
|
|
```bash
|
|
npm i ai@^4.1.15
|
|
```
|
|
|
|
</Step>
|
|
<Step title="Use the hook">
|
|
|
|
```tsx
|
|
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>
|
|
);
|
|
}
|
|
```
|
|
|
|
**Required configuration for Mintlify:**
|
|
- `streamProtocol: 'data'` - Required for streaming responses.
|
|
- `sendExtraMessageFields: true` - Required to send message metadata.
|
|
- `body.fp` - Fingerprint identifier (use 'anonymous' or a 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.
|
|
- `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.
|
|
|
|
</Step>
|
|
</Steps>
|
|
|
|
See [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) in the AI SDK documentation for more details.
|
|
|
|
## Rate limits
|
|
|
|
The assistant API has the following limits:
|
|
|
|
- 10,000 requests per Mintlify organization per hour
|
|
- 10,000 requests per IP per day
|