Skip to content

Commit 30af8bd

Browse files
Update api-reference/assistant/create-assistant-message.mdx
1 parent b4684fa commit 30af8bd

File tree

1 file changed

+77
-3
lines changed

1 file changed

+77
-3
lines changed

api-reference/assistant/create-assistant-message.mdx

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,69 @@
22
openapi: POST /assistant/{domain}/message
33
---
44

5+
The AI Discovery Assistant API provides intelligent, context-aware responses based on your documentation. The API returns responses as a **streaming text response**, allowing you to display answers progressively as they're generated.
6+
7+
## Streaming response
8+
9+
This endpoint returns a **streaming response** using Server-Sent Events (SSE). The response body contains a readable stream that you must process chunk by chunk to receive the complete answer.
10+
11+
### Complete example
12+
13+
Here's a complete example showing how to send a message and handle the streaming response:
14+
15+
```javascript
16+
const domain = process.env.MINTLIFY_DOMAIN!;
17+
const apiKey = process.env.MINTLIFY_API_KEY!;
18+
const userMessage = process.argv.slice(2).join(' ') || 'How do I get started?';
19+
20+
const response = await fetch(`https://api-dsc.mintlify.com/v1/assistant/${domain}/message`, {
21+
method: 'POST',
22+
headers: {
23+
'Authorization': `Bearer ${apiKey}`,
24+
'Content-Type': 'application/json',
25+
},
26+
body: JSON.stringify({
27+
fp: 'user-fingerprint-' + Date.now(),
28+
threadId: 'my-thread-id',
29+
messages: [{
30+
id: 'msg-' + Date.now(),
31+
role: 'user',
32+
content: userMessage,
33+
parts: [{ type: 'text', text: userMessage }]
34+
}],
35+
retrievalPageSize: 5,
36+
filter: null, // { version: "string", language: "string" }
37+
}),
38+
});
39+
40+
// Handle the streaming response
41+
const reader = response.body!.getReader();
42+
const decoder = new TextDecoder();
43+
44+
while (true) {
45+
const { done, value } = await reader.read();
46+
if (done) break;
47+
process.stdout.write(decoder.decode(value, { stream: true }));
48+
}
49+
```
50+
51+
### Key parameters
52+
53+
- **`fp`** - A unique fingerprint to identify the user session
54+
- **`threadId`** - Identifier for the conversation thread to maintain context
55+
- **`messages`** - Array of message objects with `id`, `role`, `content`, and `parts`
56+
- **`retrievalPageSize`** - Number of documentation chunks to retrieve for context (default: 5)
57+
- **`filter`** - Optional filter to limit search to specific versions or languages
58+
59+
### Handling the stream
60+
61+
The response is a readable stream that must be processed using the Streams API:
62+
63+
1. Get a reader from `response.body.getReader()`
64+
2. Create a `TextDecoder` to convert bytes to text
65+
3. Read chunks in a loop until `done` is true
66+
4. Decode each chunk and process the text
67+
568
## Rate limits
669

770
The assistant API has the following limits:
@@ -10,8 +73,19 @@ The assistant API has the following limits:
1073
- 10,000 requests per Mintlify organization per hour
1174
- 10,000 requests per IP per day
1275

13-
## Suggested usage
76+
## Frontend integration
77+
78+
For React applications, use the [useChat hook from ai-sdk](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#usechat) to send requests and handle streaming responses automatically.
1479

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.
80+
You can set `fp`, `threadId`, and `filter` in the `body` field of the options parameter passed to the hook:
1681

17-
You can set `fp`, `threadId`, and `filter` in the `body` field of the options parameter passed to the hook.
82+
```javascript
83+
const { messages, input, handleInputChange, handleSubmit } = useChat({
84+
api: `/api/chat`,
85+
body: {
86+
fp: 'user-fingerprint-123',
87+
threadId: 'conversation-thread-1',
88+
filter: { version: 'v2', language: 'javascript' }
89+
}
90+
});
91+
```

0 commit comments

Comments
 (0)