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