Streaming without repetition
Send only the new text from each streaming update so screen readers do not hear the whole response again and again.
Send only the new text
Send response.started when a response begins. Each response.text.delta must contain only the text that just arrived. Send response.completed to announce any useful text still waiting. Send response.failed or response.interrupted to discard that text.
runtime.dispatch({ type: "response.started", responseId: "r1" });
runtime.dispatch({
type: "response.text.delta",
responseId: "r1",
delta: "First complete sentence. ",
});
runtime.dispatch({
type: "response.text.delta",
responseId: "r1",
delta: "Second complete sentence.",
});
runtime.dispatch({ type: "response.completed", responseId: "r1" });How this code works
- 01Start the response
response.startedtells the runtime that a new response is beginning. - 02Send new text only
Each delta contains only new text, so earlier text is not announced again.
- 03Let the runtime group text
Your runtime waits for useful phrases instead of announcing every token.
- 04Finish the response
response.completedsends any useful text that is still waiting and closes the response.
Meaningful units, not tokens
Balanced mode waits for a complete sentence when possible. It can also send a useful phrase after enough text arrives or a short delay. Each piece is announced once.