@rawdash/connector-anthropic 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -0
- package/dist/index.d.ts +605 -0
- package/dist/index.js +628 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<!-- This file is generated from connector metadata by scripts/generate-connector-docs.ts. Do not edit by hand. -->
|
|
2
|
+
|
|
3
|
+
# @rawdash/connector-anthropic
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@rawdash/connector-anthropic)
|
|
6
|
+
[](https://github.com/rawdash/rawdash/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Track Anthropic spend, daily token usage across Claude models, cache hit volumes, and web-search tool requests from the Anthropic Admin API.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @rawdash/connector-anthropic
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Authentication
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
2. Store the key as a secret (e.g. ANTHROPIC_ADMIN_API_KEY).
|
|
22
|
+
3. Reference it from config as `adminApiKey: secret("ANTHROPIC_ADMIN_API_KEY")`.
|
|
23
|
+
4. Optionally set `workspaceIds` to restrict the query to a subset of workspaces.
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
| Field | Type | Required | Description |
|
|
28
|
+
| -------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| `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. |
|
|
30
|
+
| `workspaceIds` | array | No | Restrict usage and cost queries to specific Anthropic workspace ids (wrkspc\_...). Omit to aggregate every workspace the admin key can see. |
|
|
31
|
+
| `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. |
|
|
32
|
+
| `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. |
|
|
33
|
+
|
|
34
|
+
## Resources
|
|
35
|
+
|
|
36
|
+
- **`anthropic_input_tokens`** _(metric)_ - Daily uncached input tokens processed by the Anthropic Messages API, grouped by model and workspace.
|
|
37
|
+
- Endpoint: `GET /v1/organizations/usage_report/messages`
|
|
38
|
+
- Unit: tokens
|
|
39
|
+
- Granularity: daily
|
|
40
|
+
- Dimensions: `model`, `workspace_id`, `api_key_id`, `service_tier`, `context_window`, `inference_geo`
|
|
41
|
+
- 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.
|
|
42
|
+
- **`anthropic_output_tokens`** _(metric)_ - Daily output tokens generated by the Anthropic Messages API, grouped by model and workspace.
|
|
43
|
+
- Endpoint: `GET /v1/organizations/usage_report/messages`
|
|
44
|
+
- Unit: tokens
|
|
45
|
+
- Granularity: daily
|
|
46
|
+
- Dimensions: `model`, `workspace_id`, `api_key_id`, `service_tier`, `context_window`, `inference_geo`
|
|
47
|
+
- Written alongside anthropic_input_tokens from the same usage_messages API call.
|
|
48
|
+
- **`anthropic_cache_read_tokens`** _(metric)_ - Daily input tokens read from the prompt cache, grouped by model and workspace.
|
|
49
|
+
- Endpoint: `GET /v1/organizations/usage_report/messages`
|
|
50
|
+
- Unit: tokens
|
|
51
|
+
- Granularity: daily
|
|
52
|
+
- Dimensions: `model`, `workspace_id`, `api_key_id`, `service_tier`, `context_window`, `inference_geo`
|
|
53
|
+
- Cache hits are charged at a fraction of the uncached rate, so this metric paired with anthropic_input_tokens gives the cache hit ratio.
|
|
54
|
+
- **`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.
|
|
55
|
+
- Endpoint: `GET /v1/organizations/usage_report/messages`
|
|
56
|
+
- Unit: tokens
|
|
57
|
+
- Granularity: daily
|
|
58
|
+
- Dimensions: `model`, `workspace_id`, `api_key_id`, `service_tier`, `context_window`, `inference_geo`
|
|
59
|
+
- The per-cache-bucket counts (ephemeral_1h_input_tokens, ephemeral_5m_input_tokens) are mirrored in attributes for finer-grained widgets.
|
|
60
|
+
- **`anthropic_web_search_requests`** _(metric)_ - Daily count of web-search tool requests executed server-side by Claude, grouped by model and workspace.
|
|
61
|
+
- Endpoint: `GET /v1/organizations/usage_report/messages`
|
|
62
|
+
- Unit: requests
|
|
63
|
+
- Granularity: daily
|
|
64
|
+
- Dimensions: `model`, `workspace_id`, `api_key_id`, `service_tier`, `context_window`, `inference_geo`
|
|
65
|
+
- 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.
|
|
66
|
+
- **`anthropic_cost_usd`** _(metric)_ - Daily organization spend in USD, broken down by workspace and cost line item, pulled from the Anthropic Cost Report.
|
|
67
|
+
- Endpoint: `GET /v1/organizations/cost_report`
|
|
68
|
+
- Unit: USD
|
|
69
|
+
- Granularity: daily
|
|
70
|
+
- Dimensions: `workspace_id`, `description`, `cost_type`, `model`, `token_type`, `service_tier`, `context_window`, `currency`
|
|
71
|
+
- 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.
|
|
72
|
+
|
|
73
|
+
## Example
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import {
|
|
77
|
+
defineConfig,
|
|
78
|
+
defineDashboard,
|
|
79
|
+
defineMetric,
|
|
80
|
+
secret,
|
|
81
|
+
} from '@rawdash/core';
|
|
82
|
+
|
|
83
|
+
const anthropic = {
|
|
84
|
+
name: 'anthropic',
|
|
85
|
+
connectorId: 'anthropic',
|
|
86
|
+
config: {
|
|
87
|
+
adminApiKey: secret('ANTHROPIC_ADMIN_API_KEY'),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default defineConfig({
|
|
92
|
+
connectors: [anthropic],
|
|
93
|
+
dashboards: {
|
|
94
|
+
ai: defineDashboard({
|
|
95
|
+
widgets: {
|
|
96
|
+
spend_mtd: {
|
|
97
|
+
kind: 'stat',
|
|
98
|
+
title: 'Anthropic spend (last 30d)',
|
|
99
|
+
window: '30d',
|
|
100
|
+
metric: defineMetric({
|
|
101
|
+
connector: anthropic,
|
|
102
|
+
shape: 'metric',
|
|
103
|
+
name: 'anthropic_cost_usd',
|
|
104
|
+
fn: 'sum',
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
input_tokens_today: {
|
|
108
|
+
kind: 'stat',
|
|
109
|
+
title: 'Input tokens today',
|
|
110
|
+
window: '1d',
|
|
111
|
+
metric: defineMetric({
|
|
112
|
+
connector: anthropic,
|
|
113
|
+
shape: 'metric',
|
|
114
|
+
name: 'anthropic_input_tokens',
|
|
115
|
+
fn: 'sum',
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Rate limits
|
|
125
|
+
|
|
126
|
+
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.
|
|
127
|
+
|
|
128
|
+
## Limitations
|
|
129
|
+
|
|
130
|
+
- 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.
|
|
131
|
+
- 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.
|
|
132
|
+
- The Cost Report only supports 1d bucket_width and reports cost in USD; non-USD billing currencies are not converted.
|
|
133
|
+
- Admin API keys are required - regular sk-ant-api- keys do not have access to the organization Usage and Cost reports.
|
|
134
|
+
|
|
135
|
+
## Links
|
|
136
|
+
|
|
137
|
+
- [Rawdash docs](https://rawdash.dev/docs/connectors/)
|
|
138
|
+
- [Anthropic API docs](https://docs.claude.com/en/api/admin-api/usage-cost/get-messages-usage-report)
|
|
139
|
+
- [GitHub](https://github.com/rawdash/rawdash)
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
Apache-2.0
|