Skip to content

Enable custom token counting #7263

Closed
Closed

Description

@luisquintanilla

Currently, Tokenizer returns counts strictly based on tokens.

However, there are scenarios where library authors may want / need to implement their own custom token counting function.

One such scenario is providing token counts for image inputs. In such cases, AI service providers provide an arbitrary way of calculating cost based on a fixed token count.

Provider Cost calculations Does tokenization Link
OpenAI Fixed No https://platform.openai.com/docs/guides/vision/calculating-costs
Claude Fixed No https://docs.anthropic.com/en/docs/build-with-claude/vision#calculate-image-costs
Gemini Fixed No https://ai.google.dev/gemini-api/docs/tokens?lang=python#multimodal-tokens
Cohere N/A N/A https://docs.cohere.com/docs/tokens
Mistral N/A N/A https://docs.mistral.ai/guides/tokenization/#tokens-count

Activity

  1. rosebyte commented on Sep 23, 2026

    @rosebyte
    Member

    @luisquintanilla, could you please elaborate the request and ideally provide a use case?

  2. dotnet-policy-service commented on Sep 23, 2026

    @dotnet-policy-service
    Contributor

    This issue has been marked needs-author-action and may be missing some important information.

  3. dotnet-policy-service commented on Oct 7, 2026

    @dotnet-policy-service
    Contributor

    This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

  4. dotnet-policy-service commented on Oct 21, 2026

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

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-TokenizersText tokenisation and tokenizer APIsenhancementNew feature or requestgreendevelopmentneeds-author-actionMore information or action is needed from the authorno-recent-activityNo recent activity on this issue or pull request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions