Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions api/assistant/create-assistant-message.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,65 @@
openapi: POST /assistant/{domain}/message
---

## Integration with `useChat`

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).

Check warning on line 7 in api/assistant/create-assistant-message.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

api/assistant/create-assistant-message.mdx#L7

Use 'app' instead of 'application'.

<Steps>
<Step title="Install the AI SDK">

```bash
npm i ai
```

</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-dsc.mintlify.com/v1/assistant/${domain}/message`,
headers: {
'Authorization': `Bearer ${process.env.MINTLIFY_TOKEN}`,
},
body: {
fp: 'anonymous',
messages: [
{ role: 'user', content: 'What is this documentation about?' }
]
},
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>
);
}
```

</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 uses per key per month
- 10,000 requests per Mintlify organization per hour
- 10,000 requests per IP per day

## Suggested usage

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.

You can set `fp`, `threadId`, and `filter` in the `body` field of the options parameter passed to the hook.
- 10,000 requests per IP per day
2 changes: 1 addition & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
]
},
{
"tab": "API Reference",
"tab": "API reference",
"groups": [
{
"group": "API reference",
Expand Down