Add support for custom session/client injection for proxy authentication#156
Open
Barneyjm wants to merge 4 commits intotavily-ai:masterfrom
Open
Add support for custom session/client injection for proxy authentication#156Barneyjm wants to merge 4 commits intotavily-ai:masterfrom
Barneyjm wants to merge 4 commits intotavily-ai:masterfrom
Conversation
- Add optional session parameter to __init__ - Preserve custom headers from provided session (e.g., Authorization) - Allows integration with enterprise API gateways requiring custom auth - Add tests for custom session functionality
521ad05 to
848a5d1
Compare
- Track whether session is external with _external_session flag - Only close internally-created sessions in close() method - Prevents closing shared sessions used across multiple clients - Add comprehensive tests for session lifecycle management
- Change proxy handling from unconditional .update() to conditional merge - Only add proxy for protocol if not already in session.proxies - Matches existing header preservation behavior for consistency - Custom session proxies now take precedence over: - proxies parameter - TAVILY_*_PROXY environment variables - Add 4 comprehensive tests for proxy preservation scenarios
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Author
|
this PR also allows for the functionality requested in #128 and allows more flexibility on top. |
- self.headers previously leaked session defaults (User-Agent, Accept-Encoding, etc.) - For custom sessions, also leaked user-defined headers - Now self.headers contains only Tavily-specific headers (Content-Type, Authorization, X-Client-Source, X-Project-ID) - This restores the original public API contract for self.headers attribute - Add comprehensive test to verify headers attribute semantics
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
Adds the ability to pass a custom
requests.Session(sync) orhttpx.AsyncClient(async) to Tavily clients, enabling integration with authentication proxies without distributing API keys to each application team.Motivation
When using Tavily behind an authentication proxy (e.g., client → some API Management → Tavily API), organizations need to:
Changes
TavilyClient: Added optionalsessionparameter to accept a pre-configuredrequests.SessionAsyncTavilyClient: Added optionalclientparameter to accept a pre-configuredhttpx.AsyncClientUsage Example