Skip to content

Commit 308d35e

Browse files
feat: support setting headers via env
1 parent 9488fb3 commit 308d35e

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/browserbase/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
RequestOptions,
2020
not_given,
2121
)
22-
from ._utils import is_given, get_async_library
22+
from ._utils import (
23+
is_given,
24+
is_mapping_t,
25+
get_async_library,
26+
)
2327
from ._compat import cached_property
2428
from ._version import __version__
2529
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
@@ -95,6 +99,15 @@ def __init__(
9599
if base_url is None:
96100
base_url = f"https://api.browserbase.com"
97101

102+
custom_headers_env = os.environ.get("BROWSERBASE_CUSTOM_HEADERS")
103+
if custom_headers_env is not None:
104+
parsed: dict[str, str] = {}
105+
for line in custom_headers_env.split("\n"):
106+
colon = line.find(":")
107+
if colon >= 0:
108+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
109+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
110+
98111
super().__init__(
99112
version=__version__,
100113
base_url=base_url,
@@ -299,6 +312,15 @@ def __init__(
299312
if base_url is None:
300313
base_url = f"https://api.browserbase.com"
301314

315+
custom_headers_env = os.environ.get("BROWSERBASE_CUSTOM_HEADERS")
316+
if custom_headers_env is not None:
317+
parsed: dict[str, str] = {}
318+
for line in custom_headers_env.split("\n"):
319+
colon = line.find(":")
320+
if colon >= 0:
321+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
322+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
323+
302324
super().__init__(
303325
version=__version__,
304326
base_url=base_url,

0 commit comments

Comments
 (0)