Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
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.mdnew file mode 100644index 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__.pyindex 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 twicemore_headers: Optional[dict] = kwargs.pop("headers", None)if more_headers: