feat: wrap /v1/messages/count_tokens (regenerate core + ergonomic method)#10
Merged
Conversation
…at/count-tokens-wrapper
…hod) The gateway spec gained POST /v1/messages/count_tokens, which the endpoint-coverage drift gate flagged as unaccounted-for (CI red on main). This regenerates the client core to include the count_tokens operation (absorbs the open codegen PR) and adds a hand-written count_tokens() ergonomic method to the sync and async shells, mirroring message(). It returns a typed CountTokensResponse and omits max_tokens, since the endpoint only counts input tokens. The endpoint is listed under [covered] in sdk-endpoints.txt and covered by sync + async unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
The gateway OpenAPI spec gained
POST /v1/messages/count_tokens. The endpoint-coverage drift gate flagged it as unaccounted-for, so CI is red onmainand the SDK is not releasable as-is.This PR:
count_tokensoperation and itsCountTokensRequest/CountTokensResponsemodels (this absorbs the open codegen PR Regenerate SDK client core from gateway OpenAPI spec #8, which only regenerated the core and therefore would not have turned the gate green on its own).count_tokens()ergonomic method to both the sync (client.py) and async (async_client.py) shells, mirroring the existingmessage()wrapper. It returns a typedCountTokensResponseand omitsmax_tokens, since the endpoint only counts input tokens.POST /v1/messages/count_tokensunder[covered]insdk-endpoints.txt.Why one PR (core + shell together)
The pieces are interdependent: merging the core regen alone leaves the drift gate red (no manifest entry), and adding the wrapper without the regen would reference a generated method that does not exist yet. Landing them together keeps
maingreen at every step.Validation
Run locally:
uv run ruff check .-> passeduv run mypy src/-> passeduv run pytest tests/unit-> 111 passed (includes the drift gate, which now passes)Closes #9. Supersedes #8.