Skip to content

Exact token counting (optional tiktoken or a custom tokenizer) #15

Description

@TheCoder30ec4

Motivation

estimate_tokens assumes about 4 characters per token. That undercounts code, CJK text and emoji, so a prompt can pass the context check and still overflow at the provider.

Proposal

  • Router(..., count_tokens=callable) lets users plug in their own counter
  • Optional extra: pip install model-router-python[tiktoken]; use tiktoken when it's installed, otherwise fall back to the heuristic
  • The core package keeps zero required dependencies

Done when

  • The custom counter is used for both the context and the cost checks
  • Tests with a fake counter

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routingRouter, limits and the Jev requestenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions