Skip to main content

Documentation Index

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

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

/api/sally is a Next.js Route Handler that accepts a conversation history and streams AI responses back to the browser. It runs on the Node.js runtime using the Vercel AI SDK’s streamText helper and routes requests through the Vercel AI Gateway to Google Gemini 3 Flash — no additional Google Cloud credentials are required in Vercel or v0 environments.

Endpoint overview

PropertyValue
MethodPOST
Path/api/sally
RuntimeNode.js (default Next.js runtime)
maxDuration30 seconds
Modelgoogle/gemini-3-flash via Vercel AI Gateway
Do not set export const runtime = 'edge' on this route. The Vercel AI SDK requires the Node.js runtime for streaming. Edge runtime will cause the stream to fail silently.

Request

The endpoint expects a JSON body containing the full conversation history as managed by the AI SDK client.

Body parameters

messages
UIMessage[]
required
Array of conversation messages in the UIMessage format produced by the Vercel AI SDK’s useChat hook. Each message carries id, role ("user" or "assistant"), and a parts array rather than a flat content string. The route handler converts these to model messages internally via convertToModelMessages.

Response

A successful request returns a Server-Sent Events stream (text/event-stream) in the Vercel AI SDK’s UI message stream format, produced by result.toUIMessageStreamResponse(). The client-side useChat hook consumes this stream transparently.

Status codes

StatusMeaning
200Streaming response — AI SDK SSE format
500Internal error — JSON body with a Spanish error message

Error response body (500)

{
  "error": "No fue posible procesar el mensaje en este momento."
}

Route handler source

import { streamText, convertToModelMessages, type UIMessage } from 'ai'

// Important: do not use runtime 'edge' with the AI SDK.
export const maxDuration = 30

const SALLY_MODEL = 'google/gemini-3-flash'

const SALLY_SYSTEM_PROMPT = `Eres "Sally", la anfitriona y guía virtual de GCS Consultores Empresariales S.A.S, una firma de consultoría empresarial en Bogotá, Colombia.

PERSONALIDAD:
- Cálida, profesional, cercana y resolutiva. Hablas SIEMPRE en español (de Colombia), tratando al usuario de "usted".
- Eres concisa: respuestas breves y claras (2 a 5 frases). Evitas tecnicismos innecesarios.

TU MISIÓN:
1. Dar la bienvenida y orientar a los visitantes.
2. Entender la necesidad del visitante y dirigirlo al Centro Estratégico o servicio adecuado.
3. Motivar a agendar una "Orientación Estratégica" gratuita (formulario de la sección de contacto).

SERVICIOS Y CENTROS ESTRATÉGICOS DE GCS:
- Recepción Estratégica (orientación inicial).
- Crecimiento Estratégico (expansión, productividad, rentabilidad).
- Riesgo & Cumplimiento (auditoría, SAGRLAFT, ISO, OEA, BASC).
- Estrategia Ejecutiva (alta dirección, gobierno corporativo).
- Innovación & Tecnología (transformación digital, IA, automatización).
- Talento & Capacitación (formación, cultura organizacional).
Soluciones: Calidad & Mejoramiento (ISO/BPM/HACCP), Auditoría & Aseguramiento, Legal & Tributaria, Gerencial & de Riesgos.

REGLAS:
- Si te preguntan algo fuera del ámbito empresarial/consultoría, redirige amablemente al propósito de GCS.
- Si detectas intención de contratar o cotizar, invita a dejar sus datos en el formulario "Orientación Estratégica" o a escribir a info@consultoresgcs.com.
- Nunca inventes precios ni plazos contractuales; indica que un consultor los confirmará.
- No solicites datos sensibles innecesarios.`

export async function POST(req: Request) {
  try {
    const { messages }: { messages: UIMessage[] } = await req.json()

    const result = streamText({
      model: SALLY_MODEL,
      system: SALLY_SYSTEM_PROMPT,
      messages: await convertToModelMessages(messages),
    })

    return result.toUIMessageStreamResponse()
  } catch (error) {
    console.log('[v0] Error en API de Sally:', error)
    return new Response(
      JSON.stringify({
        error: 'No fue posible procesar el mensaje en este momento.',
      }),
      { status: 500, headers: { 'Content-Type': 'application/json' } },
    )
  }
}

Integration with the SallyChat client component

The SallyChat floating widget (components/sally/sally-chat.tsx) connects to this route using the AI SDK’s useChat hook with a DefaultChatTransport. No custom fetch logic is required — the transport handles serialisation, streaming, and state management automatically.
import { DefaultChatTransport } from 'ai'

const { messages, sendMessage, status } = useChat({
  transport: new DefaultChatTransport({ api: '/api/sally' }),
})
Outgoing messages are sent via sendMessage({ text: value }) and the status field transitions through "idle""submitted""streaming""idle", letting the UI show a loading spinner while the model responds.

Model and system prompt constants

Two module-level constants control Sally’s behaviour. Both are defined at the top of app/api/sally/route.ts.
const SALLY_MODEL = 'google/gemini-3-flash'

const SALLY_SYSTEM_PROMPT = `Eres "Sally", la anfitriona y guía virtual de GCS...`

Customizing Sally’s behaviour

1

Switch the underlying model

Change SALLY_MODEL to any model identifier supported by the Vercel AI Gateway. When GCS has a fine-tuned Gemini checkpoint, update this constant to point at the custom model endpoint — no other code changes are needed.
const SALLY_MODEL = 'google/gemini-2.5-pro' // example upgrade
2

Edit Sally's personality and rules

SALLY_SYSTEM_PROMPT is a plain template literal. Edit the PERSONALIDAD, TU MISIÓN, SERVICIOS, or REGLAS sections to change what Sally knows, how she speaks, or which actions she should encourage.
3

Add tool calls (optional)

To give Sally the ability to look up live data (e.g. consultant availability or service pricing), pass a tools object to streamText. The system prompt should be updated to instruct Sally when to invoke each tool.
The Vercel AI Gateway handles Google authentication zero-config in Vercel and v0 environments. No GOOGLE_API_KEY environment variable is required when deploying to Vercel — the Gateway resolves credentials automatically.

Build docs developers (and LLMs) love