@usagetap/sdk 0.2.1 → 0.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.
- package/README.md +27 -1
- package/dist/adapters/openai.d.cts +1 -1
- package/dist/adapters/openai.d.ts +1 -1
- package/dist/adapters/openrouter.d.cts +1 -1
- package/dist/adapters/openrouter.d.ts +1 -1
- package/dist/index.cjs +23 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/{openai-CeptbEGH.d.cts → openai-Ch7hN2vD.d.cts} +16 -1
- package/dist/{openai-CeptbEGH.d.ts → openai-Ch7hN2vD.d.ts} +16 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UsageTapClient, B as BeginCallRequest, W as WrapOpenAIContext, a as WrapOpenAIOptions, w as wrapOpenAI, p as pipeToResponse } from './openai-
|
|
2
|
-
export {
|
|
1
|
+
import { U as UsageTapClient, B as BeginCallRequest, W as WrapOpenAIContext, a as WrapOpenAIOptions, w as wrapOpenAI, p as pipeToResponse } from './openai-Ch7hN2vD.cjs';
|
|
2
|
+
export { H as AllowedEntitlements, z as BalanceSummary, m as BeginCallOptions, n as BeginCallResponseBody, r as CheckUsageOptions, u as CheckUsageRequest, v as CheckUsageResponseBody, C as CreateCustomerOptions, o as CreateCustomerRequest, q as CreateCustomerResponseBody, E as EndCallOptions, x as EndCallRequest, y as EndCallResponseBody, A as EntitlementHints, a1 as IdempotencyMetadata, _ as LimitType, D as MeterSnapshot, M as MeterSummary, F as MeteredUsage, a0 as ModelHints, N as NodeResponseLike, O as OpenAIAdapter, b as OpenAIAdapterInit, d as OpenAIInvokeParams, e as OpenAIInvokeResult, f as OpenAIStreamParams, g as OpenAIStreamResult, P as PlanSummary, R as RemainingRatios, G as RequestedEntitlements, I as RetryOptions, S as StreamMode, l as StreamOpenAIRouteOptions, h as StreamToResponseOptions, $ as SubscriptionSnapshot, J as UsageTapClientOptions, L as UsageTapErrorResponse, X as UsageTapLogEntry, Q as UsageTapResultEnvelope, T as UsageTapResultStatus, K as UsageTapSuccessResponse, V as VendorHints, Y as WithUsageContext, Z as WithUsageOptions, i as WrapOpenAICallOptions, j as WrapOpenAIResponseCallOptions, k as WrappedOpenAI, c as createOpenAIAdapter, s as streamOpenAIRoute, t as toNextResponse } from './openai-Ch7hN2vD.cjs';
|
|
3
3
|
export { createOpenRouterAdapter } from './adapters/openrouter.cjs';
|
|
4
4
|
import OpenAI from 'openai';
|
|
5
5
|
import { Request, Response, NextFunction } from 'express';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UsageTapClient, B as BeginCallRequest, W as WrapOpenAIContext, a as WrapOpenAIOptions, w as wrapOpenAI, p as pipeToResponse } from './openai-
|
|
2
|
-
export {
|
|
1
|
+
import { U as UsageTapClient, B as BeginCallRequest, W as WrapOpenAIContext, a as WrapOpenAIOptions, w as wrapOpenAI, p as pipeToResponse } from './openai-Ch7hN2vD.js';
|
|
2
|
+
export { H as AllowedEntitlements, z as BalanceSummary, m as BeginCallOptions, n as BeginCallResponseBody, r as CheckUsageOptions, u as CheckUsageRequest, v as CheckUsageResponseBody, C as CreateCustomerOptions, o as CreateCustomerRequest, q as CreateCustomerResponseBody, E as EndCallOptions, x as EndCallRequest, y as EndCallResponseBody, A as EntitlementHints, a1 as IdempotencyMetadata, _ as LimitType, D as MeterSnapshot, M as MeterSummary, F as MeteredUsage, a0 as ModelHints, N as NodeResponseLike, O as OpenAIAdapter, b as OpenAIAdapterInit, d as OpenAIInvokeParams, e as OpenAIInvokeResult, f as OpenAIStreamParams, g as OpenAIStreamResult, P as PlanSummary, R as RemainingRatios, G as RequestedEntitlements, I as RetryOptions, S as StreamMode, l as StreamOpenAIRouteOptions, h as StreamToResponseOptions, $ as SubscriptionSnapshot, J as UsageTapClientOptions, L as UsageTapErrorResponse, X as UsageTapLogEntry, Q as UsageTapResultEnvelope, T as UsageTapResultStatus, K as UsageTapSuccessResponse, V as VendorHints, Y as WithUsageContext, Z as WithUsageOptions, i as WrapOpenAICallOptions, j as WrapOpenAIResponseCallOptions, k as WrappedOpenAI, c as createOpenAIAdapter, s as streamOpenAIRoute, t as toNextResponse } from './openai-Ch7hN2vD.js';
|
|
3
3
|
export { createOpenRouterAdapter } from './adapters/openrouter.js';
|
|
4
4
|
import OpenAI from 'openai';
|
|
5
5
|
import { Request, Response, NextFunction } from 'express';
|
package/dist/index.js
CHANGED
|
@@ -117,6 +117,7 @@ async function runWithRetry(operation, options, shouldRetry, onSchedule, signal)
|
|
|
117
117
|
var CALL_BEGIN_PATH = "call_begin";
|
|
118
118
|
var CALL_END_PATH = "call_end";
|
|
119
119
|
var CHECK_USAGE_PATH = "customers/{customerId}/usage";
|
|
120
|
+
var CREATE_CUSTOMER_PATH = "customers";
|
|
120
121
|
var AUTH_HEADER = "authorization";
|
|
121
122
|
var API_KEY_HEADER = "x-api-key";
|
|
122
123
|
var CORRELATION_HEADER = "x-usage-correlation-id";
|
|
@@ -124,7 +125,7 @@ var IDEMPOTENCY_HEADER = "idempotency-key";
|
|
|
124
125
|
var SDK_HEADER = "x-usage-sdk";
|
|
125
126
|
var USER_AGENT = "UsageTapClient";
|
|
126
127
|
var CANONICAL_MEDIA_TYPE = "application/vnd.usagetap.v1+json";
|
|
127
|
-
var SDK_VERSION = "0.
|
|
128
|
+
var SDK_VERSION = "0.4.0" ;
|
|
128
129
|
var HAS_WINDOW = typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined";
|
|
129
130
|
var UsageTapClient = class {
|
|
130
131
|
apiKey;
|
|
@@ -235,6 +236,24 @@ var UsageTapClient = class {
|
|
|
235
236
|
);
|
|
236
237
|
return response;
|
|
237
238
|
}
|
|
239
|
+
async createCustomer(request, options = {}) {
|
|
240
|
+
if (!request?.customerId) {
|
|
241
|
+
throw new UsageTapError(
|
|
242
|
+
"USAGETAP_BAD_REQUEST",
|
|
243
|
+
"createCustomer requires customerId"
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const idempotencyKey = options.idempotencyKey ?? (this.autoIdempotency ? this.idempotencyGenerator() : void 0);
|
|
247
|
+
const response = await this.request(
|
|
248
|
+
CREATE_CUSTOMER_PATH,
|
|
249
|
+
{ ...request },
|
|
250
|
+
{
|
|
251
|
+
...options,
|
|
252
|
+
idempotencyKey
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
return response;
|
|
256
|
+
}
|
|
238
257
|
async withUsage(beginRequest, handler, options = {}) {
|
|
239
258
|
const idempotencyKey = beginRequest.idempotency ?? (this.autoIdempotency ? this.idempotencyGenerator() : void 0);
|
|
240
259
|
const beginPayload = idempotencyKey ? { ...beginRequest, idempotency: idempotencyKey } : { ...beginRequest };
|
|
@@ -478,10 +497,12 @@ var UsageTapClient = class {
|
|
|
478
497
|
const headers = {
|
|
479
498
|
...this.defaultHeaders,
|
|
480
499
|
[SDK_HEADER]: `js/${SDK_VERSION}`,
|
|
481
|
-
"user-agent": `${USER_AGENT}/${SDK_VERSION}`,
|
|
482
500
|
"content-type": "application/json",
|
|
483
501
|
accept: CANONICAL_MEDIA_TYPE
|
|
484
502
|
};
|
|
503
|
+
if (!HAS_WINDOW) {
|
|
504
|
+
headers["user-agent"] = `${USER_AGENT}/${SDK_VERSION}`;
|
|
505
|
+
}
|
|
485
506
|
if (this.authHeader === API_KEY_HEADER) {
|
|
486
507
|
headers[API_KEY_HEADER] = this.apiKey;
|
|
487
508
|
} else {
|