# 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.

- Skill: `agentskillexchange/anthropic-sdk-token-usage-logger` (Agent Skill)
- Install (CLI): `npx skillmds@latest add agentskillexchange/anthropic-sdk-token-usage-logger`
- Raw SKILL.md: https://api.skillmd.com/api/skills/agentskillexchange/anthropic-sdk-token-usage-logger/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: agentskillexchange (https://skillmd.com/u/agentskillexchange)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/agentskillexchange/anthropic-sdk-token-usage-logger

---


# 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:
- sh
- js
- import Anthropic from '@anthropic-ai/sdk';

- Source: https://github.com/anthropics/anthropic-sdk-typescript
- Extracted from upstream docs: https://raw.githubusercontent.com/anthropics/anthropic-sdk-typescript/HEAD/README.md

## Documentation

- https://platform.claude.com/docs/en/api/sdks/typescript

## Source

- [Agent Skill Exchange](https://agentskillexchange.com/skills/anthropic-sdk-token-usage-logger/)

