Repository navigation
feat: expose response headers on streams and results - #190
Conversation
The stream objects of tts.stream(), tts.stream_with_timestamps() and asr.stream_websocket(), and the results of asr.transcribe() and tts.convert_with_timestamps(), gain a headers attribute with the headers of the response that opened them, so a caller can read x-fish-trace-id from a call that was accepted.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified, and the response-header changes are covered across stream, result, failure, closure, and realtime scenarios.
No open issues 🎉
What changed in this PR
This pull request exposes HTTP response headers on accepted TTS and ASR streams and result models, allowing callers to retain diagnostic information such as trace IDs after streams complete, close, or fail.
Changes:
- Added
headersto synchronous and asynchronous TTS streams and realtime ASR streams. - Attached response headers to
ASRResponseandTTSTimestampResultwithout changing Pydantic serialization or equality behavior. - Added coverage for successful, failed, closed, headerless, and realtime response lifecycles.
- Documented accessing response headers and trace IDs.
| File | Description |
|---|---|
| tests/unit/test_response_headers.py | Adds coverage for response headers across HTTP, timestamp, result, failure, lifecycle, and realtime flows. |
| tests/unit/test_asr_realtime.py | Updates realtime test doubles to provide the WebSocket handshake response attribute. |
| tests/unit/realtime_server.py | Adds response headers to accepted realtime test handshakes. |
| src/fishaudio/types/tts.py | Exposes response headers on TTSTimestampResult. |
| src/fishaudio/types/shared.py | Provides private header storage and access helpers for result models. |
| src/fishaudio/types/asr.py | Exposes response headers on ASRResponse. |
| src/fishaudio/resources/tts.py | Passes HTTP response headers into synchronous and asynchronous TTS streams. |
| src/fishaudio/resources/asr.py | Attaches HTTP response headers to transcription results. |
| src/fishaudio/resources/asr_realtime.py | Captures and exposes accepted realtime WebSocket handshake headers. |
| src/fishaudio/core/iterators.py | Stores headers on stream wrappers and propagates them to timestamp results. |
| README.md | Documents accessing response headers and trace IDs. |
Review effort: Lite
…rs private The schema assertion compared a class with itself. The result docstrings now say when headers are empty without excluding copies.
…-on-success # Conflicts: # src/fishaudio/resources/asr.py
What
A caller whose call was accepted can now read the response headers, including
x-fish-trace-id. Part of FISH-2233; companion to #188 (calls the API refuses).The case this serves: a request succeeds but the audio sounds wrong, or a stream breaks midway. There is no error response to read, and the trace id is what support needs.
The streams and results listed below carry the headers of the response they were built from. The SDK names no header and promises none.
Public interface
AudioStream,AsyncAudioStream(tts.stream) andTTSTimestampStream,AsyncTTSTimestampStream(tts.stream_with_timestamps): a new attributeheaders(anhttpx.Headers, the response's own object), and a new optional keywordheaders=Noneon their constructors.ASRRealtimeStream,AsyncASRRealtimeStream(asr.stream_websocket): a new read-only propertyheaders, the headers of the handshake response; empty until the stream connects on first iteration.ASRResponse(asr.transcribe) andTTSTimestampResult(tts.convert_with_timestamps, andcollect()on a timestamp stream): a new read-only propertyheaders. It is not a model field.Behaviour changes
None for existing callers. On the two result models, equality,
model_dump()and the JSON schema are unchanged; a copy and a pickle round trip keep the headers and still equal the plain model. A test pins that.The headers stay readable after a stream is closed or has failed.
Not covered
tts.convert()returnsbytes, which cannot carry anything. Usetts.stream(...)andcollect(); the README shows it.tts.stream_websocketreturns a plain generator. Giving it a stream object changes its return type, so it is a separate change.Verification
poe checkand the test suite pass. Tests intests/unit/test_response_headers.py(16) run against local servers: headers before and after the body, a stream that breaks midway, a stream closed before iteration, two streams open at once, a response without the header, the timestamp stream and result, the transcription result, thatheadersis not a model field, and the realtime stream after connecting, after the session ended and after a failure. The file also passes on pydantic 2.9.1, the lowest supported version (run locally; CI has no minimum-versions job). Against production:tts.stream,stream_with_timestamps,convert_with_timestamps,asr.transcribeandasr.stream_websocketall expose the trace id.Summary by CodeRabbit