Apply the Bearer token guard to AsyncClient.web_search and web_fetch - #705
Open
ckarnell wants to merge 1 commit into
Open
Apply the Bearer token guard to AsyncClient.web_search and web_fetch#705ckarnell wants to merge 1 commit into
ckarnell wants to merge 1 commit into
Conversation
Client.web_search and Client.web_fetch raise ValueError when no Bearer token is configured. The AsyncClient versions had no such check, so an unconfigured async caller sent an unauthenticated request to ollama.com and got a 401 back instead of failing locally with an actionable message. Adds the same guard and the matching Raises: docstring section to both async methods, plus the two async tests that mirror the existing sync ones.
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_fetchboth check for a Bearer token before doing anything:The
AsyncClientversions of both methods have no such check. An async caller with noOLLAMA_API_KEYset does not get that error. The request goes out tohttps://ollama.com/api/web_searchunauthenticated and comes back as a 401, so the same mistakeproduces a clear local message on one client and a round trip plus a generic server error on the
other.
This looks like an oversight. The sync docstrings carry a
Raises:sectionfor exactly this and the async ones do not, and
tests/test_client.pyhastest_client_web_search_requires_bearer_auth_headerand theweb_fetchtwin covering the syncpath with no async equivalent, in a file that otherwise has 26 async tests.
To reproduce, with
OLLAMA_API_KEYunset:This adds the same guard and the matching
Raises:docstring line to both async methods, and thetwo async tests mirroring the existing sync ones. Both new tests fail without the change and pass
with it. Full suite is 95 passing,
ruff checkandruff format --checkboth clean.A note on severity. Not a security hole. Both clients talk to the same host, so no credential
goes anywhere new. The cost is a worse error message and a wasted round trip.
I did not check whether any other
AsyncClientmethod has a sync-only guard. I only lookedat the two that hit the hosted endpoints.