chatgpt-cli icon indicating copy to clipboard operation
chatgpt-cli copied to clipboard

Count tokens outside of `--interactive` mode

Open stephen010x opened this issue 1 year ago • 1 comments

I am wanting to write a script that will track my total token usage though the chatgpt-cli client, and the total cost of me using the tool through my own API key. Is there any way to do this outside of the --interactive mode?

stephen010x avatar Aug 12 '24 21:08 stephen010x

@stephen010x Not yet, but I can make that configurable. That's a fun idea.

kardolus avatar Aug 15 '24 18:08 kardolus

Fixed it in this commit: https://github.com/kardolus/chatgpt-cli/commit/70c808d6a232d71039e4ea71f0d58071da8e2089

Here's a test I just ran:

 2024-08-16 11:51:05 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
± |main ↑1 {1} ✓| → OPENAI_TRACK_TOKEN_USAGE=true OPENAI_THREAD=new_thread ./bin/chatgpt --query test
I'm here to help! How can I assist you today?

[Token Usage: 31]

kardolus avatar Aug 16 '24 15:08 kardolus