与 useChat 集成
useChat 钩子是将 AI 助手 API 集成到你的应用中的推荐方式。
安装 AI SDK v4
使用该钩子
streamProtocol: 'data'- 启用流式响应所必需。sendExtraMessageFields: true- 发送消息 metadata 所必需。body.fp- 指纹标识符(使用'anonymous'或某个用户标识符)。body.retrievalPageSize- 要使用的搜索结果数量(推荐:5)。
速率限制
- 每个 key 每月最多使用 10,000 次
- 每个 Mintlify 组织每小时最多 10,000 次请求
- 每个 IP 每日最多 10,000 次请求
Authorizations
The Authorization header expects a Bearer token. See the Assistant API Key documentation for details on how to get your API key.
Path Parameters
The domain identifier from your domain.mintlify.app URL. Can be found at the end of your dashboard URL. For example, dashboard.mintlify.com/organization/domain has a domain identifier of domain.
Body
Fingerprint identifier for tracking conversation sessions. Use 'anonymous' for anonymous users or provide a unique user identifier.
Array of messages in the conversation. On the frontend, you will likely want to use the handleSubmit function from the @ai-sdk package's useChat hook to append user messages and handle streaming responses, rather than manually defining the objects in this array as they have so many parameters.
An optional identifier used to maintain conversation continuity across multiple messages. When provided, it allows the system to associate follow-up messages with the same conversation thread. The threadId is returned in the response as event.threadId when event.type === 'finish'.
Number of documentation search results to use for generating the response. Higher values provide more context but may increase response time. Recommended: 5.
Optional filter criteria for the search
Response
Message generated successfully
Response object that streams formatted data stream parts with the specified status, headers, and content. This matches what is expected from the AI SDK as documented at ai-sdk.dev/docs/ai-sdk-ui/streaming-data. Instead of writing your own parser, it is recommended to use the useChat hook from ai-sdk as documented here.