-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement usage & spending API client #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,4 +11,5 @@ export * from './sandbox'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './session'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './stream'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './thread'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './usage'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace the wildcard usage export with named exports. The new wildcard export adds another index.ts ✅ Suggested explicit re-export-export * from './usage';
+export {
+ type TokenUsage,
+ TokenUsageSchema,
+ type UsageBreakdown,
+ type UsageBreakdownGroup,
+ UsageBreakdownGroupSchema,
+ type UsageBreakdownOptions,
+ UsageBreakdownSchema,
+ type UsageGranularity,
+ UsageGranularitySchema,
+ type UsageGroupBy,
+ UsageGroupBySchema,
+ type UsageMetric,
+ UsageMetricSchema,
+ type UsageOptions,
+ type UsageSortBy,
+ UsageSortBySchema,
+ type UsageSummary,
+ UsageSummarySchema,
+ type UsageTimeseries,
+ type UsageTimeseriesBucket,
+ UsageTimeseriesBucketSchema,
+ type UsageTimeseriesOptions,
+ UsageTimeseriesSchema,
+ createDefaultClient,
+ UsageError,
+ UsageNotFoundError,
+ getUsageBreakdown,
+ getUsageSummary,
+ getUsageTimeseries,
+ UsageBreakdownResponseSchema,
+ UsageSummaryResponseSchema,
+ UsageTimeseriesResponseSchema,
+} from './usage';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './user'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * @module usage | ||
| * | ||
| * Usage & Spending API client for querying project-level cost and usage data. | ||
| * | ||
| * This module provides typed client functions for the Agentuity Usage API, | ||
| * which aggregates session cost data by project. It supports: | ||
| * - **Summary**: Aggregated cost totals for a project within a time range | ||
| * - **Breakdown**: Cost data grouped by agent, deployment, day, or hour | ||
| * - **Timeseries**: Time-bucketed usage data for charting and visualization | ||
| * | ||
| * All costs are in USD. All timestamps are RFC 3339 format. | ||
| * | ||
| * @example Summary (zero-config) | ||
| * ```typescript | ||
| * import { getUsageSummary } from '@agentuity/server'; | ||
| * | ||
| * const summary = await getUsageSummary({ | ||
| * start: '2025-01-01T00:00:00Z', | ||
| * end: '2025-02-01T00:00:00Z', | ||
| * }); | ||
| * console.log(`Total cost: $${summary.totalCost}`); | ||
| * ``` | ||
| * | ||
| * @example Breakdown (zero-config) | ||
| * ```typescript | ||
| * import { getUsageBreakdown } from '@agentuity/server'; | ||
| * | ||
| * const breakdown = await getUsageBreakdown({ | ||
| * start: '2025-01-01T00:00:00Z', | ||
| * end: '2025-02-01T00:00:00Z', | ||
| * groupBy: 'agent', | ||
| * sortBy: 'cost_desc', | ||
| * }); | ||
| * for (const group of breakdown.groups) { | ||
| * console.log(`${group.label}: $${group.totalCost}`); | ||
| * } | ||
| * ``` | ||
| * | ||
| * @example Timeseries (zero-config) | ||
| * ```typescript | ||
| * import { getUsageTimeseries } from '@agentuity/server'; | ||
| * | ||
| * const timeseries = await getUsageTimeseries({ | ||
| * start: '2025-01-01T00:00:00Z', | ||
| * end: '2025-01-08T00:00:00Z', | ||
| * granularity: 'day', | ||
| * metrics: ['totalCost', 'sessionCount'], | ||
| * }); | ||
| * for (const bucket of timeseries.buckets) { | ||
| * console.log(`${bucket.timestamp}: $${bucket.totalCost}`); | ||
| * } | ||
| * ``` | ||
| */ | ||
|
|
||
| // ============================================================================ | ||
| // Types & Schemas | ||
| // ============================================================================ | ||
|
|
||
| export { | ||
| type TokenUsage, | ||
| TokenUsageSchema, | ||
| type UsageBreakdown, | ||
| type UsageBreakdownGroup, | ||
| UsageBreakdownGroupSchema, | ||
| type UsageBreakdownOptions, | ||
| UsageBreakdownSchema, | ||
| type UsageGranularity, | ||
| UsageGranularitySchema, | ||
| type UsageGroupBy, | ||
| UsageGroupBySchema, | ||
| type UsageMetric, | ||
| UsageMetricSchema, | ||
| type UsageOptions, | ||
| type UsageSortBy, | ||
| UsageSortBySchema, | ||
| type UsageSummary, | ||
| UsageSummarySchema, | ||
| type UsageTimeseries, | ||
| type UsageTimeseriesBucket, | ||
| UsageTimeseriesBucketSchema, | ||
| type UsageTimeseriesOptions, | ||
| UsageTimeseriesSchema, | ||
| } from './types'; | ||
|
|
||
| // ============================================================================ | ||
| // Errors | ||
| // ============================================================================ | ||
|
|
||
| export { createDefaultClient, UsageError, UsageNotFoundError } from './util'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Public re-export conflicts with the
🤖 Prompt for AI Agents |
||
|
|
||
| // ============================================================================ | ||
| // Usage Operations | ||
| // ============================================================================ | ||
|
|
||
| export { | ||
| getUsageBreakdown, | ||
| getUsageSummary, | ||
| getUsageTimeseries, | ||
| UsageBreakdownResponseSchema, | ||
| UsageSummaryResponseSchema, | ||
| UsageTimeseriesResponseSchema, | ||
| } from './usage'; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation depth inconsistency.
The section title "Key APIs by Module" (plural) suggests comprehensive coverage of multiple modules, but currently only the Usage & Spending Tracking module is documented. Other established modules listed in the structure (apikey, db, eval, org, project, queue, region, sandbox, session, thread, user) lack similar detailed documentation.
Consider one of these approaches:
📝 Proposed fix: Make section title more specific
Note: The actual content documenting the Usage API is accurate and helpful. This comment only addresses the structural inconsistency in documentation organization.
🤖 Prompt for AI Agents