Skip to content

Commit 9d86a3c

Browse files
feat: support setting headers via env
1 parent a94f7a1 commit 9d86a3c

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/supermemory/_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828
from ._utils import (
2929
is_given,
30+
is_mapping_t,
3031
maybe_transform,
3132
get_async_library,
3233
async_maybe_transform,
@@ -114,6 +115,15 @@ def __init__(
114115
if base_url is None:
115116
base_url = f"https://api.supermemory.ai"
116117

118+
custom_headers_env = os.environ.get("SUPERMEMORY_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+
117127
super().__init__(
118128
version=__version__,
119129
base_url=base_url,
@@ -440,6 +450,15 @@ def __init__(
440450
if base_url is None:
441451
base_url = f"https://api.supermemory.ai"
442452

453+
custom_headers_env = os.environ.get("SUPERMEMORY_CUSTOM_HEADERS")
454+
if custom_headers_env is not None:
455+
parsed: dict[str, str] = {}
456+
for line in custom_headers_env.split("\n"):
457+
colon = line.find(":")
458+
if colon >= 0:
459+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
460+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
461+
443462
super().__init__(
444463
version=__version__,
445464
base_url=base_url,

0 commit comments

Comments
 (0)