Skip to content

feat: wrap /v1/messages/count_tokens (regenerate core + ergonomic method)#10

Merged
njbrake merged 3 commits into
mainfrom
feat/count-tokens-wrapper
Jun 10, 2026
Merged

feat: wrap /v1/messages/count_tokens (regenerate core + ergonomic method)#10
njbrake merged 3 commits into
mainfrom
feat/count-tokens-wrapper

Conversation

@njbrake

@njbrake njbrake commented Jun 10, 2026

Copy link
Copy Markdown
Member

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 on main and the SDK is not releasable as-is.

This PR:

  • Regenerates the client core to include the count_tokens operation and its CountTokensRequest / CountTokensResponse models (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).
  • Adds a hand-written count_tokens() ergonomic method to both the sync (client.py) and async (async_client.py) shells, mirroring the existing message() wrapper. It returns a typed CountTokensResponse and omits max_tokens, since the endpoint only counts input tokens.
  • Lists POST /v1/messages/count_tokens under [covered] in sdk-endpoints.txt.
  • Adds sync and async unit tests.

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 main green at every step.

Validation

Run locally:

  • uv run ruff check . -> passed
  • uv run mypy src/ -> passed
  • uv run pytest tests/unit -> 111 passed (includes the drift gate, which now passes)

Closes #9. Supersedes #8.

khaledosman and others added 3 commits June 9, 2026 15:19
…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>
@njbrake njbrake merged commit 6704e56 into main Jun 10, 2026
3 checks passed
@njbrake njbrake deleted the feat/count-tokens-wrapper branch June 10, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add independent release automation + surface gateway spec version

2 participants