Skip to content
How to retrieve AI ...
 
Notifications
Clear all

How to retrieve AI agent token usage details?

20 Posts
7 Users
0 Reactions
11 Views
solomon
(@solomon)
Posts: 78
Trusted Member
Topic starter
 

How can I retrieve this information? It's visible in the chat model, but I'm unable to access this data within my workflow.

I've encountered workarounds within the community, but perhaps there's now an official method?

Information on your callin.io setup

  • callin.io version: 1.84.3
  • Database (default: SQLite): default
  • callin.io EXECUTIONS_PROCESS setting (default: own, main): main
  • Running callin.io via (Docker, npm, callin.io cloud, desktop app): docker
  • Operating system: Ubuntu 24.04

EDIT: Solution Found :white_check_mark:

You can retrieve the execution data as a workaround and get the token usage information directly from the LLM model node.

 
Posted : 30/03/2025 12:13 pm
hubschrauber
(@hubschrauber)
Posts: 15
Active Member
 

I copied this workflow as-is into the same version (1.84.3) of callin.io (community) and my output doesn’t have that part (tokenUsage) at all. Is there something you have enabled in your settings for your actual OpenAI account to make that appear in the response?

 
Posted : 30/03/2025 1:29 pm
solomon
(@solomon)
Posts: 78
Trusted Member
Topic starter
 

The information resides within the OpenAI Chat Model node, not the AI Agent node.
Did you check that specific node?

That's precisely the issue. The data isn't available in the AI Agent's output, and I'm unsure how to access it from the chat model node.

:confused:

 
Posted : 30/03/2025 1:35 pm
hubschrauber
(@hubschrauber)
Posts: 15
Active Member
 

Ah, okay. Thanks for the clarification. It's a bit more frustrating when you know something exists but you're unable to access it.

 
Posted : 30/03/2025 1:37 pm
hubschrauber
(@hubschrauber)
Posts: 15
Active Member
 

For those looking to try this out or build upon the concept to see if it can be made to function, this appeared promising (a document was inserted), but the actual information was not retained.

 
Posted : 30/03/2025 1:58 pm
solomon
(@solomon)
Posts: 78
Trusted Member
Topic starter
 

Does the agent have access to the subnode token usage data? If you inquire, will it respond?

 
Posted : 30/03/2025 2:48 pm
hubschrauber
(@hubschrauber)
Posts: 15
Active Member
 

I'm not sure. I just thought it would be worth exploring. I would expect that if anything within the workflow has access to the tokenUsage information from the model, it would be the agent.

However, it would be an unusual interaction. What I attempted would essentially involve instructing the AI to return tool-usage instructions to the agent (in some manner) with sufficient comprehension of callin.io internals, the MongoDB client tool, and itself, to create a document, populate its data, and insert it. So, it "understood" some of the MongoDB aspects, but I was merely speculating on whether it would "understand" enough to inform the agent how to retrieve the tokenUsage statistics. It was likely a fruitless effort.

Furthermore, incorporating that into the System Message results in another "tool usage" call to the AI, consuming additional tokens, thus observing it changes it.

 
Posted : 30/03/2025 3:53 pm
davidvalerio1
(@davidvalerio1)
Posts: 1
New Member
 

Alguem ja tentou fazer a consulta por api direto no site da openai.com?

 
Posted : 21/04/2025 9:13 pm
mohamed3nan
(@mohamed3nan)
Posts: 18
Active Member
 

Hi there!

Is this what you were looking for?

Please provide the rewritten markdown content *it should be in the markdown format.

 
Posted : 21/04/2025 9:21 pm
solomon
(@solomon)
Posts: 78
Trusted Member
Topic starter
 

Unfortunately, no.

What I am trying to retrieve is the information from the model node:

If I open this node, I can see the token usage data:

However, if I attempt to retrieve that data in a subsequent node, this is all I see:

 
Posted : 21/04/2025 10:39 pm
jcuypers
(@jcuypers)
Posts: 29
Eminent Member
 

Hi

I'm confident you can retrieve this information from the underlying tables.

Here's a workflow that was recently shared, which is likely based on that approach:

Reg,
J.

 
Posted : 21/04/2025 10:48 pm
solomon
(@solomon)
Posts: 78
Trusted Member
Topic starter
 

Unfortunately, that's an estimator, not actual data extraction from the workflow.

From what I can see, it retrieves the text, the AI model, and sends it to an external service to estimate the cost. Very clever, but still a bit cumbersome.

 
Posted : 21/04/2025 11:10 pm
mohamed3nan
(@mohamed3nan)
Posts: 18
Active Member
 

Just wondering, what's the practical application for this? Is the idea to handle expenses for unusual cases?

 
Posted : 21/04/2025 11:16 pm
jcuypers
(@jcuypers)
Posts: 29
Eminent Member
 

Hi,

Potential use cases for a solution like this:

  • Cost management (internal/client-facing)
  • Security and abuse mitigation.
  • Alerting: similar to the above points.
  • Performance / debugging / monitoring: Analyzing response time per workflow versus tokens utilized.
  • Unified solution: I was previously exploring OpenAI stats to integrate into a Grafana dashboard, but this approach could encompass multiple model providers.

I'm confident there are even more possibilities.

 
Posted : 22/04/2025 4:25 am
solomon
(@solomon)
Posts: 78
Trusted Member
Topic starter
 

I operate callin.io as the backend for a SaaS initiative. When our users engage with our agents, I aim to record the token consumption to deduct it from their token balance.

Currently, the interim approach involves utilizing the OpenAI nodes rather than the AI Agent node.

However, we will soon require the AI Agent node as well.

 
Posted : 22/04/2025 3:51 pm
Page 1 / 2
Share: