- Autonomous Nodes
- AI Cards
- Queries to a Knowledge Base
You will need:
Step 1: Create a table
- Create a new table named
SpendTable
. - Add two columns to the table:
- Cost (set the type to Number)
- ConversationID (set the type to String)

Step 2: Add a Hook to track AI spend
- Create a new Hook with the type After Turn End.
- Paste the following code into the Hook:
- Retrieves the AI spend for the current turn
- Convert the cost from nano-dollars into standard dollars
- Saves the cost and conversation ID to the
SpendTable
Step 3: Test your table
Try chatting with your bot in the emulator. After every message your bot sends, your table should automatically create a new row. The AI spend will display in the Cost column:
Your table will now keep a record of your bot’s AI spend for each turn.
Step 4 (Optional): Calculate total AI spend per conversation
Your table now stores the AI spend for each turn—but you can also store each conversation’s total AI spend in a separate table.- Create a second table named
TotalSpendTable
. - Add the same two columns as the first table:
- Cost (set the type to Number)
- ConversationID (set the type to String)
- Create a new Hook with the type After Conversation End.
- Paste the following code into the Hook:
- Retrieves the AI spend for each turn of the conversation
- Sums them up to get the total AI spend for the conversation
- Creates a row in
TotalSpendTable
with the total AI spend for the conversation