Repository navigation
fix(py/anthropic): allow anthropic 1.x and 2.x - #165
Closed
huangjeff5 wants to merge 2 commits into
Closed
huangjeff5 wants to merge 2 commits into
huangjeff5 wants to merge 2 commits into
Conversation
Widen the anthropic spec to >=0.98.0,<3 and lock 2.10.0. anthropic 1.0 moved its transport to httpx2 and dropped temperature/top_p/top_k from messages.create(). The plugin now reads both off the installed SDK in _compat.py: mid-stream transport errors are caught from whichever httpx module the SDK's client subclasses, and sampling fields the SDK doesn't name go in extra_body (config.extra still wins over them). Tests build mock transports from the same module, accept the key as either x-api-key (<2) or Authorization: Bearer (2.x), and use context_management as the beta-only example since speed went GA in 1.x.
… module anthropic>=1 runs on httpx2 and rejects an httpx.AsyncClient, so the fake Vertex endpoint takes its transport from genkit_anthropic._compat.
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.
genkit-anthropic capped
anthropic<1, but anthropic 1.0 shipped 2026-08-20 and 2.0 on 2026-10-21 (latest 2.10.0). Anyone already on anthropic 1.x or 2.x couldn't install genkit-anthropic or Model Garden Claude. This widens the range toanthropic>=0.98.0,<3; the plugin works on 0.98, 1.x and 2.x.Main Changes
temperature,top_pandtop_kfrom themessages.create()/stream()signatures. The API still accepts them in the body, so passing them as Python keywords is aTypeError._build_paramsnow sends any request key the SDK'screate/streamdon't name throughextra_body, beforeconfig.extramerges, soextrastill wins on conflict. On 0.98 they stay keyword arguments._models.pylisted httpx exceptions only, so on 1.x a dropped stream would escape as an unmapped error. New_compat.pyfinds the HTTP library from the base class of the SDK'sDefaultAsyncHttpxClientand exposes the matching exception tuples, without version checks.Authorization: Bearerinstead ofx-api-key.pinned_credential_headeralready checked both, so no plugin change was needed; the test helper now accepts either.httpx.AsyncClientpassed ashttp_clientwith aTypeError. The genkit-anthropic and Model Garden fixtures now importhttpxfromgenkit_anthropic._compat. This is tests only; genkit-vertexai's source doesn't touch an HTTP client.Verification
pytest packages/genkit-anthropic: 391 passed, 5 skipped (live, no key) at anthropic 0.98.0 (floor), 1.17.0 (last 1.x) and 2.10.0 (lock).check_consistency.pyclean.Notes
http_clientmust build it fromhttpx2; the SDK raises a clearTypeErrorotherwise.base_urlthat only acceptsx-api-keywould break, since the SDK now sendsAuthorization: Bearer. That's SDK behavior._plugin.pyreadsclient.credentials). Conflicts with fix(py): enforce dependency bounds policy and raise declared floors #154 only on theanthropicspec line anduv.lock.