Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/sharp-garlics-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@browserbasehq/stagehand-server-v3": patch
"@browserbasehq/stagehand-docs": patch
---

Clarify SSE streaming docs examples
8 changes: 2 additions & 6 deletions packages/docs/v3/sdk/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ uv run python examples/local_example.py

## Streaming logging example

See [`examples/logging_example.py`](https://github.com/browserbase/stagehand-python/blob/main/examples/logging_example.py) for a remote-only flow that streams `StreamEvent`s with `verbose=2`, `stream_response=True`, and `x_stream_response="true"` so you can watch the SDK’s logs as they arrive.
See [`examples/logging_example.py`](https://github.com/browserbase/stagehand-python/blob/main/examples/logging_example.py) for a remote-only flow that streams `StreamEvent`s with `verbose=2` and `stream_response=True` so you can watch the SDK’s logs as they arrive.

```bash
uv run python examples/logging_example.py
Expand Down Expand Up @@ -297,10 +297,7 @@ asyncio.run(main())

We provide support for streaming responses using Server-Sent Events (SSE).

To enable SSE streaming, you must:

1. Ask the server to stream by setting `x_stream_response="true"` (header), and
2. Tell the client to parse an SSE stream by setting `stream_response=True`.
To enable SSE streaming, set `stream_response=True`. The SDK sends the streaming request and parses the SSE response as `StreamEvent`s.

```python
import asyncio
Expand All @@ -315,7 +312,6 @@ async def main() -> None:
id=session.id,
input="click the first link on the page",
stream_response=True,
x_stream_response="true",
)
async for event in stream:
# event is a StreamEvent (type: "system" | "log")
Expand Down
6 changes: 4 additions & 2 deletions packages/server-v3/openapi.v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ info:

All endpoints except /sessions/start require an active session ID.

Responses are streamed using Server-Sent Events (SSE) when the
Supported operations stream responses using Server-Sent Events (SSE) when

`x-stream-response: true` header is provided.
`streamResponse` is set to `true` in the request body, or when the

`x-stream-response: true` header is sent by legacy or no-body clients.


This SDK is currently ALPHA software and is not production ready!
Expand Down
5 changes: 3 additions & 2 deletions packages/server-v3/scripts/gen-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ async function main() {
description: `Stagehand SDK for AI browser automation [ALPHA]. This API allows clients to
execute browser automation tasks remotely on the Browserbase cloud.
All endpoints except /sessions/start require an active session ID.
Responses are streamed using Server-Sent Events (SSE) when the
\`x-stream-response: true\` header is provided.
Supported operations stream responses using Server-Sent Events (SSE) when
\`streamResponse\` is set to \`true\` in the request body, or when the
\`x-stream-response: true\` header is sent by legacy or no-body clients.

This SDK is currently ALPHA software and is not production ready!
Please try it and give us your feedback, stay tuned for upcoming release announcements!`,
Expand Down
18 changes: 18 additions & 0 deletions stainless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ openapi:
value:
x-stainless-any: true

# Override the generated Python API reference example for the dual-mode
# act endpoint so docs show the SSE stream shape instead of iterating over
# a non-streaming response object.
- command: merge
reason: Use streaming Python snippet for sessions.act docs
args:
target: '$.paths["/v1/sessions/{id}/act"].post'
value:
x-stainless-snippets:
python: |
stream = client.sessions.act(
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
input="Click the login button",
stream_response=True,
)
for event in stream:
print(event)

# `resources` define the structure and organization for your API, such as how
# methods and models are grouped together and accessed. See the [configuration
# guide] for more information.
Expand Down
Loading