Skip to content

Commit 9bf76e7

Browse files
authored
Add useChat quickstart to assistant message API page (#1738)
* fix capitalization * add useChat example * add messages placeholder * fix split string
1 parent 81887be commit 9bf76e7

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

api/assistant/create-assistant-message.mdx

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,65 @@
22
openapi: POST /assistant/{domain}/message
33
---
44

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+
560
## Rate limits
661

762
The assistant API has the following limits:
863

964
- 10,000 uses per key per month
1065
- 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

docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
]
276276
},
277277
{
278-
"tab": "API Reference",
278+
"tab": "API reference",
279279
"groups": [
280280
{
281281
"group": "API reference",

0 commit comments

Comments
 (0)