npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rawdash/connector-anthropic

v0.27.0

Published

Rawdash connector for Anthropic — daily token usage and spend from the Anthropic Admin API (usage and cost reports)

Readme

@rawdash/connector-anthropic

npm version license

Track Anthropic spend, daily token usage across Claude models, cache hit volumes, and web-search tool requests from the Anthropic Admin API.

Install

npm install @rawdash/connector-anthropic

Authentication

Authenticates with an Anthropic organization admin API key (sk-ant-admin-). Admin keys are the only key class that can read the Usage and Cost reports; regular API keys return 403.

  1. Open console.anthropic.com -> Settings -> Admin Keys and create a new admin key. Admin keys are organization-scoped, so create the key from the organization whose usage you want to read.
  2. Store the key as a secret (e.g. ANTHROPIC_ADMIN_API_KEY).
  3. Reference it from config as adminApiKey: secret("ANTHROPIC_ADMIN_API_KEY").
  4. Optionally set workspaceIds to restrict the query to a subset of workspaces.

Configuration

| Field | Type | Required | Description | | -------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | adminApiKey | secret | Yes | Anthropic organization admin API key (starts with sk-ant-admin-). Create one at console.anthropic.com -> Settings -> Admin keys. Regular API keys (sk-ant-api-) cannot read the Usage and Cost reports. | | workspaceIds | array | No | Restrict usage and cost queries to specific Anthropic workspace ids (wrkspc_...). Omit to aggregate every workspace the admin key can see. | | resources | array | No | Which Anthropic metric series to sync. Omit to sync all of them. The five usage metrics share one upstream call to the Messages Usage Report; enabling any one of them fetches the report and writes all five. | | lookbackDays | number | No | How many days of usage history to fetch on a full sync. Defaults to 30. The Usage Report returns at most 31 buckets per page, so longer windows paginate. |

Resources

  • anthropic_input_tokens (metric) - Daily uncached input tokens processed by the Anthropic Messages API, grouped by model and workspace.
    • Endpoint: GET /v1/organizations/usage_report/messages
    • Unit: tokens
    • Granularity: daily
    • Dimensions: model, workspace_id, api_key_id, service_tier, context_window, inference_geo
    • Sample value is uncached_input_tokens. Cache-read and cache-creation token volumes are mirrored on their own metrics so a cache hit ratio can be computed at query time.
  • anthropic_output_tokens (metric) - Daily output tokens generated by the Anthropic Messages API, grouped by model and workspace.
    • Endpoint: GET /v1/organizations/usage_report/messages
    • Unit: tokens
    • Granularity: daily
    • Dimensions: model, workspace_id, api_key_id, service_tier, context_window, inference_geo
    • Written alongside anthropic_input_tokens from the same usage_messages API call.
  • anthropic_cache_read_tokens (metric) - Daily input tokens read from the prompt cache, grouped by model and workspace.
    • Endpoint: GET /v1/organizations/usage_report/messages
    • Unit: tokens
    • Granularity: daily
    • Dimensions: model, workspace_id, api_key_id, service_tier, context_window, inference_geo
    • Cache hits are charged at a fraction of the uncached rate, so this metric paired with anthropic_input_tokens gives the cache hit ratio.
  • anthropic_cache_creation_tokens (metric) - Daily input tokens written into the prompt cache (sum of the 1h and 5m ephemeral caches), grouped by model and workspace.
    • Endpoint: GET /v1/organizations/usage_report/messages
    • Unit: tokens
    • Granularity: daily
    • Dimensions: model, workspace_id, api_key_id, service_tier, context_window, inference_geo
    • The per-cache-bucket counts (ephemeral_1h_input_tokens, ephemeral_5m_input_tokens) are mirrored in attributes for finer-grained widgets.
  • anthropic_web_search_requests (metric) - Daily count of web-search tool requests executed server-side by Claude, grouped by model and workspace.
    • Endpoint: GET /v1/organizations/usage_report/messages
    • Unit: requests
    • Granularity: daily
    • Dimensions: model, workspace_id, api_key_id, service_tier, context_window, inference_geo
    • Sourced from server_tool_use.web_search_requests on each usage bucket. Zero rows are still written so a "no usage today" widget renders correctly.
  • anthropic_cost_usd (metric) - Daily organization spend in USD, broken down by workspace and cost line item, pulled from the Anthropic Cost Report.
    • Endpoint: GET /v1/organizations/cost_report
    • Unit: USD
    • Granularity: daily
    • Dimensions: workspace_id, description, cost_type, model, token_type, service_tier, context_window, currency
    • The Cost Report returns amounts as a decimal string in the lowest currency unit (cents for USD). The connector divides by 100 so the stored metric value is dollars. Costs can be revised for a couple of days after the fact; incremental syncs refetch a short trailing window to pick up adjustments.

Example

import {
  defineConfig,
  defineDashboard,
  defineMetric,
  secret,
} from '@rawdash/core';

const anthropic = {
  name: 'anthropic',
  connectorId: 'anthropic',
  config: {
    adminApiKey: secret('ANTHROPIC_ADMIN_API_KEY'),
  },
};

export default defineConfig({
  connectors: [anthropic],
  dashboards: {
    ai: defineDashboard({
      widgets: {
        spend_mtd: {
          kind: 'stat',
          title: 'Anthropic spend (last 30d)',
          window: '30d',
          metric: defineMetric({
            connector: anthropic,
            shape: 'metric',
            name: 'anthropic_cost_usd',
            fn: 'sum',
          }),
        },
        input_tokens_today: {
          kind: 'stat',
          title: 'Input tokens today',
          window: '1d',
          metric: defineMetric({
            connector: anthropic,
            shape: 'metric',
            name: 'anthropic_input_tokens',
            fn: 'sum',
          }),
        },
      },
    }),
  },
});

Rate limits

The Admin API returns 429 with a Retry-After header on burst; the shared HTTP client honors it automatically. Daily syncs against the Usage and Cost reports are well below the per-organization Admin API budget.

Limitations

  • Only the organization Messages Usage Report and Cost Report endpoints are synced. Per-request logs and individual message bodies are not exposed by the Admin API.
  • All samples are bucketed daily (1d bucket_width). The Usage Report also supports hourly and per-minute granularity but those are not exposed here in v1.
  • The Cost Report only supports 1d bucket_width and reports cost in USD; non-USD billing currencies are not converted.
  • Admin API keys are required - regular sk-ant-api- keys do not have access to the organization Usage and Cost reports.

Links

License

Apache-2.0