https://retellai.com/?utm_source=discord&utm_medium=seo logo
<@1145576664366055464> When using a custom LLM set...
# ❓・ai-evy-support
r
@AI Evy When using a custom LLM setup, can I stream LLM responses at the token level, or do I have to aggregate the message in its entirety before yielding it to Retell to process?
a
Thanks for tagging me @raviraina_. I'll look through relevant sources and get back to you shortly.
### Answer With a custom LLM setup, you can stream responses at the token level rather than aggregating the entire message [(1) ]() . The documentation shows this streaming approach in both Node.js and Python examples . For streaming responses, you send multiple response events with
content_complete: false
for partial content, and only set
content_complete: true
for the final event [(2) ]() . Here's how this works: Node.js streaming example:
Copy code
typescript
for await (const event of events) {
  if (event.choices.length >= 1) {
    let delta = event.choices[0].delta;
    if (!delta || !delta.content) continue;
    const res: RetellResponse = {
      response_id: request.response_id,
      content: delta.content,
      content_complete: false,
      end_call: false,
    };
    ws.send(JSON.stringify(res) ) ;
  }
}
[(1) ]() Python streaming example:
Copy code
python
for chunk in stream:
  if chunk.choices[0].delta.content is not None:
    yield {
      "response_id": request['response_id'],
      "content": chunk.choices[0].delta.content,
      "content_complete": False,
      "end_call": False,
    }
The key is using the
content_complete
field to indicate whether each chunk is partial (
false
) or final (
true
) content [(2) ]() . This token-level streaming approach helps reduce latency, which is crucial for conversational AI [(3) ]() .
​ To learn more, see the sources I considered: [[1] Integrate LLM](https://docs.retellai.com/integrate-llm/integrate-llm) [[2] LLM WebSocket](https://docs.retellai.com/api-references/llm-websocket) [[3] Custom LLM Best Practices](https://docs.retellai.com/integrate-llm/llm-best-practice) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
r
@AI Evy How does retell process this. Is their custom logic that allows the voice agent to begin speaking before content complete is true, or does it still wait for the whole message?
a
Thanks for the follow-up, @raviraina_. I'll get back to you soon.
### Answer Retell has custom logic that allows the voice agent to begin speaking before
content_complete
is true [(1) ]() . The streaming logic works as follows: - The voice agent will start streaming when a complete sentence is met - Or will start streaming once the content is complete This is designed to generate audio with proper tonality context . A complete sentence is identified by punctuations (apart from special cases like "Dr.") . Retell also has logic to stream based on timeout . So you don't need to wait for the entire message - the agent can begin speaking as soon as it receives a complete sentence with proper punctuation, even when
content_complete
is still false . However, it's still recommended to set
content_complete
to true after you finish the response, so Retell knows your agent is done for that turn .
​ To learn more, see the sources I considered: [[1] Issue with 11Labs voice when content complete is set false.](https://discord.com/channels/1186424376300679209/1233352616684032012) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.