Skip to content

Fix token counts, document the API, and limit abuse - #1

Merged
guuzaa merged 9 commits into
mainfrom
cursor/tokenizer-review-fixes-cef6
Oct 10, 2026
Merged

guuzaa merged 9 commits into
mainfrom
cursor/tokenizer-review-fixes-cef6

Conversation

@guuzaa

@guuzaa guuzaa commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • The README example is 11 tokens, checked with the real DeepSeek V4 tokenizer along with the other measured chats.
  • The README now documents drop_thinking, add_default_bos_token, reasoning_effort (high adds nothing on current V4), tools, tool calls, reasoning content, the 16 KiB / 4 KiB caps, and the error body.
  • POST /v1/token/count is rate limited with the Workers Rate Limiting binding: 60 requests / 60 seconds per Cloudflare location, keyed on CF-Connecting-IP. A valid API_KEYS bearer token is limited on a hash of that key instead. The endpoint stays public when the secret is unset.
  • Non-string tool content returns 400. Python dict repr cannot be rebuilt from JSON numbers (22.0 and 22 collapse after JSON.parse).
  • Workerd tests hit the bundled worker end to end. CI installs from registry.npmjs.org and runs bun install --frozen-lockfile, bun run check, and bun run test.

Notes

  • Not deployed. No secrets were created.
  • @cloudflare/vitest-pool-workers only supports Vitest 4. This repo is on Vitest 5, so the tests use @cloudflare/vitest-plugin (the renamed package). The 8 MiB tokenizer cannot travel over the Vitest socket, so the test loads a wrangler deploy --dry-run bundle as an auxiliary worker.
Open in Web Open in Cursor 

cursoragent and others added 9 commits October 10, 2026 00:57
The published example is 11 tokens. Count that prompt, and a few other measured chats, with the DeepSeek V4 tokenizer instead of a stub.

Co-authored-by: Jowell Young <guza@duck.com>
Cover drop_thinking, add_default_bos_token, reasoning_effort, tools, tool calls, reasoning content, the body and prompt caps, and the error body.

Co-authored-by: Jowell Young <guza@duck.com>
Use the Workers Rate Limiting binding, keyed on CF-Connecting-IP, and require a bearer token only when the API_KEYS secret is set.

Co-authored-by: Jowell Young <guza@duck.com>
Python's dict repr cannot be rebuilt from JSON numbers, so objects, numbers, booleans, and null return 400 instead of a guessed string.

Co-authored-by: Jowell Young <guza@duck.com>
Load the bundled worker as an auxiliary workerd worker so the 8 MiB tokenizer is not sent over the Vitest socket, and install from npmjs.org in GitHub Actions.

Co-authored-by: Jowell Young <guza@duck.com>
…er can be added beside DeepSeek V4.

Co-authored-by: Cursor <cursoragent@cursor.com>
…pSeek V4 vocabulary with that family.

Co-authored-by: Cursor <cursoragent@cursor.com>
@guuzaa
guuzaa merged commit f0d86ae into main Oct 10, 2026
1 check passed
@guuzaa
guuzaa deleted the cursor/tokenizer-review-fixes-cef6 branch October 10, 2026 13:01
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.

2 participants