From 58b0ee27cdac1f4021c6e333f8157318c838ec56 Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:51:05 +0000 Subject: [PATCH 1/4] docs: simplify browser routing example Drop typing casts and unused streaming/cleanup blocks to mirror the node SDK's browser-routing example. Co-Authored-By: Claude Opus 4.7 --- examples/browser_routing.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/examples/browser_routing.py b/examples/browser_routing.py index 68627ab9..76ba8051 100644 --- a/examples/browser_routing.py +++ b/examples/browser_routing.py @@ -1,24 +1,16 @@ -"""Example: direct-to-VM browser routing for process exec and raw HTTP.""" - -from typing import Any, cast - -import httpx +"""Example: direct-to-VM browser routing for raw HTTP.""" from kernel import Kernel def main() -> None: - with Kernel() as client: - browsers = cast(Any, client.browsers) - browser = browsers.create(headless=True) - try: - response = cast(httpx.Response, browsers.request(browser.session_id, "GET", "https://example.com")) - print("status", response.status_code) + client = Kernel() + + browser = client.browsers.create() + response = client.browsers.request(browser.session_id, "GET", "https://example.com") + print("status", response.status_code) - with browsers.stream(browser.session_id, "GET", "https://example.com") as streamed: - print("streamed-bytes", len(streamed.read())) - finally: - browsers.delete_by_id(browser.session_id) + client.browsers.delete_by_id(browser.session_id) if __name__ == "__main__": From 0dfa1fb978da1c4fd474840ae8664f027e1feb39 Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:53:11 +0000 Subject: [PATCH 2/4] docs: annotate response with httpx.Response in browser routing example Make it explicit that browsers.request returns a familiar httpx.Response so users can rely on the standard interface. Co-Authored-By: Claude Opus 4.7 --- examples/browser_routing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/browser_routing.py b/examples/browser_routing.py index 76ba8051..284a4882 100644 --- a/examples/browser_routing.py +++ b/examples/browser_routing.py @@ -1,5 +1,7 @@ """Example: direct-to-VM browser routing for raw HTTP.""" +import httpx + from kernel import Kernel @@ -7,7 +9,7 @@ def main() -> None: client = Kernel() browser = client.browsers.create() - response = client.browsers.request(browser.session_id, "GET", "https://example.com") + response: httpx.Response = client.browsers.request(browser.session_id, "GET", "https://example.com") print("status", response.status_code) client.browsers.delete_by_id(browser.session_id) From 407e74862f99db13320ea6c02a8752759d4de60a Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:56:29 +0000 Subject: [PATCH 3/4] docs: show both raw streaming and buffered curl in routing example Add the buffered client.browsers.curl call alongside the raw streaming client.browsers.request call, with comments noting when to use each. Co-Authored-By: Claude Opus 4.7 --- examples/browser_routing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/browser_routing.py b/examples/browser_routing.py index 284a4882..4f324b3f 100644 --- a/examples/browser_routing.py +++ b/examples/browser_routing.py @@ -9,9 +9,15 @@ def main() -> None: client = Kernel() browser = client.browsers.create() + + # Raw browser curl: streams the response. Use for large responses or when you want to stream. response: httpx.Response = client.browsers.request(browser.session_id, "GET", "https://example.com") print("status", response.status_code) + # Buffered browser curl: returns the full response in a JSON envelope. Use for small responses. + buffered = client.browsers.curl(browser.session_id, url="https://example.com", method="GET") + print("buffered-status", buffered.status) + client.browsers.delete_by_id(browser.session_id) From 84cb2e38486f330635487ed049d692f7c9716a1f Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:59:35 +0000 Subject: [PATCH 4/4] docs: print buffered body and mention httpx.Response semantics Co-Authored-By: Claude Opus 4.7 --- examples/browser_routing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/browser_routing.py b/examples/browser_routing.py index 4f324b3f..ff5ffcb5 100644 --- a/examples/browser_routing.py +++ b/examples/browser_routing.py @@ -10,13 +10,14 @@ def main() -> None: browser = client.browsers.create() - # Raw browser curl: streams the response. Use for large responses or when you want to stream. + # Raw browser curl: streams the response. Use for large responses, when you want to stream, + # or when you want httpx.Response semantics. response: httpx.Response = client.browsers.request(browser.session_id, "GET", "https://example.com") print("status", response.status_code) # Buffered browser curl: returns the full response in a JSON envelope. Use for small responses. buffered = client.browsers.curl(browser.session_id, url="https://example.com", method="GET") - print("buffered-status", buffered.status) + print("body", buffered.body) client.browsers.delete_by_id(browser.session_id)