From c2a1a9474763a03e1caf4341dc945bcd1aa7834c Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Mon, 20 Jan 2025 11:44:01 +0000 Subject: [PATCH] feat(streaming): add request_id getter --- src/anthropic/lib/streaming/_beta_messages.py | 8 ++++++++ src/anthropic/lib/streaming/_messages.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/anthropic/lib/streaming/_beta_messages.py b/src/anthropic/lib/streaming/_beta_messages.py index 48e419e9..87261a81 100644 --- a/src/anthropic/lib/streaming/_beta_messages.py +++ b/src/anthropic/lib/streaming/_beta_messages.py @@ -40,6 +40,10 @@ def __init__(self, raw_stream: Stream[BetaRawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") + def __next__(self) -> BetaMessageStreamEvent: return self._iterator.__next__() @@ -173,6 +177,10 @@ def __init__(self, raw_stream: AsyncStream[BetaRawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") + async def __anext__(self) -> BetaMessageStreamEvent: return await self._iterator.__anext__() diff --git a/src/anthropic/lib/streaming/_messages.py b/src/anthropic/lib/streaming/_messages.py index 67fe8f0b..7b6b464e 100644 --- a/src/anthropic/lib/streaming/_messages.py +++ b/src/anthropic/lib/streaming/_messages.py @@ -41,6 +41,10 @@ def __init__(self, raw_stream: Stream[RawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") + def __next__(self) -> MessageStreamEvent: return self._iterator.__next__() @@ -174,6 +178,10 @@ def __init__(self, raw_stream: AsyncStream[RawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") + async def __anext__(self) -> MessageStreamEvent: return await self._iterator.__anext__()