Chat
Streaming ReAct agent endpoint — product search, cart management, and checkout tools.
Requires a valid crossmint-jwt cookie and completed onboarding (onboardingStep === 3). Rate-limited at 30 req/min per user.
POST /api/chat
Send messages to the AI shopping assistant. Returns a Server-Sent Events (SSE) stream in Vercel AI SDK UIMessageStream format.
Auth required: Yes + onboarding complete
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
messages | array | Yes | At least one message (see format below). Must have role and content. |
sessionId | UUID | No | Existing session to continue. Omit to auto-create a new session. |
{
"messages": [
{ "role": "user", "content": "Find me a blue denim jacket under $100" }
],
"sessionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}The messages array accepts the Vercel AI SDK UIMessage format. The last message's content is the new user turn; previous messages form the context.
Response 200 OK — text/event-stream
The response is a streaming SSE body in Vercel AI SDK UIMessageStream format. The X-Session-Id response header contains the session UUID (useful when no sessionId was passed).
data: {"type":"text-delta","textDelta":"Here are some "}
data: {"type":"text-delta","textDelta":"options I found:"}
data: {"type":"tool-call","toolCallId":"tc_1","toolName":"searchProducts","args":{"query":"blue denim jacket"}}
data: {"type":"tool-result","toolCallId":"tc_1","toolName":"searchProducts","result":{"products":[...]}}
data: {"type":"finish","finishReason":"stop"}Response headers include:
| Header | Value |
|---|---|
Content-Type | text/event-stream |
X-Session-Id | UUID of the chat session |
Errors
| Status | Code | Cause |
|---|---|---|
| 400 | VALIDATION_ERROR | messages is empty or malformed |
| 401 | UNAUTHORIZED | Missing or invalid JWT |
| 403 | ONBOARDING_INCOMPLETE | Onboarding not finished |
| 403 | SessionOwnershipError | sessionId belongs to a different user |
| 404 | SessionNotFound | sessionId does not exist |
curl Example
curl -b cookies.txt \
-X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"messages": [
{ "role": "user", "content": "Show me running shoes in size 10 under $120" }
]
}'Agent Tools
The agent runs up to 5 reasoning steps (stopWhen: stepCountIs(5)). Available tools:
Session Persistence
- If
sessionIdis omitted, a newchat_sessionsrow is created and its UUID is returned inX-Session-Id. - All messages (user + assistant, including tool calls and results) are persisted as
chat_messagesrows withpartsstored as JSONB. - On the first exchange, the server auto-generates a session title via a second LLM call.
- User shopping preferences stored in MemWal are injected into the system prompt automatically.
- Retrieve and continue sessions via the Sessions API.
How is this guide?