Repository navigation
fix(anthropic): build message params as plain dicts so anthropic 2.x works - #1955
Merged
Yunnglin merged 1 commit intoOct 27, 2026
Merged
Conversation
anthropic 2.0 made MessageParam a Union of the user, assistant and system param types, so calling it raises "TypeError: Cannot instantiate typing.Union" and every anthropic_api eval fails before sending a request. The TypedDicts only ever produced dicts, so dict literals keep the same output on 0.x, 1.x and 2.x.
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.
anthropic 2.0.0 (2026-10-21) changed
anthropic.types.MessageParaminto aUnion[UserMessageParam, AssistantMessageParam, SystemMessageParam], so calling it now raisesevalscope doesn't pin anthropic, so anyone with a current install hits this on every
--eval-type anthropic_apirun, before any request goes out. The calls are all inevalscope/models/utils/anthropic.py(anthropic_message_paramand_combine_messages).This swaps the 7
MessageParam(...)calls for dict literals. The TypedDict "constructor" onlyever returned a dict, so the output is the same on older SDKs.
I checked the sampling params too: on 2.x
messages.createno longer hastemperature,top_por
top_k, butvalidate_request_paramsalready moves anything not in the signature intoextra_body, so those still get sent and don't raise. I left that alone.Testing (Python 3.13, Windows):
AnthropicCompatibleAPI.generate()withtemperature=0.0against a dead local port:main fails with the TypeError, this branch gets to the HTTP request (connection error, as expected)
ruff checkandruff format --checkclean