Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/gcsconsultores/centros-estrategicos-gcs/llms.txt

Use this file to discover all available pages before exploring further.

The /api/chat route powers Sally’s conversational AI throughout the virtual office. It accepts the current message history and an optional room context object, builds a contextual system prompt from the base SALLY_SYSTEM_PROMPT constant, and streams token-by-token responses from Google Gemini 2.5 Flash using the Vercel AI SDK’s streamText helper. The response is returned as a UIMessageStreamResponse that the client-side useChat hook consumes directly.

Request

PropertyValue
MethodPOST
Path/api/chat
Content-Typeapplication/json

Body Parameters

messages
UIMessage[]
required
The full conversation history in Vercel AI SDK UIMessage format. Each element must carry a role ("user" or "assistant") and a content string. The array is passed through convertToModelMessages() before being forwarded to the model.
context
object
Optional context object that is appended to the system prompt to personalise Sally’s responses for the current session.

Response

A successful call returns a Server-Sent Events stream (text/event-stream) in the Vercel AI SDK UIMessageStream format. The calling component typically consumes this via useChat and never needs to parse the raw stream manually.
PropertyValue
Content-Typetext/event-stream
FormatVercel AI SDK UIMessageStream
On error, the route short-circuits and returns a JSON body instead:
{
  "error": "Error al procesar el mensaje",
  "details": "<error message string>"
}

Configuration

The route calls streamText with the following parameters, exactly as they appear in app/api/chat/route.ts:
const result = streamText({
  model: 'google/gemini-2.5-flash',
  system: systemPrompt,          // SALLY_SYSTEM_PROMPT + context
  messages: await convertToModelMessages(messages),
  maxOutputTokens: 500,
  temperature: 0.7,
  abortSignal: req.signal,
});

return result.toUIMessageStreamResponse();
ParameterValueNotes
modelgoogle/gemini-2.5-flashServed via Vercel AI Gateway
maxOutputTokens500Keeps responses concise for chat UI
temperature0.7Balanced creativity / accuracy
abortSignalreq.signalCancels stream if the client disconnects

System Prompt

Sally’s personality and knowledge base are defined in SALLY_SYSTEM_PROMPT, exported from lib/constants.ts. Before the prompt is sent to the model, the route appends a dynamic context block:
CONTEXTO ACTUAL:
- Sala actual: ${context.currentRoom || 'lobby'}
- Nombre del usuario: ${context.userName || 'Visitante'}
This tells the model which virtual office room the conversation is happening in and how to address the user. When no context is provided, the defaults "lobby" and "Visitante" are used.

Example Request

const response = await fetch('/api/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    messages: [
      {
        role: 'user',
        content: 'Hola Sally, necesito información sobre SARLAFT'
      }
    ],
    context: {
      currentRoom: 'compliance',
      userName: 'María García'
    }
  })
})

Error Responses

StatusDescription
500Error processing the message — Gemini API unavailable or GOOGLE_GEMINI_API_KEY not set
This route requires the GOOGLE_GEMINI_API_KEY environment variable (or a configured Vercel AI Gateway key AI_GATEWAY_API_KEY) to be present at runtime. The Next.js route export maxDuration = 30 caps execution at 30 seconds — the Vercel Hobby / Pro serverless function timeout. Responses that would exceed 500 tokens are cut off by maxOutputTokens.

Build docs developers (and LLMs) love