Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions google/genai/_interactions/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def _make_status_error(
) -> _exceptions.APIStatusError:
raise NotImplementedError()

def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0) -> httpx.Headers:
def _build_headers(self, options: FinalRequestOptions) -> httpx.Headers:
custom_headers = options.headers or {}
headers_dict = _merge_mappings(self.default_headers, custom_headers)
self._validate_headers(headers_dict, custom_headers)
Expand All @@ -468,18 +468,6 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
if idempotency_header and options.idempotency_key and idempotency_header not in headers:
headers[idempotency_header] = options.idempotency_key

# Don't set these headers if they were already set or removed by the caller. We check
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
lower_custom_headers = [header.lower() for header in custom_headers]
if "x-stainless-retry-count" not in lower_custom_headers:
headers["x-stainless-retry-count"] = str(retries_taken)
if "x-stainless-read-timeout" not in lower_custom_headers:
timeout = self.timeout if isinstance(options.timeout, NotGiven) else options.timeout
if isinstance(timeout, Timeout):
timeout = timeout.read
if timeout is not None:
headers["x-stainless-read-timeout"] = str(timeout)

return headers

def _prepare_url(self, url: str) -> URL:
Expand All @@ -501,8 +489,6 @@ def _make_sse_decoder(self) -> SSEDecoder | SSEBytesDecoder:
def _build_request(
self,
options: FinalRequestOptions,
*,
retries_taken: int = 0,
) -> httpx.Request:
if log.isEnabledFor(logging.DEBUG):
log.debug(
Expand All @@ -529,7 +515,7 @@ def _build_request(
else:
raise RuntimeError(f"Unexpected JSON data type, {type(json_data)}, cannot merge with `extra_body`")

headers = self._build_headers(options, retries_taken=retries_taken)
headers = self._build_headers(options)
params = _merge_mappings(self.default_query, options.params)
content_type = headers.get("Content-Type")
files = options.files
Expand Down Expand Up @@ -694,7 +680,6 @@ def default_headers(self) -> dict[str, str | Omit]:
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": self.user_agent,
**self.platform_headers(),
**self.auth_headers,
**self._custom_headers,
}
Expand Down Expand Up @@ -1010,7 +995,7 @@ def request(
options = self._prepare_options(options)

remaining_retries = max_retries - retries_taken
request = self._build_request(options, retries_taken=retries_taken)
request = self._build_request(options)
self._prepare_request(request)

kwargs: HttpxSendArgs = {}
Expand Down Expand Up @@ -1594,7 +1579,7 @@ async def request(
options = await self._prepare_options(options)

remaining_retries = max_retries - retries_taken
request = self._build_request(options, retries_taken=retries_taken)
request = self._build_request(options)
await self._prepare_request(request)

kwargs: HttpxSendArgs = {}
Expand Down
4 changes: 1 addition & 3 deletions google/genai/_interactions/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
RequestOptions,
not_given,
)
from ._utils import is_given, get_async_library
from ._utils import is_given
from ._compat import cached_property
from ._models import FinalRequestOptions
from ._version import __version__
Expand Down Expand Up @@ -159,7 +159,6 @@ def auth_headers(self) -> dict[str, str]:
def default_headers(self) -> dict[str, str | Omit]:
return {
**super().default_headers,
"X-Stainless-Async": "false",
**self._custom_headers,
}

Expand Down Expand Up @@ -381,7 +380,6 @@ def auth_headers(self) -> dict[str, str]:
def default_headers(self) -> dict[str, str | Omit]:
return {
**super().default_headers,
"X-Stainless-Async": f"async:{get_async_library()}",
**self._custom_headers,
}

Expand Down