Repository navigation
fix(py/anthropic): bound sampling config and map cache usage - #70
Merged
Merged
Conversation
Declare common_field_bounds ([0.0, 1.0]) on AnthropicConfig for temperature and top_p so out-of-range values fail locally with INVALID_ARGUMENT and advertise minimum/maximum in the Dev UI schema. Map Anthropic cache_read_input_tokens and cache_creation_input_tokens onto cached_content_tokens and cache_write_tokens, and include both in input_tokens and total_tokens so cached counts are subsets of input_tokens (matching Go, Gemini, OpenAI, and OpenTelemetry GenAI) while preserving Anthropic's raw keys on usage.custom.
huangjeff5
force-pushed
the
fix/py-anthropic-sampling-bounds-cache-usage
branch
from
November 11, 2026 02:11
118cba4 to
f83525e
Compare
huangjeff5
enabled auto-merge (squash)
November 11, 2026 16:45
This was referenced Nov 15, 2026
Merged
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.
Two Anthropic plugin bugs. An out-of-range
temperatureortop_pwas sent to Anthropic and came back as a provider HTTP 400. And on prompt-cached calls,response.usageundercounted:input_tokensheld only the uncached tail of the prompt, and the shared cache fields stayed empty, so cost dashboards read a 1,884-token prompt as 40 tokens.Changes
AnthropicConfigdeclarescommon_field_bounds = {'temperature': (0.0, 1.0), 'top_p': (0.0, 1.0)}. Bad values raiseINVALID_ARGUMENTlocally, which Retry middleware does not retry, and the Dev UI config form now shows theminimum/maximum. Vertex AI Model Garden's Claude models reuseAnthropicConfigand get the same bounds.input_tokensandtotal_tokens: Anthropic's rawinput_tokensexcludes tokens read from or written to the prompt cache.build_cache_usagenow adds both back, setscached_content_tokens(reads) andcache_write_tokens(writes), and leaves themNonewhen zero. Anthropic's raw keys stay onusage.custom.ai.generateandai.generate_streamgo through the same_build_usageand report identical usage.Breaking changes
None. The old
input_tokenswas wrong for cached calls; uncached calls report the same numbers as before.Cross-SDK
The Anthropic config JSON Schema the Dev UI reads now has
"minimum": 0.0, "maximum": 1.0ontemperatureandtopP. Usage in model responses and trace spans changes for cached calls:cachedContentTokensandcacheWriteTokensare already ingenkit-schema.json. InclusiveinputTokensis what Go, the Gemini and OpenAI plugins, and OpenTelemetry GenAI already report. JS Anthropic still reports the uncached tail ininputTokens; the JS owner may want the same fix.