@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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import { BaseConnector, ConnectorContext, SyncOptions, StorageHandle, SyncResult, MetricSample, ConnectorDoc } from '@rawdash/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const configFields: z.ZodObject<{
|
|
5
|
+
adminApiKey: z.ZodObject<{
|
|
6
|
+
$secret: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
workspaceIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
9
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
10
|
+
anthropic_input_tokens: "anthropic_input_tokens";
|
|
11
|
+
anthropic_output_tokens: "anthropic_output_tokens";
|
|
12
|
+
anthropic_cache_read_tokens: "anthropic_cache_read_tokens";
|
|
13
|
+
anthropic_cache_creation_tokens: "anthropic_cache_creation_tokens";
|
|
14
|
+
anthropic_web_search_requests: "anthropic_web_search_requests";
|
|
15
|
+
anthropic_cost_usd: "anthropic_cost_usd";
|
|
16
|
+
}>>>;
|
|
17
|
+
lookbackDays: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
declare const doc: ConnectorDoc;
|
|
20
|
+
type AnthropicResource = 'anthropic_input_tokens' | 'anthropic_output_tokens' | 'anthropic_cache_read_tokens' | 'anthropic_cache_creation_tokens' | 'anthropic_web_search_requests' | 'anthropic_cost_usd';
|
|
21
|
+
declare const usageResultSchema: z.ZodObject<{
|
|
22
|
+
account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
api_key_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
cache_creation: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
25
|
+
ephemeral_1h_input_tokens: z.ZodNumber;
|
|
26
|
+
ephemeral_5m_input_tokens: z.ZodNumber;
|
|
27
|
+
}, z.core.$strip>>>;
|
|
28
|
+
cache_read_input_tokens: z.ZodNumber;
|
|
29
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
31
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
output_tokens: z.ZodNumber;
|
|
33
|
+
server_tool_use: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
34
|
+
web_search_requests: z.ZodNumber;
|
|
35
|
+
}, z.core.$strip>>>;
|
|
36
|
+
service_account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
38
|
+
uncached_input_tokens: z.ZodNumber;
|
|
39
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
declare const costResultSchema: z.ZodObject<{
|
|
42
|
+
amount: z.ZodString;
|
|
43
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
cost_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
currency: z.ZodString;
|
|
46
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
49
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
token_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
51
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
type UsageResult = z.infer<typeof usageResultSchema>;
|
|
54
|
+
type CostResult = z.infer<typeof costResultSchema>;
|
|
55
|
+
interface BucketPage<TResult> {
|
|
56
|
+
starting_at: string;
|
|
57
|
+
ending_at: string;
|
|
58
|
+
results: TResult[];
|
|
59
|
+
}
|
|
60
|
+
interface PageResponse<TResult> {
|
|
61
|
+
buckets: BucketPage<TResult>[];
|
|
62
|
+
nextPage: string | null;
|
|
63
|
+
}
|
|
64
|
+
declare const anthropicResources: {
|
|
65
|
+
readonly anthropic_input_tokens: {
|
|
66
|
+
readonly shape: "metric";
|
|
67
|
+
readonly description: "Daily uncached input tokens processed by the Anthropic Messages API, grouped by model and workspace.";
|
|
68
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
69
|
+
readonly unit: "tokens";
|
|
70
|
+
readonly granularity: "daily";
|
|
71
|
+
readonly dimensions: [{
|
|
72
|
+
readonly name: "model";
|
|
73
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
74
|
+
}, {
|
|
75
|
+
readonly name: "workspace_id";
|
|
76
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
77
|
+
}, {
|
|
78
|
+
readonly name: "api_key_id";
|
|
79
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
80
|
+
}, {
|
|
81
|
+
readonly name: "service_tier";
|
|
82
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
83
|
+
}, {
|
|
84
|
+
readonly name: "context_window";
|
|
85
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "inference_geo";
|
|
88
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
89
|
+
}];
|
|
90
|
+
readonly notes: "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.";
|
|
91
|
+
readonly responses: {
|
|
92
|
+
readonly usage_messages: z.ZodObject<{
|
|
93
|
+
data: z.ZodArray<z.ZodObject<{
|
|
94
|
+
starting_at: z.ZodString;
|
|
95
|
+
ending_at: z.ZodString;
|
|
96
|
+
results: z.ZodArray<z.ZodObject<{
|
|
97
|
+
account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
api_key_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
99
|
+
cache_creation: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
100
|
+
ephemeral_1h_input_tokens: z.ZodNumber;
|
|
101
|
+
ephemeral_5m_input_tokens: z.ZodNumber;
|
|
102
|
+
}, z.core.$strip>>>;
|
|
103
|
+
cache_read_input_tokens: z.ZodNumber;
|
|
104
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
105
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
106
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
107
|
+
output_tokens: z.ZodNumber;
|
|
108
|
+
server_tool_use: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
109
|
+
web_search_requests: z.ZodNumber;
|
|
110
|
+
}, z.core.$strip>>>;
|
|
111
|
+
service_account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
112
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
113
|
+
uncached_input_tokens: z.ZodNumber;
|
|
114
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
has_more: z.ZodBoolean;
|
|
118
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
readonly anthropic_output_tokens: {
|
|
123
|
+
readonly shape: "metric";
|
|
124
|
+
readonly description: "Daily output tokens generated by the Anthropic Messages API, grouped by model and workspace.";
|
|
125
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
126
|
+
readonly unit: "tokens";
|
|
127
|
+
readonly granularity: "daily";
|
|
128
|
+
readonly dimensions: [{
|
|
129
|
+
readonly name: "model";
|
|
130
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
131
|
+
}, {
|
|
132
|
+
readonly name: "workspace_id";
|
|
133
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
134
|
+
}, {
|
|
135
|
+
readonly name: "api_key_id";
|
|
136
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
137
|
+
}, {
|
|
138
|
+
readonly name: "service_tier";
|
|
139
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
140
|
+
}, {
|
|
141
|
+
readonly name: "context_window";
|
|
142
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
143
|
+
}, {
|
|
144
|
+
readonly name: "inference_geo";
|
|
145
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
146
|
+
}];
|
|
147
|
+
readonly notes: "Written alongside anthropic_input_tokens from the same usage_messages API call.";
|
|
148
|
+
};
|
|
149
|
+
readonly anthropic_cache_read_tokens: {
|
|
150
|
+
readonly shape: "metric";
|
|
151
|
+
readonly description: "Daily input tokens read from the prompt cache, grouped by model and workspace.";
|
|
152
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
153
|
+
readonly unit: "tokens";
|
|
154
|
+
readonly granularity: "daily";
|
|
155
|
+
readonly dimensions: [{
|
|
156
|
+
readonly name: "model";
|
|
157
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
158
|
+
}, {
|
|
159
|
+
readonly name: "workspace_id";
|
|
160
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
161
|
+
}, {
|
|
162
|
+
readonly name: "api_key_id";
|
|
163
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
164
|
+
}, {
|
|
165
|
+
readonly name: "service_tier";
|
|
166
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
167
|
+
}, {
|
|
168
|
+
readonly name: "context_window";
|
|
169
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
170
|
+
}, {
|
|
171
|
+
readonly name: "inference_geo";
|
|
172
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
173
|
+
}];
|
|
174
|
+
readonly notes: "Cache hits are charged at a fraction of the uncached rate, so this metric paired with anthropic_input_tokens gives the cache hit ratio.";
|
|
175
|
+
};
|
|
176
|
+
readonly anthropic_cache_creation_tokens: {
|
|
177
|
+
readonly shape: "metric";
|
|
178
|
+
readonly description: "Daily input tokens written into the prompt cache (sum of the 1h and 5m ephemeral caches), grouped by model and workspace.";
|
|
179
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
180
|
+
readonly unit: "tokens";
|
|
181
|
+
readonly granularity: "daily";
|
|
182
|
+
readonly dimensions: [{
|
|
183
|
+
readonly name: "model";
|
|
184
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
185
|
+
}, {
|
|
186
|
+
readonly name: "workspace_id";
|
|
187
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
188
|
+
}, {
|
|
189
|
+
readonly name: "api_key_id";
|
|
190
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
191
|
+
}, {
|
|
192
|
+
readonly name: "service_tier";
|
|
193
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
194
|
+
}, {
|
|
195
|
+
readonly name: "context_window";
|
|
196
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
197
|
+
}, {
|
|
198
|
+
readonly name: "inference_geo";
|
|
199
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
200
|
+
}];
|
|
201
|
+
readonly notes: "The per-cache-bucket counts (ephemeral_1h_input_tokens, ephemeral_5m_input_tokens) are mirrored in attributes for finer-grained widgets.";
|
|
202
|
+
};
|
|
203
|
+
readonly anthropic_web_search_requests: {
|
|
204
|
+
readonly shape: "metric";
|
|
205
|
+
readonly description: "Daily count of web-search tool requests executed server-side by Claude, grouped by model and workspace.";
|
|
206
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
207
|
+
readonly unit: "requests";
|
|
208
|
+
readonly granularity: "daily";
|
|
209
|
+
readonly dimensions: [{
|
|
210
|
+
readonly name: "model";
|
|
211
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
212
|
+
}, {
|
|
213
|
+
readonly name: "workspace_id";
|
|
214
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
215
|
+
}, {
|
|
216
|
+
readonly name: "api_key_id";
|
|
217
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
218
|
+
}, {
|
|
219
|
+
readonly name: "service_tier";
|
|
220
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
221
|
+
}, {
|
|
222
|
+
readonly name: "context_window";
|
|
223
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
224
|
+
}, {
|
|
225
|
+
readonly name: "inference_geo";
|
|
226
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
227
|
+
}];
|
|
228
|
+
readonly notes: "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.";
|
|
229
|
+
};
|
|
230
|
+
readonly anthropic_cost_usd: {
|
|
231
|
+
readonly shape: "metric";
|
|
232
|
+
readonly description: "Daily organization spend in USD, broken down by workspace and cost line item, pulled from the Anthropic Cost Report.";
|
|
233
|
+
readonly endpoint: "GET /v1/organizations/cost_report";
|
|
234
|
+
readonly unit: "USD";
|
|
235
|
+
readonly granularity: "daily";
|
|
236
|
+
readonly dimensions: [{
|
|
237
|
+
readonly name: "workspace_id";
|
|
238
|
+
readonly description: "Anthropic workspace id the cost is attributed to (or null for the default workspace).";
|
|
239
|
+
}, {
|
|
240
|
+
readonly name: "description";
|
|
241
|
+
readonly description: "Human-readable cost line item label (e.g. \"Claude Sonnet 4 Usage - Input Tokens\"), or null when ungrouped.";
|
|
242
|
+
}, {
|
|
243
|
+
readonly name: "cost_type";
|
|
244
|
+
readonly description: "Cost category (tokens, web_search, code_execution, session_usage), or null.";
|
|
245
|
+
}, {
|
|
246
|
+
readonly name: "model";
|
|
247
|
+
readonly description: "Claude model the cost is attributed to (or null for non-token costs).";
|
|
248
|
+
}, {
|
|
249
|
+
readonly name: "token_type";
|
|
250
|
+
readonly description: "Token category for token costs (uncached_input_tokens, output_tokens, cache_read_input_tokens, cache_creation.ephemeral_*_input_tokens), or null.";
|
|
251
|
+
}, {
|
|
252
|
+
readonly name: "service_tier";
|
|
253
|
+
readonly description: "Service tier the cost is attributed to (standard or batch), or null.";
|
|
254
|
+
}, {
|
|
255
|
+
readonly name: "context_window";
|
|
256
|
+
readonly description: "Context window the cost is attributed to (0-200k or 200k-1M), or null.";
|
|
257
|
+
}, {
|
|
258
|
+
readonly name: "currency";
|
|
259
|
+
readonly description: "Billing currency reported by Anthropic (currently always USD).";
|
|
260
|
+
}];
|
|
261
|
+
readonly notes: "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.";
|
|
262
|
+
readonly responses: {
|
|
263
|
+
readonly cost_report: z.ZodObject<{
|
|
264
|
+
data: z.ZodArray<z.ZodObject<{
|
|
265
|
+
starting_at: z.ZodString;
|
|
266
|
+
ending_at: z.ZodString;
|
|
267
|
+
results: z.ZodArray<z.ZodObject<{
|
|
268
|
+
amount: z.ZodString;
|
|
269
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
270
|
+
cost_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
271
|
+
currency: z.ZodString;
|
|
272
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
273
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
274
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
275
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
276
|
+
token_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
277
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
278
|
+
}, z.core.$strip>>;
|
|
279
|
+
}, z.core.$strip>>;
|
|
280
|
+
has_more: z.ZodBoolean;
|
|
281
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
282
|
+
}, z.core.$strip>;
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
interface AnthropicSettings {
|
|
287
|
+
workspaceIds?: readonly string[];
|
|
288
|
+
resources?: readonly AnthropicResource[];
|
|
289
|
+
lookbackDays?: number;
|
|
290
|
+
}
|
|
291
|
+
declare const anthropicCredentials: {
|
|
292
|
+
adminApiKey: {
|
|
293
|
+
description: string;
|
|
294
|
+
auth: "required";
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
type AnthropicCredentials = typeof anthropicCredentials;
|
|
298
|
+
declare const id = "anthropic";
|
|
299
|
+
interface UsageWindow {
|
|
300
|
+
startingAt: string;
|
|
301
|
+
endingAt: string;
|
|
302
|
+
}
|
|
303
|
+
declare function getUsageWindow(options: SyncOptions, lookbackDays: number, now?: number): UsageWindow;
|
|
304
|
+
declare function buildUsageSamples(buckets: readonly BucketPage<UsageResult>[]): {
|
|
305
|
+
inputTokens: MetricSample[];
|
|
306
|
+
outputTokens: MetricSample[];
|
|
307
|
+
cacheReadTokens: MetricSample[];
|
|
308
|
+
cacheCreationTokens: MetricSample[];
|
|
309
|
+
webSearchRequests: MetricSample[];
|
|
310
|
+
};
|
|
311
|
+
declare function buildCostSamples(buckets: readonly BucketPage<CostResult>[]): MetricSample[];
|
|
312
|
+
declare class AnthropicConnector extends BaseConnector<AnthropicSettings, AnthropicCredentials> {
|
|
313
|
+
static readonly id = "anthropic";
|
|
314
|
+
static readonly resources: {
|
|
315
|
+
readonly anthropic_input_tokens: {
|
|
316
|
+
readonly shape: "metric";
|
|
317
|
+
readonly description: "Daily uncached input tokens processed by the Anthropic Messages API, grouped by model and workspace.";
|
|
318
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
319
|
+
readonly unit: "tokens";
|
|
320
|
+
readonly granularity: "daily";
|
|
321
|
+
readonly dimensions: [{
|
|
322
|
+
readonly name: "model";
|
|
323
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
324
|
+
}, {
|
|
325
|
+
readonly name: "workspace_id";
|
|
326
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
327
|
+
}, {
|
|
328
|
+
readonly name: "api_key_id";
|
|
329
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
330
|
+
}, {
|
|
331
|
+
readonly name: "service_tier";
|
|
332
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
333
|
+
}, {
|
|
334
|
+
readonly name: "context_window";
|
|
335
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
336
|
+
}, {
|
|
337
|
+
readonly name: "inference_geo";
|
|
338
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
339
|
+
}];
|
|
340
|
+
readonly notes: "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.";
|
|
341
|
+
readonly responses: {
|
|
342
|
+
readonly usage_messages: z.ZodObject<{
|
|
343
|
+
data: z.ZodArray<z.ZodObject<{
|
|
344
|
+
starting_at: z.ZodString;
|
|
345
|
+
ending_at: z.ZodString;
|
|
346
|
+
results: z.ZodArray<z.ZodObject<{
|
|
347
|
+
account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
348
|
+
api_key_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
349
|
+
cache_creation: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
350
|
+
ephemeral_1h_input_tokens: z.ZodNumber;
|
|
351
|
+
ephemeral_5m_input_tokens: z.ZodNumber;
|
|
352
|
+
}, z.core.$strip>>>;
|
|
353
|
+
cache_read_input_tokens: z.ZodNumber;
|
|
354
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
355
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
356
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
357
|
+
output_tokens: z.ZodNumber;
|
|
358
|
+
server_tool_use: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
359
|
+
web_search_requests: z.ZodNumber;
|
|
360
|
+
}, z.core.$strip>>>;
|
|
361
|
+
service_account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
362
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
363
|
+
uncached_input_tokens: z.ZodNumber;
|
|
364
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
365
|
+
}, z.core.$strip>>;
|
|
366
|
+
}, z.core.$strip>>;
|
|
367
|
+
has_more: z.ZodBoolean;
|
|
368
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
369
|
+
}, z.core.$strip>;
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
readonly anthropic_output_tokens: {
|
|
373
|
+
readonly shape: "metric";
|
|
374
|
+
readonly description: "Daily output tokens generated by the Anthropic Messages API, grouped by model and workspace.";
|
|
375
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
376
|
+
readonly unit: "tokens";
|
|
377
|
+
readonly granularity: "daily";
|
|
378
|
+
readonly dimensions: [{
|
|
379
|
+
readonly name: "model";
|
|
380
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
381
|
+
}, {
|
|
382
|
+
readonly name: "workspace_id";
|
|
383
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
384
|
+
}, {
|
|
385
|
+
readonly name: "api_key_id";
|
|
386
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
387
|
+
}, {
|
|
388
|
+
readonly name: "service_tier";
|
|
389
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
390
|
+
}, {
|
|
391
|
+
readonly name: "context_window";
|
|
392
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
393
|
+
}, {
|
|
394
|
+
readonly name: "inference_geo";
|
|
395
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
396
|
+
}];
|
|
397
|
+
readonly notes: "Written alongside anthropic_input_tokens from the same usage_messages API call.";
|
|
398
|
+
};
|
|
399
|
+
readonly anthropic_cache_read_tokens: {
|
|
400
|
+
readonly shape: "metric";
|
|
401
|
+
readonly description: "Daily input tokens read from the prompt cache, grouped by model and workspace.";
|
|
402
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
403
|
+
readonly unit: "tokens";
|
|
404
|
+
readonly granularity: "daily";
|
|
405
|
+
readonly dimensions: [{
|
|
406
|
+
readonly name: "model";
|
|
407
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
408
|
+
}, {
|
|
409
|
+
readonly name: "workspace_id";
|
|
410
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
411
|
+
}, {
|
|
412
|
+
readonly name: "api_key_id";
|
|
413
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
414
|
+
}, {
|
|
415
|
+
readonly name: "service_tier";
|
|
416
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
417
|
+
}, {
|
|
418
|
+
readonly name: "context_window";
|
|
419
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
420
|
+
}, {
|
|
421
|
+
readonly name: "inference_geo";
|
|
422
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
423
|
+
}];
|
|
424
|
+
readonly notes: "Cache hits are charged at a fraction of the uncached rate, so this metric paired with anthropic_input_tokens gives the cache hit ratio.";
|
|
425
|
+
};
|
|
426
|
+
readonly anthropic_cache_creation_tokens: {
|
|
427
|
+
readonly shape: "metric";
|
|
428
|
+
readonly description: "Daily input tokens written into the prompt cache (sum of the 1h and 5m ephemeral caches), grouped by model and workspace.";
|
|
429
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
430
|
+
readonly unit: "tokens";
|
|
431
|
+
readonly granularity: "daily";
|
|
432
|
+
readonly dimensions: [{
|
|
433
|
+
readonly name: "model";
|
|
434
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
435
|
+
}, {
|
|
436
|
+
readonly name: "workspace_id";
|
|
437
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
438
|
+
}, {
|
|
439
|
+
readonly name: "api_key_id";
|
|
440
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
441
|
+
}, {
|
|
442
|
+
readonly name: "service_tier";
|
|
443
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
444
|
+
}, {
|
|
445
|
+
readonly name: "context_window";
|
|
446
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
447
|
+
}, {
|
|
448
|
+
readonly name: "inference_geo";
|
|
449
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
450
|
+
}];
|
|
451
|
+
readonly notes: "The per-cache-bucket counts (ephemeral_1h_input_tokens, ephemeral_5m_input_tokens) are mirrored in attributes for finer-grained widgets.";
|
|
452
|
+
};
|
|
453
|
+
readonly anthropic_web_search_requests: {
|
|
454
|
+
readonly shape: "metric";
|
|
455
|
+
readonly description: "Daily count of web-search tool requests executed server-side by Claude, grouped by model and workspace.";
|
|
456
|
+
readonly endpoint: "GET /v1/organizations/usage_report/messages";
|
|
457
|
+
readonly unit: "requests";
|
|
458
|
+
readonly granularity: "daily";
|
|
459
|
+
readonly dimensions: [{
|
|
460
|
+
readonly name: "model";
|
|
461
|
+
readonly description: "Claude model id reported by Anthropic (or null).";
|
|
462
|
+
}, {
|
|
463
|
+
readonly name: "workspace_id";
|
|
464
|
+
readonly description: "Anthropic workspace id the usage is attributed to (or null for the default workspace).";
|
|
465
|
+
}, {
|
|
466
|
+
readonly name: "api_key_id";
|
|
467
|
+
readonly description: "API key id the usage is attributed to (or null).";
|
|
468
|
+
}, {
|
|
469
|
+
readonly name: "service_tier";
|
|
470
|
+
readonly description: "Service tier the request ran under (standard, batch, priority, flex, etc.), or null.";
|
|
471
|
+
}, {
|
|
472
|
+
readonly name: "context_window";
|
|
473
|
+
readonly description: "Context window bucket the request used (0-200k or 200k-1M), or null.";
|
|
474
|
+
}, {
|
|
475
|
+
readonly name: "inference_geo";
|
|
476
|
+
readonly description: "Inference geo the request ran in (global, us, not_available), or null.";
|
|
477
|
+
}];
|
|
478
|
+
readonly notes: "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.";
|
|
479
|
+
};
|
|
480
|
+
readonly anthropic_cost_usd: {
|
|
481
|
+
readonly shape: "metric";
|
|
482
|
+
readonly description: "Daily organization spend in USD, broken down by workspace and cost line item, pulled from the Anthropic Cost Report.";
|
|
483
|
+
readonly endpoint: "GET /v1/organizations/cost_report";
|
|
484
|
+
readonly unit: "USD";
|
|
485
|
+
readonly granularity: "daily";
|
|
486
|
+
readonly dimensions: [{
|
|
487
|
+
readonly name: "workspace_id";
|
|
488
|
+
readonly description: "Anthropic workspace id the cost is attributed to (or null for the default workspace).";
|
|
489
|
+
}, {
|
|
490
|
+
readonly name: "description";
|
|
491
|
+
readonly description: "Human-readable cost line item label (e.g. \"Claude Sonnet 4 Usage - Input Tokens\"), or null when ungrouped.";
|
|
492
|
+
}, {
|
|
493
|
+
readonly name: "cost_type";
|
|
494
|
+
readonly description: "Cost category (tokens, web_search, code_execution, session_usage), or null.";
|
|
495
|
+
}, {
|
|
496
|
+
readonly name: "model";
|
|
497
|
+
readonly description: "Claude model the cost is attributed to (or null for non-token costs).";
|
|
498
|
+
}, {
|
|
499
|
+
readonly name: "token_type";
|
|
500
|
+
readonly description: "Token category for token costs (uncached_input_tokens, output_tokens, cache_read_input_tokens, cache_creation.ephemeral_*_input_tokens), or null.";
|
|
501
|
+
}, {
|
|
502
|
+
readonly name: "service_tier";
|
|
503
|
+
readonly description: "Service tier the cost is attributed to (standard or batch), or null.";
|
|
504
|
+
}, {
|
|
505
|
+
readonly name: "context_window";
|
|
506
|
+
readonly description: "Context window the cost is attributed to (0-200k or 200k-1M), or null.";
|
|
507
|
+
}, {
|
|
508
|
+
readonly name: "currency";
|
|
509
|
+
readonly description: "Billing currency reported by Anthropic (currently always USD).";
|
|
510
|
+
}];
|
|
511
|
+
readonly notes: "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.";
|
|
512
|
+
readonly responses: {
|
|
513
|
+
readonly cost_report: z.ZodObject<{
|
|
514
|
+
data: z.ZodArray<z.ZodObject<{
|
|
515
|
+
starting_at: z.ZodString;
|
|
516
|
+
ending_at: z.ZodString;
|
|
517
|
+
results: z.ZodArray<z.ZodObject<{
|
|
518
|
+
amount: z.ZodString;
|
|
519
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
520
|
+
cost_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
521
|
+
currency: z.ZodString;
|
|
522
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
523
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
524
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
525
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
526
|
+
token_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
527
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
528
|
+
}, z.core.$strip>>;
|
|
529
|
+
}, z.core.$strip>>;
|
|
530
|
+
has_more: z.ZodBoolean;
|
|
531
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
532
|
+
}, z.core.$strip>;
|
|
533
|
+
};
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
static readonly schemas: object & {
|
|
537
|
+
readonly usage_messages: z.ZodObject<{
|
|
538
|
+
data: z.ZodArray<z.ZodObject<{
|
|
539
|
+
starting_at: z.ZodString;
|
|
540
|
+
ending_at: z.ZodString;
|
|
541
|
+
results: z.ZodArray<z.ZodObject<{
|
|
542
|
+
account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
543
|
+
api_key_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
544
|
+
cache_creation: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
545
|
+
ephemeral_1h_input_tokens: z.ZodNumber;
|
|
546
|
+
ephemeral_5m_input_tokens: z.ZodNumber;
|
|
547
|
+
}, z.core.$strip>>>;
|
|
548
|
+
cache_read_input_tokens: z.ZodNumber;
|
|
549
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
550
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
551
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
552
|
+
output_tokens: z.ZodNumber;
|
|
553
|
+
server_tool_use: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
554
|
+
web_search_requests: z.ZodNumber;
|
|
555
|
+
}, z.core.$strip>>>;
|
|
556
|
+
service_account_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
557
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
558
|
+
uncached_input_tokens: z.ZodNumber;
|
|
559
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
560
|
+
}, z.core.$strip>>;
|
|
561
|
+
}, z.core.$strip>>;
|
|
562
|
+
has_more: z.ZodBoolean;
|
|
563
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
564
|
+
}, z.core.$strip>;
|
|
565
|
+
} & {
|
|
566
|
+
readonly cost_report: z.ZodObject<{
|
|
567
|
+
data: z.ZodArray<z.ZodObject<{
|
|
568
|
+
starting_at: z.ZodString;
|
|
569
|
+
ending_at: z.ZodString;
|
|
570
|
+
results: z.ZodArray<z.ZodObject<{
|
|
571
|
+
amount: z.ZodString;
|
|
572
|
+
context_window: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
573
|
+
cost_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
574
|
+
currency: z.ZodString;
|
|
575
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
576
|
+
inference_geo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
577
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
578
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
579
|
+
token_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
580
|
+
workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
581
|
+
}, z.core.$strip>>;
|
|
582
|
+
}, z.core.$strip>>;
|
|
583
|
+
has_more: z.ZodBoolean;
|
|
584
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
585
|
+
}, z.core.$strip>;
|
|
586
|
+
} & Readonly<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
587
|
+
static create(input: unknown, ctx?: ConnectorContext): AnthropicConnector;
|
|
588
|
+
readonly id = "anthropic";
|
|
589
|
+
readonly credentials: {
|
|
590
|
+
adminApiKey: {
|
|
591
|
+
description: string;
|
|
592
|
+
auth: "required";
|
|
593
|
+
};
|
|
594
|
+
};
|
|
595
|
+
private buildHeaders;
|
|
596
|
+
private fetch;
|
|
597
|
+
private buildInitialUrl;
|
|
598
|
+
private buildNextUrl;
|
|
599
|
+
private fetchPhasePage;
|
|
600
|
+
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
601
|
+
private fetchAnyPhasePage;
|
|
602
|
+
private writePhase;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export { AnthropicConnector, type AnthropicResource, type AnthropicSettings, type BucketPage, type CostResult, type PageResponse, type UsageResult, buildCostSamples, buildUsageSamples, configFields, AnthropicConnector as default, doc, getUsageWindow, id, anthropicResources as resources };
|