Skip to main content
Use streaming to display text as it arrives, and send relevant message history to give a llm.sg model context for the next turn.
These Python examples assume the OpenAI-compatible chat format and a supporting model. Streaming and conversation behavior still require validation with an authorized key.

Stream text

Complete the quickstart setup, then set stream=True and read incremental text from each chunk.
Some chunks contain no text. Handle connection failures during iteration and distinguish an interrupted stream from a completed answer. Streaming changes when content appears; it does not guarantee shorter total generation time.

Continue a conversation

For the compatible chat format, send the relevant user and assistant messages in each request. Your application manages the history it chooses to send.
History adds input tokens. Keep relevant recent messages or summarize older content, and leave enough context capacity for the answer. Check image input, tool calling, reasoning, and structured output support separately before using them. A model’s tool request does not execute the tool; your application usually performs that action and sends the result back.