Mersi

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

FieldTypeRequiredDescription
messagesarrayYesAt least one message (see format below). Must have role and content.
sessionIdUUIDNoExisting 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 OKtext/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:

HeaderValue
Content-Typetext/event-stream
X-Session-IdUUID of the chat session

Errors

StatusCodeCause
400VALIDATION_ERRORmessages is empty or malformed
401UNAUTHORIZEDMissing or invalid JWT
403ONBOARDING_INCOMPLETEOnboarding not finished
403SessionOwnershipErrorsessionId belongs to a different user
404SessionNotFoundsessionId 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 sessionId is omitted, a new chat_sessions row is created and its UUID is returned in X-Session-Id.
  • All messages (user + assistant, including tool calls and results) are persisted as chat_messages rows with parts stored 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?

On this page