[GH-ISSUE #9229] add token counting api call #6016

Closed
opened 2026-04-12 17:21:36 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @trebor on GitHub (Feb 19, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/9229

in general, the context window size is super important. however i often feel like i am working blind as it is hard to identify the actual prompt size to see if it fits in context. as far as i can tell, the only way to know a prompt's token count, is to send it off and inspect prompt_eval_count in the result. this is very slow, and if the prompt exceeds the context window, the context window value is returned.

i'd love to be able to query for the token size of my prompt. with that, i could:

  • automatically adjust the context window to fit the prompt.
  • warn in a UI when a prompt exceeds the maximum context, especially if we could know what the maximum context is - see #9228.
Originally created by @trebor on GitHub (Feb 19, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/9229 in general, the context window size is **super important**. however i often feel like i am working blind as it is hard to identify the actual prompt size to see if it fits in context. as far as i can tell, the only way to know a prompt's token count, is to send it off and inspect **prompt_eval_count** in the result. this is very slow, and if the prompt exceeds the context window, the context window value is returned. i'd love to be able to query for the token size of my prompt. with that, i could: - automatically adjust the context window to fit the prompt. - warn in a UI when a prompt exceeds the maximum context, especially if we could know what the maximum context is - see #9228.
GiteaMirror added the feature request label 2026-04-12 17:21:36 -05:00
Author
Owner

@rick-github commented on GitHub (Feb 19, 2025):

https://github.com/ollama/ollama/issues/3582

<!-- gh-comment-id:2669713121 --> @rick-github commented on GitHub (Feb 19, 2025): https://github.com/ollama/ollama/issues/3582
Author
Owner

@trebor commented on GitHub (Feb 25, 2025):

tis a dup.

<!-- gh-comment-id:2683485200 --> @trebor commented on GitHub (Feb 25, 2025): tis a dup.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#6016