POST
/
call
/
stream
from opperai import Opper

opper = Opper(http_bearer="YOUR_API_KEY")

# Stream a creative writing task
stream_response = opper.stream(
    name="creative_writer",
    instructions="Write a short story about a robot learning to paint. Make it engaging and creative.",
    input={"topic": "robot artist", "length": "short"},
    model="openai/gpt-4o-mini",
)

# The stream method returns a response object with 'result' containing the EventStream
for event in stream_response.result:
    # Each event is a FunctionStreamCallStreamPostResponseBody with 'data' containing the streaming chunk
    if hasattr(event, "data") and hasattr(event.data, "delta") and event.data.delta:
        print(event.data.delta, end="", flush=True)

print("\n")  # New line at the end
{
  "data": {
    "delta": "Hello! How can I assist you today?",
    "span_id": "123e4567-e89b-12d3-a456-426614174000"
  }
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Response

200
text/event-stream

Server-Sent Events stream of function execution chunks

Server-Sent Event following the SSE specification