Communitygithub.com

Anthropic SDK 令牌用量记录器

使用 Anthropic TypeScript SDK 对 API 调用进行仪器化,记录每次请求的令牌用量、延迟和成本。包装 anthropic.messages.create 方法,捕获 API 响应中的 usage.input_tokens、usage.output_tokens 和计时信息,并通过 AWS SDK v3 的 CloudWatchLogsClient 将结构化日志写入 Amazon CloudWatch。

Anthropic SDK 令牌用量记录器 是什么?

该技能(技能)为使用 Anthropic TypeScript SDK 的开发者提供了一个自动化工具,用于记录和监控 Anthropic API 调用的令牌使用情况、延迟和成本。它通过包装 SDK 的 `messages.create` 方法,在每次 API 响应中自动提取 `usage.input_tokens`、`usage.output_tokens` 和请求延迟,从而实现对每个请求的细粒度观察。记录的结构化日志通过 AWS SDK v3 的 `CloudWatchLogsClient` 发送到 Amazon CloudWatch Logs,便于集中分析和警报。此技能适用于任何使用 Anthropic TypeScript SDK(v0.27.0 或更高版本)的 Node.js 18+ 环境,帮助团队优化提示设计、管理 API 成本并监控模型性能,无需手动添加日志代码。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/agentskillexchange/skills/tree/main/skills/anthropic-sdk-token-usage-logger

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Anthropic SDK 令牌用量记录器 是做什么的?

使用 Anthropic TypeScript SDK 对 API 调用进行仪器化,记录每次请求的令牌用量、延迟和成本。包装 anthropic.messages.create 方法,捕获 API 响应中的 usage.input_tokens、usage.output_tokens 和计时信息,并通过 AWS SDK v3 的 CloudWatchLogsClient 将结构化日志写入 CloudWatch Logs。

安装

使用与您环境匹配的上游安装或设置路径:

  • npm install @anthropic-ai/sdk

上游的需求和注意事项:

  • Node.js 18+

基本用法或入门说明:

文档

来源

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

Academic Paper Citation Network Mapper

Builds citation networks from Semantic Scholar API and CrossRef DOI metadata. Visualizes paper influence graphs using NetworkX, identifies seminal works, and tracks research lineage across fields.

ACF Custom Fields REST Exposer

Exposes Advanced Custom Fields data through the WordPress REST API using register_rest_field and acf_format_value. Handles repeater fields, flexible content layouts, and gallery fields with proper serialization.

ACF Extended for Advanced Custom Fields Workflows

An ASE skill built around ACF Extended, the WordPress enhancement suite for Advanced Custom Fields that adds field types, admin improvements, front-end forms, options pages, and developer tooling. It is a practical fit for agents working inside complex WordPress content models and custom field workflows.

ACF to Gutenberg Block Migrator

Converts Advanced Custom Fields field groups into native Gutenberg blocks using the ACF Block API v2 and @wordpress/scripts build pipeline. Maps ACF repeaters, groups, and flexible content to InnerBlocks and block attributes with server-side rendering via acf_register_block_type().

Activepieces Open Source Workflow Automation

Activepieces is an open-source, self-hostable workflow automation platform with 200+ integrations. It provides a visual builder for creating automated workflows and exposes all its connectors as MCP servers for AI agent use.

ActivityWatch Cross-Platform Automated Time Tracker and Producti

ActivityWatch is a privacy-first, open-source automated time tracker that records application usage, browser activity, and AFK status across Windows, macOS, and Linux. With 16k+ GitHub stars, it provides detailed productivity analytics without sending data to external servers.

act Local GitHub Actions Runner

act is an open-source CLI tool that runs GitHub Actions workflows locally using Docker, enabling fast feedback on workflow changes without pushing to GitHub. It is a standard tool for local Actions development and testing.

Add a browser review checkpoint before risky agent actions with

Use AgentClick when an agent should pause before risky commands, plans, drafts, or code changes so a human can inspect, edit, approve, or reject them in a purpose-built browser UI.

Add Claude design-system and accessibility workflows with UX/UI

Use UX/UI Agent Skills when Claude should generate tokens, component specs, accessibility audits, and framework-specific UI code from a repeatable design workflow.

Add executable smoke tests for shell scripts and CLIs before ref

Use Bats-core when an agent needs to turn fragile shell scripts or command-line workflows into something it can verify repeatedly after edits. The agent writes focused Bash tests for success paths, failure paths, and output contracts, then runs them locally or in CI before a refactor, release, or incident fix goes out.

Add graph-backed memory and context retrieval to agent workflows

Use Cognee to ingest project knowledge into graph and vector memory so agents can retrieve durable context across sessions and workflows.

Add IDE-style semantic code navigation and symbol-safe refactors

Give a coding agent symbol-aware lookup, cross-file rename, and structural edit tools before it starts making brittle text-only changes.

Add managed long-term memory to LangGraph agents with LangMem

Give LangGraph agents memory management and search tools so they can store, retrieve, and update durable facts across sessions.

Add multimodal lifelong memory to MCP and Python agents with Sim

Use SimpleMem to store, compress, index, and retrieve text or multimodal memories for agents through MCP or Python integrations.

Add persistent project memory and hook-driven synthesis with Cla

Keep Claude Code sessions grounded in prior decisions, project context, and daily handoff notes instead of starting from zero every time.

Add Postgres-native vector retrieval to agent and RAG workflows

Store embeddings beside application data in Postgres, create vector indexes, and query nearest neighbors for semantic search, RAG, recommendations, or agent memory retrieval.

Address GitHub PR review comments from the current branch with g

Find the open PR for the current branch, gather unresolved review comments, and drive a focused comment-resolution workflow with gh-authenticated context.

Add runtime guardrails to TypeScript agents with VoltAgent

Use VoltAgent to intercept, validate, and enforce input/output policies in TypeScript agent workflows.

Add temporal context memory to agent workflows with Zep

Use Zep as an external context layer for agents that need to store events, assemble temporal graph context, and retrieve relevant memory before model calls.

Adobe Firefly API Batch Image Generator

Calls Adobe Firefly

相关技能