curl --request POST \
--url https://api.example.com/api/chat/stream \
--header 'Content-Type: application/json' \
--data '
{
"message": "<string>",
"messages": [
{}
],
"images": [
{}
],
"monto": 123,
"categoria": "<string>",
"descripcion": "<string>",
"metodo_pago": "<string>",
"registrado_por": "<string>"
}
'{
"thinking": true,
"chunk": "<string>",
"done": true
}AI-powered conversational interface for registering transactions with streaming responses and function calling
curl --request POST \
--url https://api.example.com/api/chat/stream \
--header 'Content-Type: application/json' \
--data '
{
"message": "<string>",
"messages": [
{}
],
"images": [
{}
],
"monto": 123,
"categoria": "<string>",
"descripcion": "<string>",
"metodo_pago": "<string>",
"registrado_por": "<string>"
}
'{
"thinking": true,
"chunk": "<string>",
"done": true
}POST /api/chat/stream
role: "user" or "assistant"content: Message textContent-Type: text/event-stream. Each event is a JSON object:
true: AI is analyzing the requestfalse: AI has started generating responseregistrar_gastoAlimentación, Transporte, Vivienda, Salud, Entretenimiento, Educación, Otros GastosEfectivo, Tarjeta, Transferenciaregistrar_ingresoSalario, Ventas, Servicios, Inversiones, Otros IngresosEfectivo, Tarjeta, Transferenciaconst response = await fetch('/api/chat/stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'Gasté 450 pesos en gasolina',
messages: [],
images: []
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (data.thinking) {
console.log('AI is thinking...');
} else if (data.chunk) {
console.log('Response:', data.chunk);
} else if (data.done) {
console.log('Stream complete');
}
}
}
}
data: {"thinking": true}
thinking: true)thinking: false transitiontransacciones tabledone: truedata: {"chunk": "❌ Error al procesar. Intenta de nuevo.", "done": true}
{
"message": "Aquí está el ticket",
"messages": [...],
"images": ["https://supabase.co/storage/v1/object/public/facturas/ticket_123.jpg"]
}
"[El usuario subió 1 imagen(es) de tickets]\n\nAquí está el ticket"
This allows the AI to reference OCR data from the /api/upload-image endpoint.