@usagetap/sdk 1.3.2 → 1.4.0

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.
Files changed (60) hide show
  1. package/README.md +219 -24
  2. package/dist/adapters/anthropic.cjs +990 -24
  3. package/dist/adapters/anthropic.cjs.map +1 -1
  4. package/dist/adapters/anthropic.d.cts +45 -3
  5. package/dist/adapters/anthropic.d.ts +45 -3
  6. package/dist/adapters/anthropic.mjs +990 -25
  7. package/dist/adapters/anthropic.mjs.map +1 -1
  8. package/dist/adapters/openai.cjs +1164 -44
  9. package/dist/adapters/openai.cjs.map +1 -1
  10. package/dist/adapters/openai.d.cts +46 -3
  11. package/dist/adapters/openai.d.ts +46 -3
  12. package/dist/adapters/openai.mjs +1164 -45
  13. package/dist/adapters/openai.mjs.map +1 -1
  14. package/dist/adapters/openrouter.cjs +3899 -22
  15. package/dist/adapters/openrouter.cjs.map +1 -1
  16. package/dist/adapters/openrouter.d.cts +6 -3
  17. package/dist/adapters/openrouter.d.ts +6 -3
  18. package/dist/adapters/openrouter.mjs +3897 -23
  19. package/dist/adapters/openrouter.mjs.map +1 -1
  20. package/dist/anthropic/index.cjs +990 -24
  21. package/dist/anthropic/index.cjs.map +1 -1
  22. package/dist/anthropic/index.d.cts +2 -2
  23. package/dist/anthropic/index.d.ts +2 -2
  24. package/dist/anthropic/index.mjs +990 -25
  25. package/dist/anthropic/index.mjs.map +1 -1
  26. package/dist/client-CExQ8e1T.d.cts +1225 -0
  27. package/dist/client-CExQ8e1T.d.ts +1225 -0
  28. package/dist/express/index.cjs +421 -29
  29. package/dist/express/index.cjs.map +1 -1
  30. package/dist/express/index.d.cts +2 -2
  31. package/dist/express/index.d.ts +2 -2
  32. package/dist/express/index.mjs +421 -29
  33. package/dist/express/index.mjs.map +1 -1
  34. package/dist/index.cjs +680 -15
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +5 -3
  37. package/dist/index.d.ts +5 -3
  38. package/dist/index.mjs +680 -15
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/openai/index.cjs +1165 -45
  41. package/dist/openai/index.cjs.map +1 -1
  42. package/dist/openai/index.d.cts +2 -2
  43. package/dist/openai/index.d.ts +2 -2
  44. package/dist/openai/index.mjs +1165 -46
  45. package/dist/openai/index.mjs.map +1 -1
  46. package/dist/openrouter/index.cjs +1182 -47
  47. package/dist/openrouter/index.cjs.map +1 -1
  48. package/dist/openrouter/index.d.cts +3 -3
  49. package/dist/openrouter/index.d.ts +3 -3
  50. package/dist/openrouter/index.mjs +1180 -46
  51. package/dist/openrouter/index.mjs.map +1 -1
  52. package/dist/react/index.cjs +19 -1
  53. package/dist/react/index.cjs.map +1 -1
  54. package/dist/react/index.d.cts +17 -4
  55. package/dist/react/index.d.ts +17 -4
  56. package/dist/react/index.mjs +19 -1
  57. package/dist/react/index.mjs.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/client-BD8O2J8Z.d.cts +0 -668
  60. package/dist/client-BD8O2J8Z.d.ts +0 -668
