@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
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { U as UsageTapClient, B as BeginCallRequest } from './client-
|
|
2
|
-
export {
|
|
1
|
+
import { U as UsageTapClient, B as BeginCallRequest } from './client-C0UiaqVB.cjs';
|
|
2
|
+
export { aF as AllowedEntitlements, as as BalanceSummary, a5 as BeginCallOptions, d as BeginCallResponseBody, aX as CaptureSampleOptions, aW as CaptureSampleRequest, aY as CaptureSampleResponseBody, ai as ChangePlanOptions, aj as ChangePlanRequest, ak as ChangePlanResponseBody, al as ChangePlanStrategy, af as CheckUsageOptions, ag as CheckUsageRequest, ah as CheckUsageResponseBody, b3 as CircuitBreakerDecision, b2 as CircuitBreakerOptions, ac as CreateCustomerOptions, ad as CreateCustomerRequest, ae as CreateCustomerResponseBody, ap as CustomMeterSlot, aq as EndCallOptions, E as EndCallRequest, ar as EndCallResponseBody, aw as EntitlementHints, G as GatewayBatch, g as GatewayBatchCreateParams, h as GatewayBatchRequest, i as GatewayBatchResult, j as GatewayBatchStatus, k as GatewayChatCompletion, l as GatewayChatCompletionCreateParams, m as GatewayChatMessage, x as GatewayModel, y as GatewayModelList, n as GatewayPromptCacheBreakpoint, o as GatewayResponse, p as GatewayResponseCreateParams, q as GatewayResponseInputItem, r as GatewayResponseInputMessage, s as GatewayResponseInputText, t as GatewayResponsePromptCacheOptions, u as GatewayResponseTextConfig, v as GatewayResponseTextFormat, w as GatewayResponseVerbosity, a_ as GetSamplingSettingsOptions, aT as IdempotencyMetadata, am as IncrementCustomMeterOptions, an as IncrementCustomMeterRequest, ao as IncrementCustomMeterResponseBody, aQ as LimitType, M as MeterRequest, az as MeterSnapshot, ay as MeterSummary, aA as MeteredUsage, aS as ModelHints, ax as PlanSummary, $ as PromptCompressionInput, a2 as PromptCompressionMessageRole, a0 as PromptCompressionMessagesAggressiveness, a1 as PromptCompressionMessagesInput, a8 as PromptCompressionMessagesOptions, a as PromptCompressionMode, a7 as PromptCompressionOptions, P as PromptCompressionProvider, a6 as PromptCompressionRequest, a9 as PromptCompressionResponseBody, a3 as PromptCompressionResult, a4 as PromptCompressionRoleAggressiveness, aa as PromptCompressionStandaloneOptions, b as PromptCompressionTelemetry, aB as RateLimitsSnapshot, aH as ReasoningEffort, aI as ReasoningEffortSource, aG as ReasoningLevel, ab as RecordPromptCompressionRequest, aC as RemainingRatios, aE as RequestedEntitlements, R as ResourceRequestOptions, aJ as RetryOptions, aD as RollingCallsRateLimitState, aV as SamplingDecisionInput, b1 as SamplingDecisionOptions, a$ as SamplingDecisionRequest, b0 as SamplingDecisionResponseBody, S as SamplingOptions, aZ as SamplingSettings, at as SpendVelocitySnapshot, au as SpendVelocityWindow, av as SpendVelocityWindowKey, aR as SubscriptionSnapshot, z as SummarizationBatch, A as SummarizationBatchCreateParams, C as SummarizationBatchJob, D as SummarizationContext, F as SummarizationCreateParams, H as SummarizationJob, I as SummarizationMeasurement, J as SummarizationMeasurementCreateParams, K as SummarizationProfile, L as SummarizationStatus, aU as UsageMetricEvent, aK as UsageTapClientOptions, e as UsageTapCompressOptions, f as UsageTapCompressResult, aL as UsageTapErrorResponse, aO as UsageTapLogEntry, aM as UsageTapResultEnvelope, aN as UsageTapResultStatus, c as UsageTapSuccessResponse, V as VendorHints, N as WaitOptions, aP as WithUsageContext, W as WithUsageOptions, O as compressPrompt, T as compressPromptHeuristic, Q as compressPromptMessages, X as compressPromptToon, Y as estimatePromptTokens, Z as protect, _ as protectPromptText } from './client-C0UiaqVB.cjs';
|
|
3
3
|
|
|
4
|
-
type UsageTapErrorCode = "USAGETAP_BROWSER_RUNTIME" | "USAGETAP_AUTH_ERROR" | "USAGETAP_BAD_REQUEST" | "USAGETAP_INVALID_RESPONSE" | "USAGETAP_NETWORK_ERROR" | "USAGETAP_RATE_LIMITED" | "USAGETAP_SERVER_ERROR" | "USAGETAP_RETRY_EXHAUSTED" | "USAGETAP_END_CALL_ERROR";
|
|
4
|
+
type UsageTapErrorCode = "USAGETAP_BROWSER_RUNTIME" | "USAGETAP_AUTH_ERROR" | "USAGETAP_BAD_REQUEST" | "USAGETAP_INVALID_RESPONSE" | "USAGETAP_NETWORK_ERROR" | "USAGETAP_RATE_LIMITED" | "USAGETAP_CIRCUIT_OPEN" | "USAGETAP_SERVER_ERROR" | "USAGETAP_RETRY_EXHAUSTED" | "USAGETAP_END_CALL_ERROR";
|
|
5
5
|
interface UsageTapErrorInit {
|
|
6
6
|
status?: number;
|
|
7
7
|
retryable?: boolean;
|
|
@@ -24,6 +24,8 @@ interface WrapFetchContext extends Omit<BeginCallRequest, "idempotency"> {
|
|
|
24
24
|
customerId: string;
|
|
25
25
|
}
|
|
26
26
|
interface WrapFetchOptions {
|
|
27
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
28
|
+
provider?: string;
|
|
27
29
|
/**
|
|
28
30
|
* Context for UsageTap begin calls.
|
|
29
31
|
* Can be overridden per-request via special headers.
|
|
@@ -41,9 +43,18 @@ interface WrapFetchOptions {
|
|
|
41
43
|
autoIdempotency?: boolean;
|
|
42
44
|
/**
|
|
43
45
|
* Detect OpenAI-compatible endpoints by URL pattern.
|
|
44
|
-
* Default: detects /v1/chat/completions and /v1/
|
|
46
|
+
* Default: detects /v1/chat/completions, /v1/responses, and /v1/embeddings
|
|
45
47
|
*/
|
|
46
48
|
isOpenAIEndpoint?: (url: string) => boolean;
|
|
49
|
+
/** Receive request parsing or begin/end failures after client retries. */
|
|
50
|
+
onMeteringError?: (event: WrapFetchMeteringError) => void | Promise<void>;
|
|
51
|
+
/** Throw metering failures instead of allowing the vendor response through. */
|
|
52
|
+
strictMetering?: boolean;
|
|
53
|
+
}
|
|
54
|
+
interface WrapFetchMeteringError {
|
|
55
|
+
stage: "request" | "begin" | "end";
|
|
56
|
+
callId?: string;
|
|
57
|
+
error: unknown;
|
|
47
58
|
}
|
|
48
59
|
/**
|
|
49
60
|
* Wraps a fetch implementation to automatically instrument OpenAI API calls
|
|
@@ -65,4 +76,4 @@ declare function wrapFetch(usageTap: UsageTapClient, options: WrapFetchOptions):
|
|
|
65
76
|
|
|
66
77
|
declare function createIdempotencyKey(): string;
|
|
67
78
|
|
|
68
|
-
export { BeginCallRequest, UsageTapClient as UsageTap, UsageTapClient, UsageTapError, type UsageTapErrorCode, type UsageTapErrorInit, type WrapFetchContext, type WrapFetchOptions, createIdempotencyKey, isUsageTapError, wrapFetch };
|
|
79
|
+
export { BeginCallRequest, UsageTapClient as UsageTap, UsageTapClient, UsageTapError, type UsageTapErrorCode, type UsageTapErrorInit, type WrapFetchContext, type WrapFetchMeteringError, type WrapFetchOptions, createIdempotencyKey, isUsageTapError, wrapFetch };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { U as UsageTapClient, B as BeginCallRequest } from './client-
|
|
2
|
-
export {
|
|
1
|
+
import { U as UsageTapClient, B as BeginCallRequest } from './client-C0UiaqVB.js';
|
|
2
|
+
export { aF as AllowedEntitlements, as as BalanceSummary, a5 as BeginCallOptions, d as BeginCallResponseBody, aX as CaptureSampleOptions, aW as CaptureSampleRequest, aY as CaptureSampleResponseBody, ai as ChangePlanOptions, aj as ChangePlanRequest, ak as ChangePlanResponseBody, al as ChangePlanStrategy, af as CheckUsageOptions, ag as CheckUsageRequest, ah as CheckUsageResponseBody, b3 as CircuitBreakerDecision, b2 as CircuitBreakerOptions, ac as CreateCustomerOptions, ad as CreateCustomerRequest, ae as CreateCustomerResponseBody, ap as CustomMeterSlot, aq as EndCallOptions, E as EndCallRequest, ar as EndCallResponseBody, aw as EntitlementHints, G as GatewayBatch, g as GatewayBatchCreateParams, h as GatewayBatchRequest, i as GatewayBatchResult, j as GatewayBatchStatus, k as GatewayChatCompletion, l as GatewayChatCompletionCreateParams, m as GatewayChatMessage, x as GatewayModel, y as GatewayModelList, n as GatewayPromptCacheBreakpoint, o as GatewayResponse, p as GatewayResponseCreateParams, q as GatewayResponseInputItem, r as GatewayResponseInputMessage, s as GatewayResponseInputText, t as GatewayResponsePromptCacheOptions, u as GatewayResponseTextConfig, v as GatewayResponseTextFormat, w as GatewayResponseVerbosity, a_ as GetSamplingSettingsOptions, aT as IdempotencyMetadata, am as IncrementCustomMeterOptions, an as IncrementCustomMeterRequest, ao as IncrementCustomMeterResponseBody, aQ as LimitType, M as MeterRequest, az as MeterSnapshot, ay as MeterSummary, aA as MeteredUsage, aS as ModelHints, ax as PlanSummary, $ as PromptCompressionInput, a2 as PromptCompressionMessageRole, a0 as PromptCompressionMessagesAggressiveness, a1 as PromptCompressionMessagesInput, a8 as PromptCompressionMessagesOptions, a as PromptCompressionMode, a7 as PromptCompressionOptions, P as PromptCompressionProvider, a6 as PromptCompressionRequest, a9 as PromptCompressionResponseBody, a3 as PromptCompressionResult, a4 as PromptCompressionRoleAggressiveness, aa as PromptCompressionStandaloneOptions, b as PromptCompressionTelemetry, aB as RateLimitsSnapshot, aH as ReasoningEffort, aI as ReasoningEffortSource, aG as ReasoningLevel, ab as RecordPromptCompressionRequest, aC as RemainingRatios, aE as RequestedEntitlements, R as ResourceRequestOptions, aJ as RetryOptions, aD as RollingCallsRateLimitState, aV as SamplingDecisionInput, b1 as SamplingDecisionOptions, a$ as SamplingDecisionRequest, b0 as SamplingDecisionResponseBody, S as SamplingOptions, aZ as SamplingSettings, at as SpendVelocitySnapshot, au as SpendVelocityWindow, av as SpendVelocityWindowKey, aR as SubscriptionSnapshot, z as SummarizationBatch, A as SummarizationBatchCreateParams, C as SummarizationBatchJob, D as SummarizationContext, F as SummarizationCreateParams, H as SummarizationJob, I as SummarizationMeasurement, J as SummarizationMeasurementCreateParams, K as SummarizationProfile, L as SummarizationStatus, aU as UsageMetricEvent, aK as UsageTapClientOptions, e as UsageTapCompressOptions, f as UsageTapCompressResult, aL as UsageTapErrorResponse, aO as UsageTapLogEntry, aM as UsageTapResultEnvelope, aN as UsageTapResultStatus, c as UsageTapSuccessResponse, V as VendorHints, N as WaitOptions, aP as WithUsageContext, W as WithUsageOptions, O as compressPrompt, T as compressPromptHeuristic, Q as compressPromptMessages, X as compressPromptToon, Y as estimatePromptTokens, Z as protect, _ as protectPromptText } from './client-C0UiaqVB.js';
|
|
3
3
|
|
|
4
|
-
type UsageTapErrorCode = "USAGETAP_BROWSER_RUNTIME" | "USAGETAP_AUTH_ERROR" | "USAGETAP_BAD_REQUEST" | "USAGETAP_INVALID_RESPONSE" | "USAGETAP_NETWORK_ERROR" | "USAGETAP_RATE_LIMITED" | "USAGETAP_SERVER_ERROR" | "USAGETAP_RETRY_EXHAUSTED" | "USAGETAP_END_CALL_ERROR";
|
|
4
|
+
type UsageTapErrorCode = "USAGETAP_BROWSER_RUNTIME" | "USAGETAP_AUTH_ERROR" | "USAGETAP_BAD_REQUEST" | "USAGETAP_INVALID_RESPONSE" | "USAGETAP_NETWORK_ERROR" | "USAGETAP_RATE_LIMITED" | "USAGETAP_CIRCUIT_OPEN" | "USAGETAP_SERVER_ERROR" | "USAGETAP_RETRY_EXHAUSTED" | "USAGETAP_END_CALL_ERROR";
|
|
5
5
|
interface UsageTapErrorInit {
|
|
6
6
|
status?: number;
|
|
7
7
|
retryable?: boolean;
|
|
@@ -24,6 +24,8 @@ interface WrapFetchContext extends Omit<BeginCallRequest, "idempotency"> {
|
|
|
24
24
|
customerId: string;
|
|
25
25
|
}
|
|
26
26
|
interface WrapFetchOptions {
|
|
27
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
28
|
+
provider?: string;
|
|
27
29
|
/**
|
|
28
30
|
* Context for UsageTap begin calls.
|
|
29
31
|
* Can be overridden per-request via special headers.
|
|
@@ -41,9 +43,18 @@ interface WrapFetchOptions {
|
|
|
41
43
|
autoIdempotency?: boolean;
|
|
42
44
|
/**
|
|
43
45
|
* Detect OpenAI-compatible endpoints by URL pattern.
|
|
44
|
-
* Default: detects /v1/chat/completions and /v1/
|
|
46
|
+
* Default: detects /v1/chat/completions, /v1/responses, and /v1/embeddings
|
|
45
47
|
*/
|
|
46
48
|
isOpenAIEndpoint?: (url: string) => boolean;
|
|
49
|
+
/** Receive request parsing or begin/end failures after client retries. */
|
|
50
|
+
onMeteringError?: (event: WrapFetchMeteringError) => void | Promise<void>;
|
|
51
|
+
/** Throw metering failures instead of allowing the vendor response through. */
|
|
52
|
+
strictMetering?: boolean;
|
|
53
|
+
}
|
|
54
|
+
interface WrapFetchMeteringError {
|
|
55
|
+
stage: "request" | "begin" | "end";
|
|
56
|
+
callId?: string;
|
|
57
|
+
error: unknown;
|
|
47
58
|
}
|
|
48
59
|
/**
|
|
49
60
|
* Wraps a fetch implementation to automatically instrument OpenAI API calls
|
|
@@ -65,4 +76,4 @@ declare function wrapFetch(usageTap: UsageTapClient, options: WrapFetchOptions):
|
|
|
65
76
|
|
|
66
77
|
declare function createIdempotencyKey(): string;
|
|
67
78
|
|
|
68
|
-
export { BeginCallRequest, UsageTapClient as UsageTap, UsageTapClient, UsageTapError, type UsageTapErrorCode, type UsageTapErrorInit, type WrapFetchContext, type WrapFetchOptions, createIdempotencyKey, isUsageTapError, wrapFetch };
|
|
79
|
+
export { BeginCallRequest, UsageTapClient as UsageTap, UsageTapClient, UsageTapError, type UsageTapErrorCode, type UsageTapErrorInit, type WrapFetchContext, type WrapFetchMeteringError, type WrapFetchOptions, createIdempotencyKey, isUsageTapError, wrapFetch };
|