Skip to content

Commit

Permalink
feat(streaming): add request_id getter
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Jan 20, 2025
1 parent f2c10ca commit c2a1a94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/anthropic/lib/streaming/_beta_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down Expand Up @@ -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__()

Expand Down
8 changes: 8 additions & 0 deletions src/anthropic/lib/streaming/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down Expand Up @@ -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__()

Expand Down

0 comments on commit c2a1a94

Please sign in to comment.