Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

fix(python-sdk): let api_headers Authorization win over deprecated access_token (#1464)

Mish Ushakov8171a03765b0
diff --git a/.changeset/strong-apes-bow.md b/.changeset/strong-apes-bow.md
new file mode 100644
index 000000000..4c72388ae
--- /dev/null
+++ b/.changeset/strong-apes-bow.md
@@ -0,0 +1,5 @@
+---
+"@e2b/python-sdk": patch
+---
+
+Fix Python SDK header precedence so a custom `Authorization` passed via `api_headers` is no longer overwritten by the deprecated `access_token`. The deprecated access token is now applied before `api_headers`, matching the JS SDK where a custom `Authorization` wins.
diff --git a/packages/python-sdk/e2b/api/__init__.py b/packages/python-sdk/e2b/api/__init__.py
index 2b854ff12..eed85ad1d 100644
--- a/packages/python-sdk/e2b/api/__init__.py
+++ b/packages/python-sdk/e2b/api/__init__.py
@@ -143,14 +143,18 @@ class ApiClient(AuthenticatedClient):
headers = {
**default_headers,
+ # Deprecated: send the access token alongside the API key when one
+ # is available, mirroring the JS SDK. Prefer `api_headers` instead.
+ # Spread before `config.headers` so a custom `Authorization` in
+ # `api_headers` wins over the deprecated access token, matching JS.
+ **(
+ {"Authorization": f"Bearer {config.access_token}"}
+ if config.access_token is not None
+ else {}
+ ),
**(config.headers or {}),
}
- # Deprecated: send the access token alongside the API key when one is
- # available, mirroring the JS SDK. Prefer `api_headers` instead.
- if config.access_token is not None:
- headers["Authorization"] = f"Bearer {config.access_token}"
-
# Prevent passing these parameters twice
more_headers: Optional[dict] = kwargs.pop("headers", None)
if more_headers: