|
2 | 2 | openapi: POST /assistant/{domain}/message |
3 | 3 | --- |
4 | 4 |
|
| 5 | +## Integration with `useChat` |
| 6 | + |
| 7 | +The recommended way to integrate the assistant API into your application is with the `useChat` hook from [Vercel's AI SDK](https://sdk.vercel.ai/docs). |
| 8 | + |
| 9 | +<Steps> |
| 10 | +<Step title="Install the AI SDK"> |
| 11 | + |
| 12 | +```bash |
| 13 | +npm i ai |
| 14 | +``` |
| 15 | + |
| 16 | +</Step> |
| 17 | +<Step title="Use the hook"> |
| 18 | + |
| 19 | +```tsx |
| 20 | +import { useChat } from 'ai/react'; |
| 21 | + |
| 22 | +function MyComponent({ domain }) { |
| 23 | + const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({ |
| 24 | + api: `https://api-dsc.mintlify.com/v1/assistant/${domain}/message`, |
| 25 | + headers: { |
| 26 | + 'Authorization': `Bearer ${process.env.MINTLIFY_TOKEN}`, |
| 27 | + }, |
| 28 | + body: { |
| 29 | + fp: 'anonymous', |
| 30 | + messages: [ |
| 31 | + { role: 'user', content: 'What is this documentation about?' } |
| 32 | + ] |
| 33 | + }, |
| 34 | + streamProtocol: 'data', |
| 35 | + sendExtraMessageFields: true, |
| 36 | + }); |
| 37 | + |
| 38 | + return ( |
| 39 | + <div> |
| 40 | + {messages.map((message) => ( |
| 41 | + <div key={message.id}> |
| 42 | + {message.role === 'user' ? 'User: ' : 'Assistant: '} |
| 43 | + {message.content} |
| 44 | + </div> |
| 45 | + ))} |
| 46 | + <form onSubmit={handleSubmit}> |
| 47 | + <input value={input} onChange={handleInputChange} /> |
| 48 | + <button type="submit">Send</button> |
| 49 | + </form> |
| 50 | + </div> |
| 51 | + ); |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +</Step> |
| 56 | +</Steps> |
| 57 | + |
| 58 | +See [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) in the AI SDK documentation for more details. |
| 59 | + |
5 | 60 | ## Rate limits |
6 | 61 |
|
7 | 62 | The assistant API has the following limits: |
8 | 63 |
|
9 | 64 | - 10,000 uses per key per month |
10 | 65 | - 10,000 requests per Mintlify organization per hour |
11 | | -- 10,000 requests per IP per day |
12 | | - |
13 | | -## Suggested usage |
14 | | - |
15 | | -For best results, use the [useChat hook from ai-sdk](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#usechat) to send requests and handle responses. |
16 | | - |
17 | | -You can set `fp`, `threadId`, and `filter` in the `body` field of the options parameter passed to the hook. |
| 66 | +- 10,000 requests per IP per day |
0 commit comments