Skip to content

feat: expose response headers on streams and results - #190

Merged
lumpinif merged 6 commits into
mainfrom
feat/response-headers-on-success
Dec 1, 2026
Merged

lumpinif merged 6 commits into
mainfrom
feat/response-headers-on-success

Conversation

@lumpinif

@lumpinif lumpinif commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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) and TTSTimestampStream, AsyncTTSTimestampStream (tts.stream_with_timestamps): a new attribute headers (an httpx.Headers, the response's own object), and a new optional keyword headers=None on their constructors.
  • ASRRealtimeStream, AsyncASRRealtimeStream (asr.stream_websocket): a new read-only property headers, the headers of the handshake response; empty until the stream connects on first iteration.
  • ASRResponse (asr.transcribe) and TTSTimestampResult (tts.convert_with_timestamps, and collect() on a timestamp stream): a new read-only property headers. It is not a model field.
  • No new class, exception, export, option or parameter on a client method. No return, iterator or exception type changes.

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() returns bytes, which cannot carry anything. Use tts.stream(...) and collect(); the README shows it.
  • tts.stream_websocket returns a plain generator. Giving it a stream object changes its return type, so it is a separate change.

Verification

poe check and the test suite pass. Tests in tests/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, that headers is 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.transcribe and asr.stream_websocket all expose the trace id.

Summary by CodeRabbit

  • New Features
    • View response headers, including trace IDs, on audio streams, timestamped results, transcription results, and realtime ASR sessions.
    • Read the transcription request ID from ASR results.
    • Header access remains available after streams end or encounter errors; headers are empty until realtime connections open.
  • Documentation
    • Added guidance on where trace IDs and request IDs are available and how to access them.

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.
@lumpinif
lumpinif requested review from abersheeran and a lite review from Copilot November 26, 2026 14:07
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T14:07:35.307229Z
We couldn’t complete this review. Comment @codex review to try again.
171f471 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The client now exposes response headers on selected TTS streams and results, ASR transcription results, and realtime ASR streams. The README documents header availability, including when headers are empty or unavailable. Unit tests cover HTTP responses and WebSocket handshakes.

Changes: Response Header Exposure

Layer / File(s) Summary
Header storage and result properties
src/fishaudio/types/shared.py, src/fishaudio/types/asr.py, src/fishaudio/types/tts.py
Shared helpers store and retrieve response headers. ASRResponse and TTSTimestampResult expose headers through properties.
HTTP response propagation
src/fishaudio/core/iterators.py, src/fishaudio/resources/asr.py, src/fishaudio/resources/tts.py, tests/unit/test_response_headers.py, README.md
TTS streams receive HTTP response headers. Timestamp collection and ASR transcription attach headers to results. Tests cover HTTP header behavior, and the README documents header availability.
Realtime handshake headers
src/fishaudio/resources/asr_realtime.py, tests/unit/realtime_server.py, tests/unit/test_asr_realtime.py, tests/unit/test_response_headers.py
Realtime ASR streams expose handshake headers after connection. Tests cover synchronous and asynchronous sessions, including sessions that close or fail.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ASRRealtimeStream
  participant WebSocket
  participant HandshakeServer
  ASRRealtimeStream->>HandshakeServer: Open realtime connection
  HandshakeServer->>WebSocket: Accept connection with response headers
  WebSocket->>ASRRealtimeStream: Provide handshake response headers
  ASRRealtimeStream->>ASRRealtimeStream: Retain headers for access after session
Loading

Possibly related PRs

Suggested reviewers: leng-yue

Merge Risk: Minimal · up to 7e694

The change adds read-only access to response headers such as the trace ID and leaves existing client behavior unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: expose response headers on streams and results" matches the main change. The PR adds a read-only headers attribute or property to audio streams, timestamp streams, realtime ASR stream…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat: expose response headers on streams and results" matches the main change. The PR adds a read-only headers attribute or property to audio streams, timestamp streams, realtime ASR streams, ASRResponse, and TTSTimestampResult, so the title names the primary change without listing files. It uses the conventional commit prefix and is specific enough for a teammate scanning history.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 043b782c-8956-46ca-935e-be02af27b1c5
Commits

Reviewing files that changed from the base of the PR and between 171f471 and 7e694bf.

Files selected for processing: 11

  • README.md
  • src/fishaudio/core/iterators.py
  • src/fishaudio/resources/asr.py
  • src/fishaudio/resources/asr_realtime.py
  • src/fishaudio/resources/tts.py
  • src/fishaudio/types/asr.py
  • src/fishaudio/types/shared.py
  • src/fishaudio/types/tts.py
  • tests/unit/realtime_server.py
  • tests/unit/test_asr_realtime.py
  • tests/unit/test_response_headers.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/fishaudio/core/iterators.py 100.00% <100.00%> (ø)
src/fishaudio/resources/asr.py 100.00% <100.00%> (ø)
src/fishaudio/resources/asr_realtime.py 97.25% <100.00%> (+0.09%) ⬆️
src/fishaudio/resources/tts.py 96.58% <100.00%> (ø)
src/fishaudio/types/asr.py 100.00% <100.00%> (ø)
src/fishaudio/types/shared.py 100.00% <100.00%> (ø)
src/fishaudio/types/tts.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 headers to synchronous and asynchronous TTS streams and realtime ASR streams.
  • Attached response headers to ASRResponse and TTSTimestampResult without 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

@lumpinif
lumpinif merged commit 573a0da into main Dec 1, 2026
27 checks passed
@lumpinif
lumpinif deleted the feat/response-headers-on-success branch December 1, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants