Skip to content

Commit 8083e37

Browse files
feat: support setting headers via env
1 parent 98c0635 commit 8083e37

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/runloop_api_client/_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
@@ -111,6 +115,15 @@ def __init__(
111115
if base_url is None:
112116
base_url = f"https://api.runloop.ai"
113117

118+
custom_headers_env = os.environ.get("RUNLOOP_CUSTOM_HEADERS")
119+
if custom_headers_env is not None:
120+
parsed: dict[str, str] = {}
121+
for line in custom_headers_env.split("\n"):
122+
colon = line.find(":")
123+
if colon >= 0:
124+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
125+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
126+
114127
super().__init__(
115128
version=__version__,
116129
base_url=base_url,
@@ -371,6 +384,15 @@ def __init__(
371384
if base_url is None:
372385
base_url = f"https://api.runloop.ai"
373386

387+
custom_headers_env = os.environ.get("RUNLOOP_CUSTOM_HEADERS")
388+
if custom_headers_env is not None:
389+
parsed: dict[str, str] = {}
390+
for line in custom_headers_env.split("\n"):
391+
colon = line.find(":")
392+
if colon >= 0:
393+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
394+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
395+
374396
super().__init__(
375397
version=__version__,
376398
base_url=base_url,

0 commit comments

Comments
 (0)