Streaming
Stream tokens in real-time as the model generates them. Instead of waiting for the full response, your app receives each token as it's produced.
Stream to console
Pass stream=True to print tokens to the console as they arrive:
stream.py
from veska import Agent
agent = Agent(
name="writer",
system_prompt="You are a creative writer.",
model="claude-sonnet-4-6",
)
result = agent.run("Write a poem about the ocean", stream=True)Stream to a custom function
Pass a function to stream to handle each token yourself:
stream_custom.py
from veska import Agent
agent = Agent(
name="writer",
system_prompt="You are a creative writer.",
model="claude-sonnet-4-6",
)
# Send tokens to your UI, file, or anywhere
def on_token(text):
my_ui.append(text)
result = agent.run("Write a poem about the ocean", stream=on_token)
# result still contains the full response
print(result.output)Stream options
| Value | Behavior |
|---|---|
None / False | No streaming. Waits for full response. |
True | Prints tokens to console automatically. |
function | Calls your function with each token. |
Provider support
Both Claude and OpenAI models support streaming. The behavior is the same regardless of which model you use.