OpenAI tokens Usage via token_counter function

Hello,

I’m trying to integrate the token_counter function into Glide. I’m currently developing statistics for my app and need to accurately track my usage. My current method, which calculates based on input and output word counts, isn’t precise. It doesn’t distinguish between different languages, and some tokens comprise multiple words.

While it’s straightforward to achieve this with Python, I haven’t found a way to do it within Glide’s existing features. Is there a possible solution or workaround?

What exactly does the Python code do? Maybe it could be done with the JS column

It gives the number of tokens that OPEN AI used in the current API call. I’d love to solve my problem using JavaScript for this, if possible, but I’m unsure of how to proceed at the moment. I’ve set actions to “Send message to ChatGPT without history” and am a bit unclear on how to connect this Glide integration using a JS column.