Skip to content

Commit 12037dd

Browse files
authored
fix: type background response stream reconnection
Add validated reconnect cursors and typed synchronous and asynchronous stream retrieval while preserving snapshots.
1 parent acb52e6 commit 12037dd

5 files changed

Lines changed: 356 additions & 9 deletions

File tree

‎BUILD.bazel‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ bazel_py_test(
6868
"--show-traceback",
6969
"src",
7070
"typing_decisions.py",
71+
"typing_responses.py",
7172
],
7273
data = [
7374
"pyproject.toml",
7475
"typing_decisions.py",
76+
"typing_responses.py",
7577
"//src:perplexity",
7678
],
7779
deps = PYTHON_DEPS,

‎api.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ Methods:
107107
- <code title="get /v1/responses/{response_id}">client.responses.<a href="./src/perplexity/resources/responses/responses.py">retrieve</a>(response_id) -> <a href="./src/perplexity/types/response_retrieve_response.py">ResponseRetrieveResponse</a></code>
108108
- <code title="post /v1/responses/{response_id}/cancel">client.responses.<a href="./src/perplexity/resources/responses/responses.py">cancel</a>(response_id) -> <a href="./src/perplexity/types/response_cancel_response.py">ResponseCancelResponse</a></code>
109109

110+
To reconnect to a background response's event stream, supply the last event
111+
sequence number received:
112+
113+
```python
114+
stream = client.responses.retrieve(response_id, stream=True, starting_after=last_sequence_number)
115+
```
116+
117+
Streaming retrieval requires `starting_after`. If the API returns HTTP 400 because
118+
the cursor has expired, call `client.responses.retrieve(response_id)` without
119+
streaming parameters to obtain the current JSON snapshot.
120+
110121
## Files
111122

112123
Methods:

‎src/perplexity/generated/api.py‎

Lines changed: 158 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)