Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Logs LLM token usage per agent and user for billing, cost monitoring, and invoice generation in Convex agents.
41% 82%+41 ptsof test cases passed
Passed 18 of 22 test cases with the skill, and 9 of 22 without it.
3 of 3 safety checks passed
12 agent runs
Usage tracking records how many tokens each agent uses, enabling accurate billing, cost monitoring, and performance optimization. Essential for understanding LLM costs and user impact.
Create a handler to log usage:
// convex/agents/myAgent.ts
import { Agent } from "@convex-dev/agent";
import { components } from "../_generated/api";
import { openai } from "@ai-sdk/openai";
import { internal } from "../_generated/api";
const myAgent = new Agent(components.agent, {
name: "My Agent",
languageModel: openai.chat("gpt-4o-mini"),
usageHandler: async (ctx, args) => {
const {
userId,
threadId,
agentName,
model,
provider,
usage, // { inputTokens, outputTokens, totalTokens }
providerMetadata,
} = args;
Next to this one in the catalogue, plus more from the same author.