[GH-ISSUE #7447] Feature Request: count tokens before calling '/v1/chat/completions' #51246

Closed
opened 2026-04-28 19:02:25 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @GPTLocalhost on GitHub (Oct 31, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7447

Recently, we integrated Microsoft Word with Ollama through a local Word Add-in. You can view a demo here. We're planning to add a feature to count tokens before calling '/v1/chat/completions,' allowing users to see the remaining tokens available for inference. Our question is: Is it possible for Ollama to count the tokens of the prompt before calling '/v1/chat/completions'? Thank you for your advice.

Originally created by @GPTLocalhost on GitHub (Oct 31, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7447 Recently, we integrated Microsoft Word with Ollama through a local Word Add-in. You can view a demo [here](https://gptlocalhost.com/demo/). We're planning to add a feature to count tokens before calling '/v1/chat/completions,' allowing users to see the remaining tokens available for inference. Our question is: Is it possible for Ollama to count the tokens of the prompt before calling '/v1/chat/completions'? Thank you for your advice.
GiteaMirror added the feature request label 2026-04-28 19:02:26 -05:00
Author
Owner

@rick-github commented on GitHub (Oct 31, 2024):

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

With a little effort, you can count tokens in the client if #3582 doesn't get merged: https://github.com/ollama/ollama/issues/7376#issuecomment-2439749060

<!-- gh-comment-id:2449686650 --> @rick-github commented on GitHub (Oct 31, 2024): https://github.com/ollama/ollama/issues/3582 With a little effort, you can count tokens in the client if #3582 doesn't get merged: https://github.com/ollama/ollama/issues/7376#issuecomment-2439749060
Author
Owner

@rick-github commented on GitHub (Dec 2, 2024):

dupe #3582

<!-- gh-comment-id:2511746016 --> @rick-github commented on GitHub (Dec 2, 2024): dupe #3582
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#51246