Repository navigation
Fix token counts, document the API, and limit abuse - #1
Merged
Merged
Conversation
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>
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.
Summary
drop_thinking,add_default_bos_token,reasoning_effort(highadds nothing on current V4), tools, tool calls, reasoning content, the 16 KiB / 4 KiB caps, and the error body.POST /v1/token/countis rate limited with the Workers Rate Limiting binding: 60 requests / 60 seconds per Cloudflare location, keyed onCF-Connecting-IP. A validAPI_KEYSbearer token is limited on a hash of that key instead. The endpoint stays public when the secret is unset.reprcannot be rebuilt from JSON numbers (22.0and22collapse afterJSON.parse).registry.npmjs.organd runsbun install --frozen-lockfile,bun run check, andbun run test.Notes
@cloudflare/vitest-pool-workersonly 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 awrangler deploy --dry-runbundle as an auxiliary worker.