@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
77 lines • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cost = void 0;
const resource_1 = require("../../../../core/resource.js");
const pagination_1 = require("../../../../core/pagination.js");
const headers_1 = require("../../../../internal/headers.js");
const tracing_1 = require("../../../../internal/tracing.js");
class Cost extends resource_1.APIResource {
/**
* Get cost in USD across a date range, broken out by dimension.
*
* Returns one row per combination of the requested `group_by[]` dimensions (and
* time bucket, when `time_bucket_width` is set) that has cost in the range, ranked
* by spend or ordered by time bucket; every combination is returned across pages.
* With no `group_by[]` and no `time_bucket_width`, a single row aggregates the
* whole range. Includes all cost, whether or not it is attributable to a seat
* user. Requires an API key with the `read:analytics` scope, or an Admin API key.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaAnalyticsCostItem of client.beta.organization.analytics.cost.list(
* { starting_at: '2026-09-01T00:00:00Z' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { betas, ...query } = params;
return this._client.getAPIList('/v1/organizations/analytics/cost', (pagination_1.ReportPageCursor), {
query,
...options,
headers: (0, headers_1.buildHeaders)([
{ 'anthropic-beta': [...(betas ?? []), 'analytics-usage-cost-2026-08-24'].toString() },
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.organization.analytics.cost.list', options, {
route: '/v1/organizations/analytics/cost',
queryParams: [
'actor_ids',
'actor_types',
'agent_ids',
'api_key_ids',
'claude_tag_categories',
'claude_tag_user_ids',
'context_windows',
'deployment_ids',
'ending_at',
'environment_ids',
'exclude_deleted_users',
'group_by',
'inference_geos',
'limit',
'models',
'order',
'order_by',
'organization_ids',
'page',
'products',
'rbac_group_ids',
'service_tiers',
'session_ids',
'slack_channel_ids',
'speeds',
'starting_at',
'time_bucket_width',
'user_profile_ids',
'workspace_ids',
],
}),
});
}
}
exports.Cost = Cost;
//# sourceMappingURL=cost.js.map