Skip to main content

Chat with AI assistant

POST /v1/ai/chat

Send messages to the AI assistant with trip and page context.

Request

Authentication: Required (JWT token) Headers:
  • Content-Type: application/json
  • Authorization: Bearer <token>
Body parameters:
tripId
string
required
Trip ID the conversation belongs to
pageKey
string
required
Current page context (e.g., "flights", "transit", "finance", "itinerary", "overview")
pageContext
object
Additional page-specific context data
messages
array
required
Array of chat messages
refresh
boolean
default:"false"
Whether to fetch real-time context (flight status, transit options, etc.)

Response

ok
boolean
required
Request success status
data
object
Chat response data
error
string
Error message if ok is false

Example request

curl -X POST http://localhost:8080/v1/ai/chat \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "tripId": "trip_abc123",
    "pageKey": "flights",
    "pageContext": {},
    "messages": [
      {
        "role": "user",
        "content": "What is the status of flight AA123 on 2026-03-15?"
      }
    ],
    "refresh": true
  }'

Example response

{
  "ok": true,
  "data": {
    "conversationId": "conv_xyz789",
    "answer": "Flight AA123 on March 15, 2026 departs from JFK at 8:00 AM and arrives at LAX at 11:30 AM local time. The flight duration is 6 hours 30 minutes with no stops. Departure is from Terminal 8 Gate 12, and arrival is at Terminal 4 Gate 42.",
    "highlights": [
      "Read-only guidance generated from current trip context",
      "Page-aware reasoning for flights"
    ],
    "suggestedActions": [
      "Share exact flight number and date for live status",
      "Compare price-time tradeoff before selecting"
    ],
    "sources": [
      {
        "name": "next_flight_status",
        "status": "ok",
        "fetchedAt": "2026-03-02T14:30:00Z",
        "detail": ""
      }
    ],
    "degraded": false
  }
}

Example request (transit context)

curl -X POST http://localhost:8080/v1/ai/chat \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "tripId": "trip_abc123",
    "pageKey": "transit",
    "pageContext": {},
    "messages": [
      {
        "role": "user",
        "content": "How do I get from Times Square to Brooklyn Bridge?"
      }
    ],
    "refresh": true
  }'

Page-aware context

The assistant fetches real-time data based on pageKey when refresh is true:
  • flights: Extracts flight number and date from message, calls /api/flights/status
  • transit: Extracts origin/destination from message (“from X to Y” format), calls /api/transit/suggest
  • finance: Uses trip database for expense totals and budget data
  • itinerary: Uses trip database for daily activities and timeline
  • overview: Generic trip context with destination and dates

Error responses

ok
boolean
false when error occurs
error
string
Error description
Status codes:
  • 400 - Invalid input (missing tripId, pageKey, or messages)
  • 403 - Unauthorized trip access
  • 500 - Internal server error

Build docs developers (and LLMs) love