Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.opper.ai/llms.txt

Use this file to discover all available pages before exploring further.

Use opper.stream() instead of opper.call() to receive the response as a series of chunks instead of one final object. Good for showing output as it arrives in a UI. opper.stream(...) returns a response whose result is the stream of chunks. Each chunk has a data payload, and text chunks carry a delta string.

Stream text

import os
from opperai import Opper

opper = Opper(http_bearer=os.getenv("OPPER_API_KEY", ""))

response = opper.stream(
    name="creative-writer",
    instructions="Write a short story about a robot learning to paint.",
    input={"topic": "robot artist"},
)

for chunk in response.result:
    delta = chunk.data.get("delta")
    if delta:
        print(delta, end="", flush=True)
The first chunk carries the span_id; the rest carry a delta with the next piece of text. Over HTTP, the endpoint sends server-sent events.

With a schema

Pass an output_schema just like a regular call. The deltas stream the JSON as the model produces it. Accumulate them and parse the result once the stream finishes if you need the typed object.

Errors mid-stream

If a Guard rule rejects the output or the upstream model fails, the stream ends with an error. Wrap the iteration in a try/except (Python) or try/catch (TypeScript).

What’s next

Calls

The non-streaming version.

Schemas

Pydantic, JSON Schema, and media types.

Chat streaming

Token-level streaming for the Chat API.