Anthropic SDK Token Usage Logger

Instruments Anthropic API calls to log token usage, latency, and cost per request using the Anthropic TypeScript SDK. Wraps the anthropic.messages.create method to capture usage.input_tokens, usage.output_tokens, and timing from the API response. Writes structured logs to CloudWatch Logs via the AWS SDK v3 CloudWatchLogsClient.

agentskillexchange Updated 28 repo stars

File contents

Anthropic SDK Token Usage Logger

Instruments Anthropic API calls to log token usage, latency, and cost per request using the Anthropic TypeScript SDK. Wraps the anthropic.messages.create method to capture usage.input_tokens, usage.output_tokens, and timing from the API response. Writes structured logs to CloudWatch Logs via the AWS SDK v3 CloudWatchLogsClient.

Installation

Use the upstream install or setup path that matches your environment:

  • npm install @anthropic-ai/sdk

Requirements and caveats from upstream:

  • Node.js 18+

Basic usage or getting-started notes:

Documentation

Source

agentskillexchange/skills/tree/main/skills/anthropic-sdk-token-usage-logger commit d170da9fd4

Frequently asked questions

npx skillmds@latest add agentskillexchange/anthropic-sdk-token-usage-logger