Token Usage
Monitor costs and resource consumption by tracking input/output tokens and estimated spend for individual requests or entire chat sessions.
Table of contents
Track tokens for individual turns or the entire conversation to monitor costs and usage.
Per-Response Usage
Every response object contains usage metadata for that specific interaction.
const response = await chat.ask(“Hello!”);
// Standard Snake Case console.log(response.input_tokens);
// Modern Camel Case Alias v1.6.0 console.log(response.inputTokens);
// Full Metadata Object (Perfect for DB storage) v1.6.0 console.log(response.meta); // => { usage: {…}, model: “…”, provider: “…”, reasoning: “…” }
## Session Totals
The `Chat` instance maintains a running total of usage for the life of that object.
```ts
// Access aggregated usage for the whole session
console.log(chat.totalUsage.total_tokens);
console.log(chat.totalUsage.cost);