wraithunder
12/12/2025, 6:08 AMglad screen now looking really that hear.I'm I'm to forward you about how has over changed the. image an have I I years to here with — like'd should you share you chatting What on your it. notice you to this image do in? dancing that with see
can I get the sequence index somehow?wraithunder
12/12/2025, 6:08 AMprivate modelOutputBuffer: Map<string, string> = new Map();
private modelOutputTimers: Map<string, NodeJS.Timeout> = new Map();
private GAP_MS = 250;
/**
* Main handler for Vapi server messages.
*/
async handleServerMessage(
call: InferResultType<'call'>,
data: Vapi.ServerMessage,
): Promise<void> {
switch (data.message.type) {
case 'model-output':
return this.handleModelOutputUpdate(call, data.message);
default:
return;
}
}
getModelOutputMessageSync(obj: Record<string, unknown>): string {
let output = '';
for (const [, value] of Object.entries(obj)) {
if (value !== null && typeof value === 'object') continue;
output += String(value);
}
return output;
}
async handleModelOutputUpdate(
call: InferResultType<'call'>,
data: Vapi.ServerMessageModelOutput
): Promise<void> {
const callId = call.id;
const chunk = this.getModelOutputMessageSync(data.output);
// Append chunk to buffer
const existing = this.modelOutputBuffer.get(callId) ?? '';
this.modelOutputBuffer.set(callId, existing + chunk);
// Clear any existing timeout
const existingTimer = this.modelOutputTimers.get(callId);
if (existingTimer) clearTimeout(existingTimer);
// Debounce timer
const timer = setTimeout(async () => {
await this.flushModelOutput(call);
}, this.GAP_MS);
this.modelOutputTimers.set(callId, timer);
this.logger.log(`buffered chunk for ${callId}: ${JSON.stringify(chunk)}`);
}
async flushModelOutput(call: InferResultType<'call'>): Promise<void> {
const callId = call.id;
const fullOutput = this.modelOutputBuffer.get(callId) ?? '';
if (!fullOutput) return;
this.logger.log(`FLUSHED final message: ${JSON.stringify(fullOutput, null, 2)}`);
}wraithunder
12/12/2025, 10:51 AMVapi Support Bot
12/12/2025, 10:53 AMmodel-output server message does not include a sequence index or ordering field in its payload, according to the official documentation.
If chunk order is critical, you may need to buffer and process the chunks as they arrive, but there is no built-in way to re-order them.
Consider reaching out to Vapi support or submitting a feature request for sequence indices in the webhook payload.
[See the official server message reference for details.](https://docs.vapi.ai/api-reference/webhooks/server-message)
Source:
- [Server Message API Reference](https://docs.vapi.ai/api-reference/webhooks/server-message)Chiranjeet Mishra
12/16/2025, 3:24 AMmodel-output server messages do NOT currently include a sequence index or guaranteed ordering, so chunks can arrive out of order and concatenating them will produce jumbled text. There’s no sequenceNumber (or similar) you can rely on today.
What you can do instead:
- Treat model-output as best-effort streaming only
- Buffer by arrival time and accept possible reordering
- Or switch to end-of-call report / conversation-update if you need a clean, ordered transcript
If deterministic ordering is critical, this would need to be a feature request (sequence indices in model-output payloads).wraithunder
12/16/2025, 11:22 PMChiranjeet Mishra
12/18/2025, 8:59 PM