Skip to content

Commit f34f02a

Browse files
committed
chore(internal): send more detailed x-stainless headers (#71)
1 parent 22f23ae commit f34f02a

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies = [
1313
"typing-extensions>=4.5, <5",
1414
"anyio>=3.5.0, <4",
1515
"distro>=1.7.0, <2",
16+
"sniffio",
1617

1718
]
1819
requires-python = ">= 3.7"

src/orb/_client.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
from ._qs import Querystring
1414
from ._types import (
1515
NOT_GIVEN,
16+
Omit,
1617
Timeout,
1718
NotGiven,
1819
Transport,
1920
ProxiesTypes,
2021
RequestOptions,
2122
)
22-
from ._utils import is_given, is_mapping
23+
from ._utils import is_given, is_mapping, get_async_library
2324
from ._version import __version__
2425
from ._streaming import Stream as Stream
2526
from ._streaming import AsyncStream as AsyncStream
@@ -133,6 +134,15 @@ def auth_headers(self) -> dict[str, str]:
133134
api_key = self.api_key
134135
return {"Authorization": f"Bearer {api_key}"}
135136

137+
@property
138+
@override
139+
def default_headers(self) -> dict[str, str | Omit]:
140+
return {
141+
**super().default_headers,
142+
"X-Stainless-Async": "false",
143+
**self._custom_headers,
144+
}
145+
136146
def copy(
137147
self,
138148
*,
@@ -370,6 +380,15 @@ def auth_headers(self) -> dict[str, str]:
370380
api_key = self.api_key
371381
return {"Authorization": f"Bearer {api_key}"}
372382

383+
@property
384+
@override
385+
def default_headers(self) -> dict[str, str | Omit]:
386+
return {
387+
**super().default_headers,
388+
"X-Stainless-Async": f"async:{get_async_library()}",
389+
**self._custom_headers,
390+
}
391+
373392
def copy(
374393
self,
375394
*,

src/orb/_utils/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ._utils import deepcopy_minimal as deepcopy_minimal
2626
from ._utils import extract_type_arg as extract_type_arg
2727
from ._utils import is_required_type as is_required_type
28+
from ._utils import get_async_library as get_async_library
2829
from ._utils import is_annotated_type as is_annotated_type
2930
from ._utils import maybe_coerce_float as maybe_coerce_float
3031
from ._utils import get_required_header as get_required_header

src/orb/_utils/_utils.py

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from pathlib import Path
1919
from typing_extensions import Required, Annotated, TypeGuard, get_args, get_origin
2020

21+
import sniffio
22+
2123
from .._types import Headers, NotGiven, FileTypes, NotGivenOr, HeadersLike
2224
from .._compat import is_union as _is_union
2325
from .._compat import parse_date as parse_date
@@ -406,3 +408,10 @@ def get_required_header(headers: HeadersLike, header: str) -> str:
406408
return value
407409

408410
raise ValueError(f"Could not find {header} header")
411+
412+
413+
def get_async_library() -> str:
414+
try:
415+
return sniffio.current_async_library()
416+
except Exception:
417+
return "false"

0 commit comments

Comments
 (0)