Skip to content

Commit 082ef37

Browse files
committed
chore(internal): send more detailed x-stainless headers (#198)
1 parent 250a202 commit 082ef37

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-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/finch/_client.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
AsyncTransport,
2323
RequestOptions,
2424
)
25-
from ._utils import is_given
25+
from ._utils import is_given, get_async_library
2626
from ._version import __version__
2727
from ._streaming import Stream as Stream
2828
from ._streaming import AsyncStream as AsyncStream
@@ -156,6 +156,7 @@ def auth_headers(self) -> dict[str, str]:
156156
def default_headers(self) -> dict[str, str | Omit]:
157157
return {
158158
**super().default_headers,
159+
"X-Stainless-Async": "false",
159160
"Finch-API-Version": "2020-09-17",
160161
**self._custom_headers,
161162
}
@@ -459,6 +460,7 @@ def auth_headers(self) -> dict[str, str]:
459460
def default_headers(self) -> dict[str, str | Omit]:
460461
return {
461462
**super().default_headers,
463+
"X-Stainless-Async": f"async:{get_async_library()}",
462464
"Finch-API-Version": "2020-09-17",
463465
**self._custom_headers,
464466
}

src/finch/_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/finch/_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)