Skip to content

Commit

Permalink
chore(internal): send more detailed x-stainless headers (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Nov 24, 2023
1 parent ddff306 commit 654604e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies = [
"typing-extensions>=4.5, <5",
"anyio>=3.5.0, <4",
"distro>=1.7.0, <2",
"sniffio",
"tokenizers >= 0.13.0",
"boto3 >= 1.28.57",
"botocore >= 1.31.57"
Expand Down
21 changes: 20 additions & 1 deletion src/anthropic_bedrock/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
from ._qs import Querystring
from ._types import (
NOT_GIVEN,
Omit,
Timeout,
NotGiven,
Transport,
ProxiesTypes,
RequestOptions,
)
from ._utils import is_given
from ._utils import is_given, get_async_library
from ._version import __version__
from ._streaming import Stream as Stream
from ._streaming import AsyncStream as AsyncStream
Expand Down Expand Up @@ -137,6 +138,15 @@ def _prepare_request(self, request: httpx.Request) -> None:
)
request.headers.update(headers)

@property
@override
def default_headers(self) -> dict[str, str | Omit]:
return {
**super().default_headers,
"X-Stainless-Async": "false",
**self._custom_headers,
}

def copy(
self,
*,
Expand Down Expand Up @@ -347,6 +357,15 @@ async def _prepare_request(self, request: httpx.Request) -> None:
)
request.headers.update(headers)

@property
@override
def default_headers(self) -> dict[str, str | Omit]:
return {
**super().default_headers,
"X-Stainless-Async": f"async:{get_async_library()}",
**self._custom_headers,
}

def copy(
self,
*,
Expand Down
1 change: 1 addition & 0 deletions src/anthropic_bedrock/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ._utils import deepcopy_minimal as deepcopy_minimal
from ._utils import extract_type_arg as extract_type_arg
from ._utils import is_required_type as is_required_type
from ._utils import get_async_library as get_async_library
from ._utils import is_annotated_type as is_annotated_type
from ._utils import maybe_coerce_float as maybe_coerce_float
from ._utils import get_required_header as get_required_header
Expand Down
9 changes: 9 additions & 0 deletions src/anthropic_bedrock/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from pathlib import Path
from typing_extensions import Required, Annotated, TypeGuard, get_args, get_origin

import sniffio

from .._types import Headers, NotGiven, FileTypes, NotGivenOr, HeadersLike
from .._compat import is_union as _is_union
from .._compat import parse_date as parse_date
Expand Down Expand Up @@ -406,3 +408,10 @@ def get_required_header(headers: HeadersLike, header: str) -> str:
return value

raise ValueError(f"Could not find {header} header")


def get_async_library() -> str:
try:
return sniffio.current_async_library()
except Exception:
return "false"

0 comments on commit 654604e

Please sign in to comment.