feat: add extra_headers support to all client methods#193
Merged
Kamilbenkirane merged 3 commits intomainfrom Feb 25, 2026
Merged
feat: add extra_headers support to all client methods#193Kamilbenkirane merged 3 commits intomainfrom
Kamilbenkirane merged 3 commits intomainfrom
Conversation
Add `extra_headers: dict[str, str] | None = None` alongside `extra_body` on all client methods, enabling users to pass provider-specific HTTP headers (e.g., Anthropic's 1M context beta header). - Extend `_json_headers()` to accept and merge extra headers - Add `_merge_headers()` static helper for edge cases (WebSocket, multipart) - Thread `extra_headers` through `_predict()` → `_make_request()` and `_stream()` → `_make_stream_request()` across all providers - Update all 3 templates and the template contract test Closes #178 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
- Make _merge_headers return a new dict instead of mutating input - Add extra_headers to base _make_stream_request stub signature - Fix OpenAI videos multipart sending wrong Content-Type - Add extra_headers to Google _get_interaction and download_content - Simplify BFL header construction to use _json_headers(extra_headers) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extra_headers: dict[str, str] | None = Nonealongsideextra_bodyon all client methods (generate,stream,analyze,speak,embed,edit)_json_headers()to accept and merge user headers for the common case (~28 call sites)_merge_headers()static helper for edge cases that bypass_json_headers(WebSocket, multipart, custom poll headers)_build_headers()acceptsextra_headersand applies it last so user headers win over version + beta headersextra_headersvalidation to the template contract testUsage
Test plan
extra_headersparam on all provider API clientsCloses #178