TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Jason-AML/MonzaSport-Nextjs/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/chat route powers the Monza Motors AI assistant. On each request it retrieves the full vehicle catalog via getCollections() and the user’s last 20 chat messages from Supabase, then sends that context alongside the new message to Groq’s llama-3.3-70b-versatile model. Once a response is generated, the AI reply is inserted into the messages table with role: 'assistant' — making it immediately visible to the client through its existing Supabase Realtime subscription.
Endpoint
| Property | Value |
|---|---|
| Method | POST |
| Path | /api/chat |
| Auth | Authenticated user required — user_id scopes message history |
| Content-Type | application/json |
Request Body
The authenticated user’s Supabase UUID. Used to filter and persist message history in the
messages table.The user’s message text to send to the AI assistant.
Response
200 OKmessages table. See the note below for details.
500 Internal Server Error
Example Request
Processing Steps
Fetch vehicle catalog
Call
getCollections() to retrieve the full list of vehicles from Supabase. The resulting array is serialised into the AI system prompt as catalog context.Load message history
Query the
messages table for the most recent 20 rows where user_id matches, ordered by created_at ascending. This forms the conversation history passed to the model.Generate AI response
Call
generateText() from the Vercel AI SDK with groq('llama-3.3-70b-versatile') as the model. The call includes a system prompt containing the full vehicle catalog and the conversation history merged with the new user message.Persist AI reply
Insert the generated
text into the messages table with role: 'assistant' and the same user_id. If the insert fails, an error is thrown and a 500 response is returned.System Prompt Context
The system prompt instructs the model to answer only based on the vehicle catalog. Each vehicle entry is formatted as a single colon-delimited line containing the following fields:| Field | Description |
|---|---|
nombre_vehiculo | Vehicle name |
modelo | Model designation |
anio | Model year |
precio | Price in USD |
motor | Engine type / displacement |
poder_hp | Horsepower output |
aceleracion_0_100 | 0–100 km/h acceleration time |
velocidad_maxima | Top speed |
torque_nm | Torque in Newton-metres |
peso_kg | Kerb weight in kilograms |
description | Free-text vehicle description |
The AI response is not returned in the HTTP response body. After inserting the reply into the
messages table, the client’s Supabase Realtime subscription fires and delivers the new row automatically. This design decouples the HTTP response time from the model generation time — the client gets an immediate { ok: true } acknowledgement while the reply streams in through the live database subscription.