@@ -0,0 +1,1225 @@
1
+ type ReasoningLevel = "NONE" | "LOW" | "MEDIUM" | "HIGH";
2
+ /** Provider execution setting used for a completed call. */
3
+ type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
4
+ /** How UsageTap learned the execution reasoning effort. */
5
+ type ReasoningEffortSource = "provider_response" | "provider_request" | "gateway_config" | "model_default";
6
+ type LimitType = "NONE" | "BLOCK" | "DOWNGRADE";
7
+ interface RequestedEntitlements {
8
+ standard?: boolean;
9
+ premium?: boolean;
10
+ audio?: boolean;
11
+ image?: boolean;
12
+ search?: boolean;
13
+ reasoningLevel?: ReasoningLevel;
14
+ }
15
+ type AllowedEntitlements = Required<RequestedEntitlements>;
16
+ type ModelTier = "premium" | "standard" | "none";
17
+ interface EntitlementDowngradeHint {
18
+ reason: string;
19
+ fallbackTier?: ModelTier;
20
+ }
21
+ interface EntitlementHints {
22
+ suggestedModelTier: ModelTier;
23
+ reasoningLevel: ReasoningLevel;
24
+ policy: LimitType;
25
+ downgrade?: EntitlementDowngradeHint;
26
+ }
27
+ interface MeterSummary {
28
+ /** Always numeric. Check the `unlimited` flag to detect unbounded meters. */
29
+ remaining: number;
30
+ limit: number | null;
31
+ /** Always numeric (0 when no usage recorded). */
32
+ used: number;
33
+ /** When true this meter is unbounded; `remaining` is informational only. */
34
+ unlimited: boolean;
35
+ /** remaining / limit (0-1). null when unlimited or limit is null/0. */
36
+ ratio: number | null;
37
+ label?: string;
38
+ }
39
+ type MeterSnapshot = Record<string, MeterSummary>;
40
+ type RemainingRatios = Record<string, number | null | undefined>;
41
+ interface RollingCallsRateLimitState {
42
+ windowType: "rolling_calls";
43
+ limit: number;
44
+ used: number;
45
+ remaining: number;
46
+ windowSeconds: number;
47
+ state: "fresh" | "estimated" | "stale" | "unknown";
48
+ source?: "current_rolling_check" | "call_records";
49
+ nextAvailableAt?: string;
50
+ scope?: {
51
+ callType?: "standard" | "API";
52
+ tier?: "standard" | "premium";
53
+ };
54
+ }
55
+ interface RateLimitsSnapshot {
56
+ rollingCalls?: RollingCallsRateLimitState | Record<string, RollingCallsRateLimitState>;
57
+ }
58
+ interface SubscriptionSnapshot {
59
+ id: string | null;
60
+ usagePlanVersionId: string | null;
61
+ planName: string | null;
62
+ planVersion: string | null;
63
+ limitType: LimitType;
64
+ reasoningLevel: ReasoningLevel;
65
+ lastReplenishedAt: string | null;
66
+ nextReplenishAt: string | null;
67
+ subscriptionVersion: number | null;
68
+ customerFriendlyName?: string | null;
69
+ customerEmail?: string | null;
70
+ pending?: {
71
+ usagePlanVersionId: string | null;
72
+ strategy: string | null;
73
+ effectiveAt: string | null;
74
+ };
75
+ stripeCustomerId?: string | null;
76
+ }
77
+ type ModelHints = Record<string, string[]>;
78
+ interface IdempotencyMetadata {
79
+ key: string;
80
+ source: "explicit" | "derived";
81
+ }
82
+ interface VendorHints {
83
+ preferredModel?: string;
84
+ reasoning?: ReasoningLevel;
85
+ maxInputTokens?: number;
86
+ maxResponseTokens?: number;
87
+ }
88
+ interface PromptCompressionRequest {
89
+ callId: string;
90
+ input?: unknown;
91
+ text?: string;
92
+ provider?: "heuristic" | "toon" | "thetokencompany" | "usagetap";
93
+ model?: string;
94
+ tokenCompanyModel?: string;
95
+ /** Provider-neutral compression aggressiveness from 0.0 to 1.0. */
96
+ aggressiveness?: number;
97
+ /** @deprecated Use aggressiveness instead. */
98
+ tokenCompanyAggressiveness?: number;
99
+ tokenCompanyAppId?: string;
100
+ usageTapCompressionModel?: string;
101
+ /** @deprecated Use aggressiveness instead. */
102
+ usageTapCompressionAggressiveness?: number;
103
+ }
104
+ interface PromptCompressionTelemetry {
105
+ provider: "heuristic" | "toon" | "thetokencompany" | "usagetap";
106
+ originalTokens: number;
107
+ compressedTokens: number;
108
+ savedTokens: number;
109
+ tokenSavingsRatio: number;
110
+ techniques: string[];
111
+ }
112
+ interface BeginCallRequest {
113
+ customerId: string;
114
+ /**
115
+ * Identifies one application workflow or agent run for local circuit-breaker
116
+ * enforcement. This value is used by the SDK only and is not sent to UsageTap.
117
+ */
118
+ runId?: string;
119
+ requested?: RequestedEntitlements;
120
+ feature?: string;
121
+ tags?: string[];
122
+ /**
123
+ * Optional PAYG hold hint (USD) to authorize upfront during call_begin.
124
+ * When provided, overrides the plan's default hold for this call only.
125
+ */
126
+ holdUsd?: number;
127
+ /**
128
+ * Idempotency key for safe retries.
129
+ * The SDK generates a unique key by default. Direct API callers should send
130
+ * one explicitly and reuse it only when retrying the same logical call.
131
+ * @deprecated Use idempotencyKey instead
132
+ */
133
+ idempotency?: string;
134
+ /**
135
+ * Idempotency key for safe retries.
136
+ * The SDK generates a unique key by default. Direct API callers should send
137
+ * one explicitly and reuse it only when retrying the same logical call.
138
+ */
139
+ idempotencyKey?: string;
140
+ customerName?: string;
141
+ customerEmail?: string;
142
+ /** Stable identifier for the end user who initiated this call. */
143
+ customerUserId?: string;
144
+ /** Display name for the end user who initiated this call. */
145
+ customerUserName?: string;
146
+ /** Email address for the end user who initiated this call. */
147
+ customerUserEmail?: string;
148
+ stripeCustomerId?: string;
149
+ /**
150
+ * Compatibility flag for batch pricing (typically 50% of standard rates).
151
+ * When both fields are supplied, pricingMode is authoritative.
152
+ */
153
+ batch?: boolean;
154
+ /**
155
+ * Explicit pricing mode for this call. Takes precedence over batch.
156
+ */
157
+ pricingMode?: "batch" | "standard";
158
+ /**
159
+ * Runtime Compression Policy resolution context. SDK adapters populate this
160
+ * automatically; direct integrations may provide it explicitly.
161
+ */
162
+ runtimeCompressionContext?: {
163
+ assignmentKey?: string;
164
+ projectId?: string;
165
+ provider?: string;
166
+ model?: string;
167
+ };
168
+ }
169
+ interface RuntimeCompressionPolicyDecision {
170
+ policyId: string;
171
+ policyVersionId: string;
172
+ version: number;
173
+ mode: "DRAFT" | "SHADOW" | "CANARY" | "ACTIVE" | "PAUSED" | "ARCHIVED";
174
+ selected: boolean;
175
+ snapshot: {
176
+ scope: {
177
+ minimumTokens: number;
178
+ messageRoles: string[];
179
+ contentTypes: string[];
180
+ };
181
+ methods: {
182
+ deterministic: {
183
+ enabled: true;
184
+ };
185
+ deepText: {
186
+ enabled: boolean;
187
+ };
188
+ };
189
+ gates: {
190
+ minimumTokensRemoved: number;
191
+ minimumReductionPercentage: number;
192
+ maximumLatencyMs: number;
193
+ maximumCompressionCostUsd?: number;
194
+ minimumProjectedNetSavingUsd?: number;
195
+ };
196
+ rollout: {
197
+ deterministicOnly: boolean;
198
+ deepTextCanaryAllowed: boolean;
199
+ };
200
+ capturePayloads: boolean;
201
+ payloadRetentionDays: number;
202
+ };
203
+ }
204
+ interface RuntimeCompressionMeasurement {
205
+ policyId: string;
206
+ policyVersionId: string;
207
+ policyVersion: number;
208
+ rolloutMode: RuntimeCompressionPolicyDecision["mode"];
209
+ decision: "compressed" | "skipped" | "fallback" | "bypassed" | "error";
210
+ reasonCode?: string;
211
+ methodsAttempted: string[];
212
+ methodsApplied: string[];
213
+ originalTokens: number;
214
+ resultTokens: number;
215
+ savedTokens: number;
216
+ reductionPercentage: number;
217
+ compressionLatencyMs: number;
218
+ compressionComputeCostUsd: number;
219
+ financialsEstimated: boolean;
220
+ }
221
+ interface BalanceSummary {
222
+ standardCallsRemaining?: number;
223
+ premiumCallsRemaining?: number;
224
+ tokensRemaining?: number;
225
+ searchesRemaining?: number;
226
+ audioSecondsRemaining?: number;
227
+ customMeter1Remaining?: number;
228
+ customMeter2Remaining?: number;
229
+ }
230
+ type SpendVelocityWindowKey = "hour" | "day";
231
+ interface SpendVelocityWindow {
232
+ bucket: string;
233
+ windowMinutes: number;
234
+ startedAt: string;
235
+ endedAt: string;
236
+ completedCostUsd: number;
237
+ completedCalls: number;
238
+ }
239
+ interface SpendVelocitySnapshot {
240
+ currency: "USD";
241
+ source: "usage_aggregate";
242
+ generatedAt: string;
243
+ customerId: string;
244
+ currentCallCostUsd: number;
245
+ windows: Record<SpendVelocityWindowKey, SpendVelocityWindow>;
246
+ }
247
+ interface PlanSummary {
248
+ id: string | null;
249
+ name: string | null;
250
+ version: string | null;
251
+ }
252
+ interface BeginCallResponseBody {
253
+ callId: string;
254
+ callType?: "standard" | "API";
255
+ startTime: string;
256
+ feature?: string;
257
+ tags?: string[];
258
+ newCustomer: boolean;
259
+ canceled: boolean;
260
+ policy: LimitType;
261
+ allowed: AllowedEntitlements;
262
+ entitlementHints: EntitlementHints;
263
+ rateLimits?: RateLimitsSnapshot;
264
+ meters: MeterSnapshot;
265
+ remainingRatios: RemainingRatios;
266
+ subscription: SubscriptionSnapshot;
267
+ models?: ModelHints;
268
+ idempotency?: IdempotencyMetadata;
269
+ vendorHints?: VendorHints;
270
+ plan?: PlanSummary;
271
+ balances?: BalanceSummary;
272
+ stripeCustomerId?: string | null;
273
+ batch?: boolean;
274
+ pricingMode?: "batch" | "standard";
275
+ runtimeCompressionPolicy?: RuntimeCompressionPolicyDecision;
276
+ }
277
+ interface EndCallRequest {
278
+ callId: string;
279
+ /** Optional customer ID for metric tracking. Not sent to API, used for onUsageMetric callback. */
280
+ customerId?: string;
281
+ /** Optional feature for metric tracking. Not sent to API, used for onUsageMetric callback. */
282
+ feature?: string;
283
+ /** Optional tags for metric tracking. Not sent to API, used for onUsageMetric callback. */
284
+ tags?: string[];
285
+ /** Vendor that executed the request, for example `openai` or `anthropic`. */
286
+ providerUsed?: string;
287
+ modelUsed?: string;
288
+ /** Reasoning effort actually used, or the best-known requested/configured value. */
289
+ reasoningEffort?: ReasoningEffort;
290
+ /** Provenance for reasoningEffort. Provider responses are most authoritative. */
291
+ reasoningEffortSource?: ReasoningEffortSource;
292
+ /** Provider-specific reasoning mode, such as `enabled` or `adaptive`. */
293
+ reasoningMode?: string;
294
+ /** Explicit reasoning/thinking token budget when the provider supports one. */
295
+ reasoningBudgetTokens?: number;
296
+ /**
297
+ * Total prompt/input tokens for the call (including any cached prompt tokens).
298
+ */
299
+ inputTokens?: number;
300
+ responseTokens?: number;
301
+ /**
302
+ * Prompt/input tokens served from cache.
303
+ * Preferred over legacy aliases.
304
+ */
305
+ cachedInputTokens?: number;
306
+ /**
307
+ * Prompt/input tokens written to a provider prompt cache.
308
+ * inputTokens must include these tokens.
309
+ */
310
+ cacheWriteInputTokens?: number;
311
+ reasoningTokens?: number;
312
+ searches?: number;
313
+ audio?: number;
314
+ audioSeconds?: number;
315
+ error?: {
316
+ code: string;
317
+ message: string;
318
+ };
319
+ /**
320
+ * Optional downstream status metadata for direct integrations.
321
+ * Prefer `error` for failed provider calls.
322
+ */
323
+ responseStatusCode?: number;
324
+ /**
325
+ * Optional downstream error metadata for direct integrations.
326
+ * Prefer `error` for failed provider calls.
327
+ */
328
+ responseErrorMessage?: string;
329
+ /**
330
+ * Advanced compatibility override for model-tier classification.
331
+ */
332
+ isPremium?: boolean;
333
+ stripeCustomerId?: string;
334
+ /**
335
+ * Compatibility flag for batch pricing (typically 50% of standard rates).
336
+ * When both fields are supplied, pricingMode is authoritative.
337
+ */
338
+ batch?: boolean;
339
+ /**
340
+ * Explicit pricing mode for this call. Takes precedence over batch.
341
+ */
342
+ pricingMode?: "batch" | "standard";
343
+ runtimeCompression?: RuntimeCompressionMeasurement;
344
+ }
345
+ interface MeteredUsage {
346
+ calls?: number;
347
+ tokens?: number;
348
+ reasoningTokens?: number;
349
+ searches?: number;
350
+ audio?: number;
351
+ audioSeconds?: number;
352
+ }
353
+ interface EndCallResponseBody {
354
+ callId: string;
355
+ status?: "COMPLETED" | "FAILED";
356
+ error?: {
357
+ code: string;
358
+ message: string;
359
+ };
360
+ providerUsed?: string;
361
+ modelUsed?: string;
362
+ reasoningEffort?: ReasoningEffort;
363
+ reasoningEffortSource?: ReasoningEffortSource;
364
+ reasoningMode?: string;
365
+ reasoningBudgetTokens?: number;
366
+ /** Final model cost after the selected pricing mode is applied. */
367
+ costUSD: number;
368
+ /** Integer decimal representation used by the API for high-precision cost storage. */
369
+ costUsdNano?: string;
370
+ costBreakdown?: Record<string, unknown>;
371
+ /** Model cost before a vendor-batch discount is applied. */
372
+ standardCostUSD?: number;
373
+ /** Multiplier applied to standardCostUSD (0.5 for batch, 1 for standard). */
374
+ pricingMultiplier?: number;
375
+ usage?: {
376
+ inputTokens: number;
377
+ cachedInputTokens: number;
378
+ cacheWriteInputTokens: number;
379
+ billableInputTokens: number;
380
+ responseTokens: number;
381
+ reasoningTokens: number;
382
+ };
383
+ metered?: MeteredUsage;
384
+ spendVelocity?: SpendVelocitySnapshot;
385
+ policy?: LimitType;
386
+ allowed?: AllowedEntitlements;
387
+ entitlementHints?: EntitlementHints;
388
+ meters?: MeterSnapshot;
389
+ remainingRatios?: RemainingRatios;
390
+ subscription?: SubscriptionSnapshot;
391
+ models?: ModelHints;
392
+ plan?: PlanSummary;
393
+ balances?: BalanceSummary;
394
+ stripeCustomerId?: string | null;
395
+ batch?: boolean;
396
+ pricingMode?: "batch" | "standard";
397
+ }
398
+ type UsageTapResultStatus = "ACCEPTED" | "ERROR";
399
+ interface UsageTapResultEnvelope {
400
+ status: UsageTapResultStatus;
401
+ code?: string;
402
+ message?: string;
403
+ timestamp?: string;
404
+ }
405
+ interface UsageTapErrorPayload {
406
+ code: string;
407
+ message: string;
408
+ details?: Record<string, unknown>;
409
+ }
410
+ interface UsageTapSuccessResponse<TData> {
411
+ result: UsageTapResultEnvelope;
412
+ data: TData;
413
+ correlationId: string;
414
+ }
415
+ interface UsageTapErrorResponse {
416
+ result: UsageTapResultEnvelope;
417
+ error: UsageTapErrorPayload;
418
+ correlationId: string;
419
+ }
420
+ interface RetryOptions {
421
+ /**
422
+ * Maximum number of attempts including the initial try.
423
+ * @default 3
424
+ */
425
+ maxAttempts?: number;
426
+ /**
427
+ * Base backoff delay in milliseconds.
428
+ * @default 250
429
+ */
430
+ baseDelayMs?: number;
431
+ /**
432
+ * Maximum backoff delay in milliseconds.
433
+ * @default 5000
434
+ */
435
+ maxDelayMs?: number;
436
+ /**
437
+ * Jitter ratio between 0 and 1 applied to the computed delay.
438
+ * @default 0.2
439
+ */
440
+ jitterRatio?: number;
441
+ }
442
+ interface UsageTapLogEntry {
443
+ event: "request:start" | "request:success" | "request:error" | "retry:scheduled" | "retry:exhausted";
444
+ path: string;
445
+ attempt: number;
446
+ elapsedMs?: number;
447
+ idempotencyKey?: string;
448
+ correlationId?: string;
449
+ error?: unknown;
450
+ }
451
+ interface UsageTapClientOptions {
452
+ /**
453
+ * UsageTap API key. Defaults to the server-side USAGETAP_API_KEY environment variable.
454
+ */
455
+ apiKey?: string;
456
+ /**
457
+ * UsageTap API base URL. Defaults to USAGETAP_BASE_URL, then https://api.usagetap.com.
458
+ */
459
+ baseUrl?: string;
460
+ /**
461
+ * UsageTap Gateway base URL. Defaults to USAGETAP_GATEWAY_URL, then
462
+ * https://gateway.usagetap.com.
463
+ */
464
+ gatewayBaseUrl?: string;
465
+ defaultFeature?: string;
466
+ defaultTags?: string[];
467
+ fetchImpl?: typeof fetch;
468
+ headers?: Record<string, string>;
469
+ retries?: RetryOptions;
470
+ idempotencyGenerator?: () => string;
471
+ /**
472
+ * When true (default), the client auto-generates an idempotency key when one is not provided.
473
+ * Set to false to rely on the backend's deterministic fallback.
474
+ */
475
+ autoIdempotency?: boolean;
476
+ onLog?: (entry: UsageTapLogEntry) => void;
477
+ /**
478
+ * Callback invoked when usage metrics are recorded (call_end, custom_meter).
479
+ * Use this to export metrics to OpenTelemetry or other observability systems.
480
+ */
481
+ onUsageMetric?: (event: UsageMetricEvent) => void;
482
+ /**
483
+ * Override the default Authorization header with x-api-key when true.
484
+ */
485
+ useApiKeyHeader?: boolean;
486
+ /**
487
+ * Allow constructing the client in browser-like environments for testing.
488
+ */
489
+ allowBrowser?: boolean;
490
+ /** API key for The Token Company Bear compression API. */
491
+ tokenCompanyApiKey?: string;
492
+ /** Override endpoint for The Token Company compatible compression APIs. */
493
+ tokenCompanyEndpoint?: string;
494
+ /** Default model for The Token Company compression. */
495
+ model?: string;
496
+ tokenCompanyModel?: string;
497
+ /** Default compression aggressiveness, from 0.0 to 1.0. */
498
+ aggressiveness?: number;
499
+ /** @deprecated Use aggressiveness instead. */
500
+ tokenCompanyAggressiveness?: number;
501
+ /** Optional application identifier sent to The Token Company. */
502
+ tokenCompanyAppId?: string;
503
+ /** API key for UsageTap prompt compression. Defaults to apiKey when omitted. */
504
+ usageTapCompressionApiKey?: string;
505
+ /** Override endpoint for UsageTap-compatible prompt compression APIs. */
506
+ usageTapCompressionEndpoint?: string;
507
+ /** Override endpoint for UsageTap-compatible message/request compression APIs. */
508
+ usageTapCompressionMessagesEndpoint?: string;
509
+ /** Default model for UsageTap prompt compression. */
510
+ usageTapCompressionModel?: string;
511
+ /** @deprecated Use aggressiveness instead. */
512
+ usageTapCompressionAggressiveness?: number;
513
+ /** Local policy override. Omit to load the saved UsageTap policy; false disables sampling. */
514
+ sampling?: SamplingOptions | false;
515
+ /** Maximum local lifetime for remotely loaded sampling settings. Defaults to 5 minutes. */
516
+ samplingSettingsCacheMs?: number;
517
+ /**
518
+ * Optional local hard stop for recursive or runaway workflows.
519
+ * Calls without a runId are not affected.
520
+ */
521
+ circuitBreaker?: CircuitBreakerOptions | false;
522
+ }
523
+ interface CircuitBreakerOptions {
524
+ /** Maximum call_begin attempts allowed for one customerId + runId pair. */
525
+ maxCallsPerRun: number;
526
+ /**
527
+ * Forget inactive runs after this many milliseconds.
528
+ * Defaults to 60 minutes. Call resetRun() when a run completes to release it sooner.
529
+ */
530
+ runInactivityMs?: number;
531
+ }
532
+ interface CircuitBreakerDecision {
533
+ allowed: boolean;
534
+ reason?: "max_calls_per_run";
535
+ customerId: string;
536
+ runId: string;
537
+ calls: number;
538
+ limit: number;
539
+ remaining: number;
540
+ }
541
+ interface RequestOptions {
542
+ signal?: AbortSignal;
543
+ headers?: Record<string, string>;
544
+ retries?: RetryOptions;
545
+ }
546
+ interface SamplingOptions {
547
+ /** Fraction of eligible calls to retain, from 0 to 1. */
548
+ rate: number;
549
+ /** Skip inputs below this local estimated-token threshold. */
550
+ minInputTokens?: number;
551
+ features?: {
552
+ include?: string[];
553
+ exclude?: string[];
554
+ };
555
+ customers?: {
556
+ exclude?: string[];
557
+ };
558
+ /** Optional deterministic random source, primarily for testing. */
559
+ random?: () => number;
560
+ }
561
+ interface SamplingDecisionInput {
562
+ customerId?: string;
563
+ feature?: string;
564
+ input: unknown;
565
+ }
566
+ interface SamplingSettings extends Omit<SamplingOptions, "random"> {
567
+ version: string;
568
+ retentionDays: number;
569
+ cacheSeconds: number;
570
+ settingsExpiresAt: string;
571
+ }
572
+ interface GetSamplingSettingsOptions extends RequestOptions {
573
+ correlationId?: string;
574
+ forceRefresh?: boolean;
575
+ }
576
+ interface SamplingDecisionRequest {
577
+ samplingKey?: string;
578
+ customerId?: string;
579
+ feature?: string;
580
+ inputTokens?: number;
581
+ inputCharacters?: number;
582
+ }
583
+ interface SamplingDecisionResponseBody {
584
+ sample: boolean;
585
+ reason: "selected" | "rate_disabled" | "customer_excluded" | "feature_excluded" | "feature_not_included" | "below_minimum_tokens" | "rate_not_selected";
586
+ decisionId: string;
587
+ samplingKey: string;
588
+ policyVersion: string;
589
+ settingsExpiresAt: string;
590
+ score?: number;
591
+ }
592
+ interface SamplingDecisionOptions extends RequestOptions {
593
+ correlationId?: string;
594
+ }
595
+ interface CaptureSampleRequest extends SamplingDecisionInput {
596
+ sampleId?: string;
597
+ /** Exact UsageTap call ID when this sample belongs to a metered call. */
598
+ callId?: string;
599
+ environment?: string;
600
+ tags?: string[];
601
+ provider: string;
602
+ model?: string;
603
+ output?: unknown;
604
+ usage?: unknown;
605
+ latencyMs?: number;
606
+ error?: unknown;
607
+ decisionId?: string;
608
+ policyVersion?: string;
609
+ }
610
+ interface CaptureSampleOptions extends RequestOptions {
611
+ correlationId?: string;
612
+ }
613
+ interface CaptureSampleResponseBody {
614
+ sampleId: string;
615
+ stored?: boolean;
616
+ receivedAt: string;
617
+ expiresAt: string;
618
+ retentionDays: number;
619
+ policyVersion?: string;
620
+ payloadStorage?: "dynamodb" | "s3";
621
+ }
622
+ interface PromptCompressionStandaloneOptions {
623
+ signal?: AbortSignal;
624
+ provider?: "heuristic" | "toon" | "thetokencompany" | "usagetap";
625
+ failOpen?: boolean;
626
+ model?: string;
627
+ tokenCompanyModel?: string;
628
+ /** Provider-neutral compression aggressiveness from 0.0 to 1.0. */
629
+ aggressiveness?: number;
630
+ /** @deprecated Use aggressiveness instead. */
631
+ tokenCompanyAggressiveness?: number;
632
+ tokenCompanyAppId?: string;
633
+ usageTapCompressionModel?: string;
634
+ /** @deprecated Use aggressiveness instead. */
635
+ usageTapCompressionAggressiveness?: number;
636
+ }
637
+ type PromptCompressionMessageRole$1 = "system" | "user" | "tool" | "assistant";
638
+ type PromptCompressionRoleAggressiveness$1 = Partial<Record<PromptCompressionMessageRole$1, number>>;
639
+ type PromptCompressionMessagesAggressiveness$1 = number | PromptCompressionRoleAggressiveness$1;
640
+ interface PromptCompressionMessagesOptions extends RequestOptions {
641
+ provider?: "usagetap";
642
+ failOpen?: boolean;
643
+ /** Select deterministic-only, automatic model gating, or a forced model pass. */
644
+ mode?: "deterministic" | "model_auto" | "model_force";
645
+ /** Provider-neutral scalar or per-role compression aggressiveness. */
646
+ aggressiveness?: PromptCompressionMessagesAggressiveness$1;
647
+ /** Maximum compression latency the service should target. */
648
+ latencyBudgetMs?: number;
649
+ /** Remove empty user messages before compression. */
650
+ compactEmptyUserMessages?: boolean;
651
+ /** Deduplicate repeated text parts within user messages. */
652
+ compactDuplicateUserTextParts?: boolean;
653
+ /** @deprecated Use aggressiveness instead. */
654
+ usageTapCompressionAggressiveness?: PromptCompressionMessagesAggressiveness$1;
655
+ }
656
+ interface RecordPromptCompressionRequest {
657
+ callId: string;
658
+ promptCompression: PromptCompressionTelemetry;
659
+ }
660
+ interface BeginCallOptions extends RequestOptions {
661
+ correlationId?: string;
662
+ }
663
+ interface EndCallOptions extends RequestOptions {
664
+ correlationId?: string;
665
+ }
666
+ interface PromptCompressionOptions extends RequestOptions {
667
+ correlationId?: string;
668
+ }
669
+ interface PromptCompressionResponseBody extends PromptCompressionTelemetry {
670
+ callId: string;
671
+ updated: boolean;
672
+ }
673
+ interface WithUsageContext {
674
+ begin: UsageTapSuccessResponse<BeginCallResponseBody>;
675
+ setUsage: (usage: Partial<Omit<EndCallRequest, "callId" | "error">>) => void;
676
+ setError: (error: EndCallRequest["error"]) => void;
677
+ }
678
+ interface WithUsageOptions {
679
+ signal?: AbortSignal;
680
+ headers?: Record<string, string>;
681
+ retries?: RetryOptions;
682
+ correlationId?: string;
683
+ /**
684
+ * Default error payload applied when the handler throws and setError was never invoked.
685
+ */
686
+ defaultErrorCode?: string;
687
+ }
688
+ interface CheckUsageRequest {
689
+ customerId: string;
690
+ }
691
+ interface CheckUsageOptions extends RequestOptions {
692
+ correlationId?: string;
693
+ }
694
+ interface CheckUsageResponseBody {
695
+ customerId: string;
696
+ canceled: boolean;
697
+ policy: LimitType;
698
+ allowed: AllowedEntitlements;
699
+ entitlementHints: EntitlementHints;
700
+ rateLimits?: RateLimitsSnapshot;
701
+ meters: MeterSnapshot;
702
+ remainingRatios: RemainingRatios;
703
+ subscription: SubscriptionSnapshot;
704
+ models?: ModelHints;
705
+ plan?: PlanSummary;
706
+ balances?: BalanceSummary;
707
+ stripeCustomerId?: string | null;
708
+ }
709
+ interface CreateCustomerRequest {
710
+ customerId: string;
711
+ customerFriendlyName?: string;
712
+ customerName?: string;
713
+ customerEmail?: string;
714
+ stripeCustomerId?: string;
715
+ }
716
+ interface CreateCustomerOptions extends RequestOptions {
717
+ correlationId?: string;
718
+ idempotencyKey?: string;
719
+ }
720
+ interface CreateCustomerResponseBody extends CheckUsageResponseBody {
721
+ newCustomer: boolean;
722
+ }
723
+ type ChangePlanStrategy = "IMMEDIATE_RESET" | "IMMEDIATE_PRORATED" | "AT_NEXT_REPLENISH";
724
+ interface ChangePlanRequest {
725
+ customerId: string;
726
+ planId: string;
727
+ strategy?: ChangePlanStrategy;
728
+ }
729
+ interface ChangePlanOptions extends RequestOptions {
730
+ correlationId?: string;
731
+ idempotencyKey?: string;
732
+ }
733
+ interface ChangePlanResponseBody {
734
+ success: boolean;
735
+ subscription: SubscriptionSnapshot;
736
+ }
737
+ type CustomMeterSlot = "CUSTOM1" | "CUSTOM2";
738
+ interface IncrementCustomMeterRequest {
739
+ customerId: string;
740
+ /** Stable identifier for the end user responsible for this meter event. */
741
+ customerUserId?: string;
742
+ /** Display name for the end user responsible for this meter event. */
743
+ customerUserName?: string;
744
+ /** Email address for the end user responsible for this meter event. */
745
+ customerUserEmail?: string;
746
+ meterSlot: CustomMeterSlot;
747
+ amount: number;
748
+ feature?: string;
749
+ tags?: string[];
750
+ metadata?: Record<string, unknown>;
751
+ }
752
+ interface IncrementCustomMeterOptions extends RequestOptions {
753
+ correlationId?: string;
754
+ idempotencyKey?: string;
755
+ }
756
+ interface IncrementCustomMeterResponseBody {
757
+ success: boolean;
758
+ eventId: string;
759
+ meterSlot: CustomMeterSlot;
760
+ amount: number;
761
+ meter: MeterSummary;
762
+ blocked: boolean;
763
+ }
764
+ /**
765
+ * Event emitted when usage metrics are recorded.
766
+ * Use with `onUsageMetric` callback to export to OpenTelemetry or other observability systems.
767
+ */
768
+ interface UsageMetricEvent {
769
+ /** Type of metric event */
770
+ type: "call_end" | "custom_meter";
771
+ /** Timestamp in ISO 8601 format */
772
+ timestamp: string;
773
+ /** Customer identifier */
774
+ customerId: string;
775
+ /** Unique call identifier (for call_end events) */
776
+ callId?: string;
777
+ /** Feature tag */
778
+ feature?: string;
779
+ /** Additional tags */
780
+ tags?: string[];
781
+ /** Model used for the call */
782
+ modelUsed?: string;
783
+ /** Vendor that executed the request */
784
+ providerUsed?: string;
785
+ /** Reasoning effort used for the call */
786
+ reasoningEffort?: ReasoningEffort;
787
+ /** Provenance for the reasoning effort */
788
+ reasoningEffortSource?: ReasoningEffortSource;
789
+ /** Provider-specific reasoning mode */
790
+ reasoningMode?: string;
791
+ /** Explicit reasoning/thinking token budget */
792
+ reasoningBudgetTokens?: number;
793
+ /** Usage metrics */
794
+ metrics: {
795
+ inputTokens?: number;
796
+ cachedInputTokens?: number;
797
+ cacheWriteInputTokens?: number;
798
+ responseTokens?: number;
799
+ reasoningTokens?: number;
800
+ searches?: number;
801
+ audioSeconds?: number;
802
+ costUsd?: number;
803
+ /** Custom meter slot (for custom_meter events) */
804
+ customMeterSlot?: CustomMeterSlot;
805
+ /** Custom meter amount (for custom_meter events) */
806
+ customMeterAmount?: number;
807
+ };
808
+ /** Correlation ID for tracing */
809
+ correlationId?: string;
810
+ }
811
+
812
+ type PromptCompressionProvider = "heuristic" | "toon" | "thetokencompany" | "usagetap";
813
+ type PromptCompressionMessageRole = "system" | "user" | "tool" | "assistant";
814
+ type PromptCompressionMode = "deterministic" | "model_auto" | "model_force";
815
+ type PromptCompressionRoleAggressiveness = Partial<Record<PromptCompressionMessageRole, number>>;
816
+ type PromptCompressionMessagesAggressiveness = number | PromptCompressionRoleAggressiveness;
817
+ interface PromptCompressionInput {
818
+ input?: unknown;
819
+ text?: string;
820
+ provider?: PromptCompressionProvider;
821
+ tokenCompanyApiKey?: string;
822
+ tokenCompanyEndpoint?: string;
823
+ model?: string;
824
+ tokenCompanyModel?: string;
825
+ aggressiveness?: number;
826
+ tokenCompanyAggressiveness?: number;
827
+ tokenCompanyAppId?: string;
828
+ usageTapCompressionApiKey?: string;
829
+ usageTapCompressionEndpoint?: string;
830
+ usageTapCompressionModel?: string;
831
+ usageTapCompressionAggressiveness?: number;
832
+ fetchImpl?: typeof fetch;
833
+ signal?: AbortSignal;
834
+ failOpen?: boolean;
835
+ }
836
+ interface PromptCompressionMessagesInput<TInput = unknown> {
837
+ input: TInput;
838
+ provider?: Extract<PromptCompressionProvider, "usagetap">;
839
+ usageTapCompressionApiKey?: string;
840
+ usageTapCompressionMessagesEndpoint?: string;
841
+ aggressiveness?: PromptCompressionMessagesAggressiveness;
842
+ usageTapCompressionAggressiveness?: PromptCompressionMessagesAggressiveness;
843
+ /** Select deterministic-only, automatic model gating, or a forced model pass. */
844
+ mode?: PromptCompressionMode;
845
+ /** Maximum compression latency the service should target. */
846
+ latencyBudgetMs?: number;
847
+ /** Remove empty user messages before compression. */
848
+ compactEmptyUserMessages?: boolean;
849
+ /** Deduplicate repeated text parts within user messages. */
850
+ compactDuplicateUserTextParts?: boolean;
851
+ fetchImpl?: typeof fetch;
852
+ signal?: AbortSignal;
853
+ failOpen?: boolean;
854
+ }
855
+ interface PromptCompressionResult<TInput = unknown> {
856
+ input: TInput;
857
+ compressedInput: unknown;
858
+ provider: PromptCompressionProvider;
859
+ originalCharacters: number;
860
+ compressedCharacters: number;
861
+ savedCharacters: number;
862
+ originalTokens: number;
863
+ compressedTokens: number;
864
+ savedTokens: number;
865
+ tokenSavingsRatio: number;
866
+ savingsRatio: number;
867
+ techniques: string[];
868
+ }
869
+ declare function protectPromptText(text: string): string;
870
+ declare const protect: typeof protectPromptText;
871
+ declare function compressPrompt<TInput = unknown>(options: PromptCompressionInput): Promise<PromptCompressionResult<TInput>>;
872
+ declare function compressPromptHeuristic<TInput = unknown>(input: TInput): PromptCompressionResult<TInput>;
873
+ declare function compressPromptToon<TInput = unknown>(input: TInput): PromptCompressionResult<TInput>;
874
+ declare function compressPromptMessages<TInput = unknown>(options: PromptCompressionMessagesInput<TInput>): Promise<PromptCompressionResult<TInput>>;
875
+ declare function estimatePromptTokens(input: unknown): number;
876
+
877
+ type JsonRecord = Record<string, unknown>;
878
+ interface ResourceRequestOptions {
879
+ signal?: AbortSignal;
880
+ headers?: Record<string, string>;
881
+ idempotencyKey?: string;
882
+ }
883
+ interface WaitOptions extends ResourceRequestOptions {
884
+ /** Delay between status requests. */
885
+ pollIntervalMs?: number;
886
+ /** Maximum total polling time. */
887
+ timeoutMs?: number;
888
+ }
889
+ interface SummarizationContext {
890
+ id: string;
891
+ type: string;
892
+ content: string;
893
+ version?: string;
894
+ contentType?: string;
895
+ }
896
+ type SummarizationStatus = "QUEUED" | "RUNNING" | "COMPLETE" | "FAILED";
897
+ interface SummarizationJob {
898
+ jobId: string;
899
+ status: SummarizationStatus;
900
+ phase?: string;
901
+ profile?: string;
902
+ version?: number;
903
+ statusUrl?: string;
904
+ progress?: JsonRecord;
905
+ billing?: JsonRecord;
906
+ result?: JsonRecord;
907
+ error?: string;
908
+ }
909
+ interface SummarizationCreateParams {
910
+ profile: string;
911
+ context: SummarizationContext;
912
+ wait?: boolean;
913
+ }
914
+ interface SummarizationBatchCreateParams {
915
+ profile: string;
916
+ items: SummarizationContext[];
917
+ }
918
+ interface SummarizationBatchJob extends Partial<SummarizationJob> {
919
+ jobId: string;
920
+ contextId?: string;
921
+ }
922
+ interface SummarizationBatch {
923
+ batchId: string;
924
+ status: SummarizationStatus;
925
+ profile?: string;
926
+ version?: number;
927
+ submittedAt?: string;
928
+ statusUrl?: string;
929
+ jobs: SummarizationBatchJob[];
930
+ }
931
+ interface SummarizationProfile {
932
+ profile: string;
933
+ version: number;
934
+ name: string;
935
+ description?: string;
936
+ settings: {
937
+ model: string;
938
+ reasoningEffort?: string;
939
+ maxOutputTokens?: number;
940
+ outputFormat?: string;
941
+ outputSchema?: unknown;
942
+ temperature?: number;
943
+ };
944
+ prompt: {
945
+ system: string;
946
+ userTemplate: string;
947
+ contextPlaceholder: string;
948
+ assetId?: string;
949
+ schemaVersion?: string;
950
+ };
951
+ measurementUrl: string;
952
+ }
953
+ interface SummarizationMeasurementCreateParams {
954
+ profile: string;
955
+ contextId?: string;
956
+ source: {
957
+ tokens: number;
958
+ };
959
+ summary: {
960
+ tokens: number;
961
+ };
962
+ provider?: {
963
+ inputTokens?: number;
964
+ outputTokens?: number;
965
+ costUsd?: number;
966
+ };
967
+ }
968
+ interface SummarizationMeasurement {
969
+ measurementId: string;
970
+ tokensSaved: number;
971
+ reported: boolean;
972
+ }
973
+ interface GatewayChatMessage {
974
+ role: string;
975
+ content: unknown;
976
+ [key: string]: unknown;
977
+ }
978
+ interface GatewayChatCompletionCreateParams {
979
+ model?: string;
980
+ models?: string[];
981
+ messages: GatewayChatMessage[];
982
+ stream?: false;
983
+ [key: string]: unknown;
984
+ }
985
+ interface GatewayChatCompletion {
986
+ id?: string;
987
+ object?: string;
988
+ created?: number;
989
+ model?: string;
990
+ choices: Array<{
991
+ index?: number;
992
+ message?: {
993
+ role?: string;
994
+ content?: string | null;
995
+ [key: string]: unknown;
996
+ };
997
+ finish_reason?: string | null;
998
+ [key: string]: unknown;
999
+ }>;
1000
+ usage?: {
1001
+ prompt_tokens?: number;
1002
+ completion_tokens?: number;
1003
+ total_tokens?: number;
1004
+ [key: string]: unknown;
1005
+ };
1006
+ usagetap?: JsonRecord;
1007
+ [key: string]: unknown;
1008
+ }
1009
+ interface GatewayModel {
1010
+ id: string;
1011
+ object?: string;
1012
+ created?: number;
1013
+ owned_by?: string;
1014
+ [key: string]: unknown;
1015
+ }
1016
+ interface GatewayModelList {
1017
+ object: string;
1018
+ data: GatewayModel[];
1019
+ }
1020
+ type GatewayBatchStatus = "queued" | "submitting" | "in_progress" | "finalizing" | "cancelling" | "completed" | "failed" | "expired" | "cancelled";
1021
+ interface GatewayBatchRequest {
1022
+ custom_id: string;
1023
+ body: GatewayChatCompletionCreateParams;
1024
+ }
1025
+ interface GatewayBatchCreateParams {
1026
+ requests: GatewayBatchRequest[];
1027
+ }
1028
+ interface GatewayBatch {
1029
+ id: string;
1030
+ object: "batch";
1031
+ status: GatewayBatchStatus;
1032
+ provider?: string;
1033
+ created_at: string;
1034
+ updated_at: string;
1035
+ completed_at?: string;
1036
+ request_counts: {
1037
+ total: number;
1038
+ completed: number;
1039
+ failed: number;
1040
+ };
1041
+ calls: Array<{
1042
+ custom_id: string;
1043
+ call_id: string;
1044
+ status: number;
1045
+ error?: {
1046
+ code: string;
1047
+ message: string;
1048
+ };
1049
+ }>;
1050
+ error?: {
1051
+ code: string;
1052
+ message: string;
1053
+ };
1054
+ }
1055
+ interface GatewayBatchResult {
1056
+ custom_id: string;
1057
+ call_id: string;
1058
+ status: number;
1059
+ response?: GatewayChatCompletion;
1060
+ usage?: JsonRecord;
1061
+ compression?: {
1062
+ applied: boolean;
1063
+ status: "applied" | "no_savings" | "failed_open";
1064
+ original_input_tokens?: number;
1065
+ compressed_input_tokens?: number;
1066
+ tokens_saved?: number;
1067
+ reduction_percent?: number;
1068
+ };
1069
+ error?: {
1070
+ code: string;
1071
+ message: string;
1072
+ };
1073
+ }
1074
+ interface ResourceClientConfig {
1075
+ apiKey: string;
1076
+ apiBaseUrl: string;
1077
+ gatewayBaseUrl?: string;
1078
+ fetchImpl: typeof fetch;
1079
+ headers?: Record<string, string>;
1080
+ sdkVersion: string;
1081
+ idempotencyGenerator?: () => string;
1082
+ }
1083
+ declare class SummarizationResource {
1084
+ readonly summaries: {
1085
+ create: (params: SummarizationCreateParams, options?: ResourceRequestOptions) => Promise<SummarizationJob>;
1086
+ retrieve: (jobId: string, options?: ResourceRequestOptions) => Promise<SummarizationJob>;
1087
+ wait: (job: string | SummarizationJob, options?: WaitOptions) => Promise<SummarizationJob>;
1088
+ };
1089
+ readonly batches: {
1090
+ create: (params: SummarizationBatchCreateParams, options?: ResourceRequestOptions) => Promise<SummarizationBatch>;
1091
+ retrieve: (batchId: string, options?: ResourceRequestOptions) => Promise<SummarizationBatch>;
1092
+ wait: (batch: string | SummarizationBatch, options?: WaitOptions) => Promise<SummarizationBatch>;
1093
+ };
1094
+ readonly profiles: {
1095
+ retrieve: (profile: string, options?: ResourceRequestOptions) => Promise<SummarizationProfile>;
1096
+ };
1097
+ readonly measurements: {
1098
+ create: (params: SummarizationMeasurementCreateParams, options?: ResourceRequestOptions) => Promise<SummarizationMeasurement>;
1099
+ };
1100
+ private readonly transport;
1101
+ constructor(config: ResourceClientConfig);
1102
+ private waitForSummary;
1103
+ private waitForBatch;
1104
+ }
1105
+ declare class GatewayResource {
1106
+ readonly chat: {
1107
+ completions: {
1108
+ create: <T extends GatewayChatCompletion = GatewayChatCompletion>(params: GatewayChatCompletionCreateParams, options?: ResourceRequestOptions) => Promise<T>;
1109
+ };
1110
+ };
1111
+ readonly models: {
1112
+ list: (options?: ResourceRequestOptions) => Promise<GatewayModelList>;
1113
+ };
1114
+ readonly batches: {
1115
+ create: (params: GatewayBatchCreateParams, options?: ResourceRequestOptions) => Promise<GatewayBatch>;
1116
+ retrieve: (batchId: string, options?: ResourceRequestOptions) => Promise<GatewayBatch>;
1117
+ wait: (batch: string | GatewayBatch, options?: WaitOptions) => Promise<GatewayBatch>;
1118
+ cancel: (batchId: string, options?: ResourceRequestOptions) => Promise<GatewayBatch>;
1119
+ results: (batchId: string, options?: ResourceRequestOptions) => Promise<GatewayBatchResult[]>;
1120
+ };
1121
+ private readonly transport;
1122
+ private readonly idempotencyGenerator;
1123
+ constructor(config: ResourceClientConfig);
1124
+ private waitForBatch;
1125
+ }
1126
+
1127
+ type UsageTapCompressOptions = Omit<PromptCompressionStandaloneOptions, "provider">;
1128
+ type UsageTapCompressResult = Omit<PromptCompressionResult<string>, "compressedInput"> & {
1129
+ /** The compressed text, ready to pass to an LLM. */
1130
+ output: string;
1131
+ /** Alias retained for consistency with the lower-level compression APIs. */
1132
+ compressedInput: string;
1133
+ };
1134
+ type MeterRequest = string | BeginCallRequest;
1135
+ declare class UsageTapClient {
1136
+ /** OpenAI-compatible chat, model, and native batch operations. */
1137
+ readonly gateway: GatewayResource;
1138
+ /** Published-profile context summarization operations. */
1139
+ readonly summarization: SummarizationResource;
1140
+ private readonly apiKey;
1141
+ private readonly baseUrl;
1142
+ private readonly fetchImpl;
1143
+ private readonly defaultFeature?;
1144
+ private readonly defaultTags?;
1145
+ private readonly defaultHeaders;
1146
+ private readonly retryDefaults;
1147
+ private readonly idempotencyGenerator;
1148
+ private readonly logFn?;
1149
+ private readonly metricFn?;
1150
+ private readonly authHeader;
1151
+ private readonly autoIdempotency;
1152
+ private readonly tokenCompanyApiKey?;
1153
+ private readonly tokenCompanyEndpoint?;
1154
+ private readonly model?;
1155
+ private readonly tokenCompanyModel?;
1156
+ private readonly aggressiveness?;
1157
+ private readonly tokenCompanyAggressiveness?;
1158
+ private readonly tokenCompanyAppId?;
1159
+ private readonly usageTapCompressionApiKey?;
1160
+ private readonly usageTapCompressionEndpoint?;
1161
+ private readonly usageTapCompressionMessagesEndpoint?;
1162
+ private readonly usageTapCompressionModel?;
1163
+ private readonly usageTapCompressionAggressiveness?;
1164
+ private readonly sampling?;
1165
+ private readonly samplingSettingsCacheMs;
1166
+ private readonly circuitBreaker?;
1167
+ private readonly circuitBreakerRuns;
1168
+ private samplingSettingsCache?;
1169
+ constructor(options?: UsageTapClientOptions);
1170
+ shouldSample(request: SamplingDecisionInput, policy?: SamplingOptions | undefined): boolean;
1171
+ getSamplingSettings(options?: GetSamplingSettingsOptions): Promise<UsageTapSuccessResponse<SamplingSettings>>;
1172
+ shouldSampleAsync(request: SamplingDecisionInput, policy?: SamplingOptions): Promise<boolean>;
1173
+ decideSample(request: SamplingDecisionRequest, options?: SamplingDecisionOptions): Promise<UsageTapSuccessResponse<SamplingDecisionResponseBody>>;
1174
+ captureSample(request: CaptureSampleRequest, options?: CaptureSampleOptions): Promise<UsageTapSuccessResponse<CaptureSampleResponseBody>>;
1175
+ beginCall(request: BeginCallRequest, options?: BeginCallOptions): Promise<UsageTapSuccessResponse<BeginCallResponseBody>>;
1176
+ /**
1177
+ * Inspect a configured run circuit breaker without consuming another call.
1178
+ */
1179
+ canRunContinue(request: Pick<BeginCallRequest, "customerId" | "runId">): CircuitBreakerDecision;
1180
+ /**
1181
+ * Release local state after a workflow finishes. Returns true when state existed.
1182
+ */
1183
+ resetRun(request: Pick<BeginCallRequest, "customerId" | "runId">): boolean;
1184
+ promptCompress(request: PromptCompressionRequest, options?: PromptCompressionOptions): Promise<PromptCompressionResult & {
1185
+ callId: string;
1186
+ }>;
1187
+ compressPromptInput<TInput = unknown>(input: TInput, options?: PromptCompressionStandaloneOptions): Promise<PromptCompressionResult<TInput>>;
1188
+ /**
1189
+ * Compress text with UsageTap's hosted compression service.
1190
+ *
1191
+ * This is the short, standalone path. It does not create a metered call and
1192
+ * fails open to the original text unless failOpen is explicitly disabled.
1193
+ */
1194
+ compress(text: string, options?: UsageTapCompressOptions): Promise<UsageTapCompressResult>;
1195
+ compressPromptMessages<TInput = unknown>(input: TInput, options?: PromptCompressionMessagesOptions): Promise<PromptCompressionResult<TInput>>;
1196
+ recordPromptCompression(request: RecordPromptCompressionRequest, options?: PromptCompressionOptions): Promise<UsageTapSuccessResponse<PromptCompressionResponseBody>>;
1197
+ endCall(request: EndCallRequest, options?: EndCallOptions): Promise<UsageTapSuccessResponse<EndCallResponseBody>>;
1198
+ checkUsage(request: CheckUsageRequest, options?: CheckUsageOptions): Promise<UsageTapSuccessResponse<CheckUsageResponseBody>>;
1199
+ createCustomer(request: CreateCustomerRequest, options?: CreateCustomerOptions): Promise<UsageTapSuccessResponse<CreateCustomerResponseBody>>;
1200
+ changePlan(request: ChangePlanRequest, options?: ChangePlanOptions): Promise<UsageTapSuccessResponse<ChangePlanResponseBody>>;
1201
+ incrementCustomMeter(request: IncrementCustomMeterRequest, options?: IncrementCustomMeterOptions): Promise<UsageTapSuccessResponse<IncrementCustomMeterResponseBody>>;
1202
+ withUsage<T>(beginRequest: BeginCallRequest, handler: (context: WithUsageContext) => Promise<T>, options?: WithUsageOptions): Promise<T>;
1203
+ /**
1204
+ * Meter one operation. Pass only a customer ID for the common path, or the
1205
+ * existing begin-call request object when feature, tags, or entitlements are needed.
1206
+ */
1207
+ meter<T>(request: MeterRequest, handler: (context: WithUsageContext) => Promise<T>, options?: WithUsageOptions): Promise<T>;
1208
+ private toPromptCompressionTelemetry;
1209
+ private reserveRunCall;
1210
+ private resolveRunIdentity;
1211
+ private createCircuitBreakerDecision;
1212
+ private expireInactiveRuns;
1213
+ private request;
1214
+ private requestGet;
1215
+ private performFetch;
1216
+ private composeHeaders;
1217
+ private log;
1218
+ private emitUsageMetric;
1219
+ private mergeTags;
1220
+ private shouldRetry;
1221
+ private toHttpError;
1222
+ private toApiError;
1223
+ }
1224
+
1225
+ export { type PromptCompressionResponseBody as $, compressPrompt as A, type BeginCallRequest as B, compressPromptMessages as C, compressPromptHeuristic as D, type EndCallRequest as E, compressPromptToon as F, type GatewayBatch as G, estimatePromptTokens as H, protect as I, protectPromptText as J, type PromptCompressionInput as K, type PromptCompressionMessagesAggressiveness as L, type MeterRequest as M, type PromptCompressionMessagesInput as N, type PromptCompressionMessageRole as O, type PromptCompressionProvider as P, type PromptCompressionResult as Q, type ResourceRequestOptions as R, type SamplingOptions as S, type PromptCompressionRoleAggressiveness as T, UsageTapClient as U, type VendorHints as V, type WithUsageOptions as W, type BeginCallOptions as X, type PromptCompressionRequest as Y, type PromptCompressionOptions as Z, type PromptCompressionMessagesOptions as _, type PromptCompressionMode as a, type PromptCompressionStandaloneOptions as a0, type RecordPromptCompressionRequest as a1, type CreateCustomerOptions as a2, type CreateCustomerRequest as a3, type CreateCustomerResponseBody as a4, type CheckUsageOptions as a5, type CheckUsageRequest as a6, type CheckUsageResponseBody as a7, type ChangePlanOptions as a8, type ChangePlanRequest as a9, type UsageTapClientOptions as aA, type UsageTapErrorResponse as aB, type UsageTapResultEnvelope as aC, type UsageTapResultStatus as aD, type UsageTapLogEntry as aE, type WithUsageContext as aF, type LimitType as aG, type SubscriptionSnapshot as aH, type ModelHints as aI, type IdempotencyMetadata as aJ, type UsageMetricEvent as aK, type SamplingDecisionInput as aL, type CaptureSampleRequest as aM, type CaptureSampleOptions as aN, type CaptureSampleResponseBody as aO, type SamplingSettings as aP, type GetSamplingSettingsOptions as aQ, type SamplingDecisionRequest as aR, type SamplingDecisionResponseBody as aS, type SamplingDecisionOptions as aT, type CircuitBreakerOptions as aU, type CircuitBreakerDecision as aV, type ChangePlanResponseBody as aa, type ChangePlanStrategy as ab, type IncrementCustomMeterOptions as ac, type IncrementCustomMeterRequest as ad, type IncrementCustomMeterResponseBody as ae, type CustomMeterSlot as af, type EndCallOptions as ag, type EndCallResponseBody as ah, type BalanceSummary as ai, type SpendVelocitySnapshot as aj, type SpendVelocityWindow as ak, type SpendVelocityWindowKey as al, type EntitlementHints as am, type PlanSummary as an, type MeterSummary as ao, type MeterSnapshot as ap, type MeteredUsage as aq, type RateLimitsSnapshot as ar, type RemainingRatios as as, type RollingCallsRateLimitState as at, type RequestedEntitlements as au, type AllowedEntitlements as av, type ReasoningLevel as aw, type ReasoningEffort as ax, type ReasoningEffortSource as ay, type RetryOptions as az, type PromptCompressionTelemetry as b, type UsageTapSuccessResponse as c, type BeginCallResponseBody as d, type UsageTapCompressOptions as e, type UsageTapCompressResult as f, type GatewayBatchCreateParams as g, type GatewayBatchRequest as h, type GatewayBatchResult as i, type GatewayBatchStatus as j, type GatewayChatCompletion as k, type GatewayChatCompletionCreateParams as l, type GatewayChatMessage as m, type GatewayModel as n, type GatewayModelList as o, type SummarizationBatch as p, type SummarizationBatchCreateParams as q, type SummarizationBatchJob as r, type SummarizationContext as s, type SummarizationCreateParams as t, type SummarizationJob as u, type SummarizationMeasurement as v, type SummarizationMeasurementCreateParams as w, type SummarizationProfile as x, type SummarizationStatus as y, type WaitOptions as z };