Skip to content

Commit 69e0549

Browse files
committed
chore(internal): send more detailed x-stainless headers (#877)
1 parent 0a06d6a commit 69e0549

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
"tqdm > 4"
1718
]
1819
requires-python = ">= 3.7.1"

src/openai/_client.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ProxiesTypes,
2121
RequestOptions,
2222
)
23-
from ._utils import is_given, is_mapping
23+
from ._utils import is_given, is_mapping, get_async_library
2424
from ._version import __version__
2525
from ._streaming import Stream as Stream
2626
from ._streaming import AsyncStream as AsyncStream
@@ -147,6 +147,7 @@ def auth_headers(self) -> dict[str, str]:
147147
def default_headers(self) -> dict[str, str | Omit]:
148148
return {
149149
**super().default_headers,
150+
"X-Stainless-Async": "false",
150151
"OpenAI-Organization": self.organization if self.organization is not None else Omit(),
151152
**self._custom_headers,
152153
}
@@ -356,6 +357,7 @@ def auth_headers(self) -> dict[str, str]:
356357
def default_headers(self) -> dict[str, str | Omit]:
357358
return {
358359
**super().default_headers,
360+
"X-Stainless-Async": f"async:{get_async_library()}",
359361
"OpenAI-Organization": self.organization if self.organization is not None else Omit(),
360362
**self._custom_headers,
361363
}

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