fix(client): validate bearer auth for async web search and fetch - #745
Open
makiaveli1 wants to merge 1 commit into
Open
makiaveli1 wants to merge 1 commit into
makiaveli1 wants to merge 1 commit into
Conversation
Client.web_search and Client.web_fetch raise a ValueError when no Bearer token is configured, but the AsyncClient methods skipped that check, so async callers without an API key sent a request that failed later with a 401 ResponseError instead of the documented ValueError. Add the same check, and the matching docstring line, to the async methods.
This branch has not been deployed
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.
Client.web_searchandClient.web_fetchraise aValueErrorwhen no Bearer token is configured:The
AsyncClientversions of both methods omitted that check (and the matchingRaises:docstring line), so an async caller withoutOLLAMA_API_KEYdoes not get the documented error. The request goes out and comes back as aResponseErrorinstead:The async methods now perform the same check as their sync counterparts.
Verification:
python -m pytest tests/ -q-> 99 passedtest_async_client_web_search_requires_bearer_auth_headerandtest_async_client_web_fetch_requires_bearer_auth_header, mirror the existing sync tests. Both fail against the current code with the 401 above, and pass with this change.ruff checkandruff format --check-> cleanAI assistance: the analysis, fix and tests were prepared with an AI coding agent at my direction. I reproduced the behaviour locally, reviewed the change, and ran the checks above.