@byte_fluffy/nexra-sdk 0.1.0-alpha.1
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 +35 -0
- package/dist/catalog-mytCeh5t.d.ts +313 -0
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.js +10 -0
- package/dist/chunk-ADKRTC6X.js +1512 -0
- package/dist/chunk-FCH5IQP5.js +34 -0
- package/dist/decimal.d.ts +4 -0
- package/dist/decimal.js +8 -0
- package/dist/index.d.ts +1006 -0
- package/dist/index.js +1428 -0
- package/package.json +44 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
import { J as JsonObject, B as BillingMetric, a as JsonValue, N as NexraSettlement, C as CursorPage, H as HttpTransport, M as ModelSearchParams, T as TaskModelSummary, b as TaskModel, c as ModelSchema, d as CatalogClient, e as NexraClientOptions } from './catalog-mytCeh5t.js';
|
|
2
|
+
export { f as BILLING_EXPORT_DIMENSIONS, g as BILLING_METRICS, h as CreateNexraQuoteRequest, F as FetchLike, i as JsonPrimitive, j as MeteredPriceRate, k as MeteredPriceRuleV1, l as MeteredUsageComponent, m as MeteringContract, n as MeteringKind, o as ModelCapabilitySummary, p as ModelDateVersion, q as ModelEndpointSummary, r as ModelModality, s as ModelResourceList, t as ModelResourceOption, u as NexraBillingCurrency, v as NexraModelOperation, w as NexraModelSpec, x as NexraModelSpecFilter, y as NexraQuote, z as NexraSalePrice, A as NormalizedUsageV1, P as PriceEvaluation, D as PriceEvaluationIssue, E as PriceEvaluationLine, G as PriceRule, U as UsageComponentEvidence, I as UsageEvidenceAssessment, K as UsageEvidenceStatus, L as allocateDiscountedPriceLines, O as assessUsageEvidence, Q as evaluatePriceRule, R as getModelSpec, S as jsonBody, V as listModelSpecs, W as queryString, X as sleep, Y as validateMeteringContract, Z as validateNormalizedUsage, _ as validatePriceRule } from './catalog-mytCeh5t.js';
|
|
3
|
+
export { ceilDecimal, multiplyDecimal } from './decimal.js';
|
|
4
|
+
|
|
5
|
+
declare const MEDIA_KINDS: readonly ["image", "video", "audio", "document", "archive", "other"];
|
|
6
|
+
type MediaKind = (typeof MEDIA_KINDS)[number];
|
|
7
|
+
type MediaAssetStatus = "pending" | "ready" | "failed" | "deleted";
|
|
8
|
+
interface MediaAsset {
|
|
9
|
+
id: string;
|
|
10
|
+
kind: MediaKind;
|
|
11
|
+
status: MediaAssetStatus;
|
|
12
|
+
source: "upload" | "generated" | "provider" | "imported";
|
|
13
|
+
name?: string;
|
|
14
|
+
mimeType?: string;
|
|
15
|
+
sizeBytes?: number;
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
checksumSha256?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
downloadUrl?: string;
|
|
22
|
+
expiresAt?: string;
|
|
23
|
+
metadata?: JsonObject;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
}
|
|
26
|
+
interface AssetReference {
|
|
27
|
+
assetId: string;
|
|
28
|
+
}
|
|
29
|
+
type AssetInput = AssetReference | Blob | File | MediaAsset | string | URL;
|
|
30
|
+
interface AssetUploadOptions {
|
|
31
|
+
kind?: MediaKind;
|
|
32
|
+
name?: string;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
interface AssetImportRequest {
|
|
36
|
+
url: string;
|
|
37
|
+
kind?: MediaKind;
|
|
38
|
+
name?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type UploadDeliveryRegion = "cn" | "global";
|
|
42
|
+
declare function modelUploadRegion(regions: readonly string[]): UploadDeliveryRegion;
|
|
43
|
+
declare function uploadedMediaUrl(value: string, region: UploadDeliveryRegion): string;
|
|
44
|
+
declare function uploadedMediaInput(input: JsonObject, region: UploadDeliveryRegion): JsonObject;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Frozen usage-reporting semantics (admin-console-status TODO-01).
|
|
48
|
+
*
|
|
49
|
+
* Time: the population axis is `gateway.requests.received_at` and every
|
|
50
|
+
* window is the half-open interval `[start, end)`. The database stores UTC
|
|
51
|
+
* instants; API callers pass ISO-8601 instants and may pass a
|
|
52
|
+
* `timeZoneOffsetMinutes` offset (east positive, -720..840) that only affects
|
|
53
|
+
* day/month/… bucket edges, never stored data or window matching.
|
|
54
|
+
*
|
|
55
|
+
* Sources: a request may carry several usage records (unique per source).
|
|
56
|
+
* Reporting reads exactly one per request with the fixed priority
|
|
57
|
+
* `reconciled` > `provider` > `estimated`; `reconciled` is the final truth
|
|
58
|
+
* after correction, `provider` is vendor evidence, `estimated` is a fallback.
|
|
59
|
+
*
|
|
60
|
+
* Normalization status (derived at query time, there is no stored column):
|
|
61
|
+
* - `normalized`: the selected record has a valid non-empty v1 component array.
|
|
62
|
+
* - `partial`: reserved for "some raw vendor fields could not be mapped into
|
|
63
|
+
* any standard metric"; the current pipeline cannot detect it, so queries
|
|
64
|
+
* never emit it yet but callers may already filter for it.
|
|
65
|
+
* - `invalid`: a record exists but the normalized envelope is unusable
|
|
66
|
+
* (missing/non-array/empty components).
|
|
67
|
+
* - `missing`: no usage record exists for the request.
|
|
68
|
+
*
|
|
69
|
+
* Rating status (derived from the highest-priority charge of the request):
|
|
70
|
+
* - `billed`: a succeeded or refunded charge exists.
|
|
71
|
+
* - `billing_failed`: the chosen charge failed.
|
|
72
|
+
* - `unsettled`: usage exists, no charge yet, and a published sale price
|
|
73
|
+
* version effective at usage time exists (or the request has not
|
|
74
|
+
* succeeded, so settlement is not expected yet).
|
|
75
|
+
* - `unpriced`: usage exists, no charge, request succeeded, and no published
|
|
76
|
+
* sale price version was effective at usage time for the model/operation.
|
|
77
|
+
* - `usage_missing`: no usage record, so rating is impossible.
|
|
78
|
+
*
|
|
79
|
+
* "不适用 / 0 / 缺失" stay distinct: a metric absent from `metrics` means
|
|
80
|
+
* nothing was metered (missing or not applicable); a present `0` value was
|
|
81
|
+
* genuinely metered as zero. `tokens.applicable = false` means the model has
|
|
82
|
+
* no token rate in any published sale/cost price version, so empty token
|
|
83
|
+
* metrics for such models are "not applicable", never "missing".
|
|
84
|
+
*/
|
|
85
|
+
declare const USAGE_SOURCES: readonly ["provider", "estimated", "reconciled"];
|
|
86
|
+
type UsageSource = (typeof USAGE_SOURCES)[number];
|
|
87
|
+
declare const USAGE_NORMALIZATION_STATUSES: readonly ["normalized", "partial", "invalid", "missing"];
|
|
88
|
+
type UsageNormalizationStatus = (typeof USAGE_NORMALIZATION_STATUSES)[number];
|
|
89
|
+
declare const USAGE_RATING_STATUSES: readonly ["billed", "unsettled", "billing_failed", "unpriced", "usage_missing"];
|
|
90
|
+
type UsageRatingStatus = (typeof USAGE_RATING_STATUSES)[number];
|
|
91
|
+
declare const USAGE_GROUP_BYS: readonly ["minute", "hour", "day", "month", "user", "apiKey", "provider", "channel", "model", "operation"];
|
|
92
|
+
type UsageGroupBy = (typeof USAGE_GROUP_BYS)[number];
|
|
93
|
+
declare const USAGE_AMOUNT_KINDS: readonly ["sale", "cost", "gross"];
|
|
94
|
+
type UsageAmountKind = (typeof USAGE_AMOUNT_KINDS)[number];
|
|
95
|
+
declare const TOKEN_METRICS: readonly ["input_tokens", "cached_input_tokens", "cache_write_tokens", "cache_creation_5m_input_tokens", "cache_creation_1h_input_tokens", "cache_read_input_tokens", "output_tokens"];
|
|
96
|
+
/** Decimal string with up to 8 fraction digits; only `gross` may be negative. */
|
|
97
|
+
declare const MONEY_STRING_PATTERN: RegExp;
|
|
98
|
+
type MoneyString = string;
|
|
99
|
+
interface UsageTimeWindow {
|
|
100
|
+
/** Inclusive ISO-8601 instant. */
|
|
101
|
+
start: string;
|
|
102
|
+
/** Exclusive ISO-8601 instant; must be after `start`. */
|
|
103
|
+
end: string;
|
|
104
|
+
}
|
|
105
|
+
interface UsageFilters extends UsageTimeWindow {
|
|
106
|
+
timeZoneOffsetMinutes?: number;
|
|
107
|
+
userIds?: string[];
|
|
108
|
+
apiKeyIds?: string[];
|
|
109
|
+
providerIds?: string[];
|
|
110
|
+
channelIds?: string[];
|
|
111
|
+
modelIds?: string[];
|
|
112
|
+
operations?: string[];
|
|
113
|
+
upstreamModelId?: string;
|
|
114
|
+
requestStatuses?: string[];
|
|
115
|
+
usageSources?: UsageSource[];
|
|
116
|
+
normalizationStatuses?: UsageNormalizationStatus[];
|
|
117
|
+
ratingStatuses?: UsageRatingStatus[];
|
|
118
|
+
}
|
|
119
|
+
interface UsageSummaryQuery {
|
|
120
|
+
filters: UsageFilters;
|
|
121
|
+
/** At most one time granularity; keys are ordered as given. */
|
|
122
|
+
groupBy: UsageGroupBy[];
|
|
123
|
+
limit: number;
|
|
124
|
+
cursor?: string;
|
|
125
|
+
}
|
|
126
|
+
interface UsageSummaryGroup {
|
|
127
|
+
/** Bucket start as a UTC instant; present for time granularities. */
|
|
128
|
+
time?: string;
|
|
129
|
+
userId?: string | null;
|
|
130
|
+
apiKeyId?: string | null;
|
|
131
|
+
providerId?: string | null;
|
|
132
|
+
channelId?: string | null;
|
|
133
|
+
modelId?: string | null;
|
|
134
|
+
operation?: string | null;
|
|
135
|
+
}
|
|
136
|
+
interface UsageSummaryAmount {
|
|
137
|
+
kind: UsageAmountKind;
|
|
138
|
+
currency: string;
|
|
139
|
+
/** Decimal string; sums of numeric(20,8) charge amounts. */
|
|
140
|
+
amount: MoneyString;
|
|
141
|
+
}
|
|
142
|
+
interface UsageSummaryRow {
|
|
143
|
+
group: UsageSummaryGroup;
|
|
144
|
+
requests: {
|
|
145
|
+
total: number;
|
|
146
|
+
succeeded: number;
|
|
147
|
+
/** failed + cancelled + rejected requests. */
|
|
148
|
+
failed: number;
|
|
149
|
+
};
|
|
150
|
+
usage: {
|
|
151
|
+
/** Requests whose prioritized usage record exists. */
|
|
152
|
+
evidence: number;
|
|
153
|
+
/** Requests without any usage record; equals rating.usage_missing. */
|
|
154
|
+
missing: number;
|
|
155
|
+
sources: Record<UsageSource, number>;
|
|
156
|
+
normalization: Record<Exclude<UsageNormalizationStatus, "missing">, number>;
|
|
157
|
+
};
|
|
158
|
+
rating: Record<UsageRatingStatus, number>;
|
|
159
|
+
costReporting: {
|
|
160
|
+
/** Succeeded charges with a CNY reporting cost. */
|
|
161
|
+
reported: number;
|
|
162
|
+
/** Succeeded charges whose procurement cost was not recorded. */
|
|
163
|
+
missingCost: number;
|
|
164
|
+
/** Succeeded charges with an original cost but no matching frozen FX rate. */
|
|
165
|
+
missingRate: number;
|
|
166
|
+
};
|
|
167
|
+
tokens: {
|
|
168
|
+
/** Null unless `model` is a group key. */
|
|
169
|
+
applicable: boolean | null;
|
|
170
|
+
requestsWithTokenMetrics: number;
|
|
171
|
+
};
|
|
172
|
+
/** Metric quantities summed across dimensions; absent keys were never metered. */
|
|
173
|
+
metrics: Partial<Record<BillingMetric, number>>;
|
|
174
|
+
amounts: UsageSummaryAmount[];
|
|
175
|
+
}
|
|
176
|
+
interface UsageSummaryPage {
|
|
177
|
+
data: UsageSummaryRow[];
|
|
178
|
+
/** Present when more groups follow; opaque, valid only for the same query. */
|
|
179
|
+
nextCursor: string | null;
|
|
180
|
+
}
|
|
181
|
+
declare const USAGE_FILTER_SELECTION_LIMIT = 200;
|
|
182
|
+
declare function validateUsageFilters(value: unknown): asserts value is UsageFilters;
|
|
183
|
+
declare function validateUsageSummaryQuery(value: unknown): asserts value is UsageSummaryQuery;
|
|
184
|
+
/** Cursors are opaque offsets; they are only valid for the identical query. */
|
|
185
|
+
declare function encodeUsageSummaryCursor(offset: number): string;
|
|
186
|
+
declare function parseUsageSummaryCursor(value: string): number | null;
|
|
187
|
+
/**
|
|
188
|
+
* Keyset cursor over `(received_at, request id)` in descending order, shared
|
|
189
|
+
* by the details and anomaly queries.
|
|
190
|
+
*/
|
|
191
|
+
declare function encodeUsageKeysetCursor(receivedAt: string, requestId: string): string;
|
|
192
|
+
declare function parseUsageKeysetCursor(value: string): {
|
|
193
|
+
receivedAt: string;
|
|
194
|
+
requestId: string;
|
|
195
|
+
} | null;
|
|
196
|
+
interface UsageDetailsQuery {
|
|
197
|
+
filters: UsageFilters;
|
|
198
|
+
/** Page size, 1..200. */
|
|
199
|
+
limit: number;
|
|
200
|
+
cursor?: string;
|
|
201
|
+
}
|
|
202
|
+
interface UsageDetailUsage {
|
|
203
|
+
id: string | null;
|
|
204
|
+
source: UsageSource | null;
|
|
205
|
+
occurredAt: string | null;
|
|
206
|
+
/** Vendor-native evidence; request/response bodies and credentials are excluded. */
|
|
207
|
+
rawUsage: JsonObject;
|
|
208
|
+
normalizedUsage: JsonObject;
|
|
209
|
+
normalizationStatus: UsageNormalizationStatus;
|
|
210
|
+
}
|
|
211
|
+
interface UsageDetailCharge {
|
|
212
|
+
id: string;
|
|
213
|
+
status: string;
|
|
214
|
+
saleAmount: MoneyString | null;
|
|
215
|
+
saleCurrency: string | null;
|
|
216
|
+
costAmount: MoneyString | null;
|
|
217
|
+
costCurrency: string | null;
|
|
218
|
+
costReportingAmount: MoneyString | null;
|
|
219
|
+
costReportingCurrency: string | null;
|
|
220
|
+
costReportingFxRate: MoneyString | null;
|
|
221
|
+
costReportingFxSource: string | null;
|
|
222
|
+
costReportingFxEffectiveAt: string | null;
|
|
223
|
+
/** Price revision numbers bound at settlement time. */
|
|
224
|
+
discountBps: number | null;
|
|
225
|
+
/** Settlement-time price evaluation snapshot, including its `lines` and `issues`. */
|
|
226
|
+
breakdown: JsonObject;
|
|
227
|
+
}
|
|
228
|
+
interface UsageDetailRow {
|
|
229
|
+
/** Database request id; the drill-down key. */
|
|
230
|
+
requestId: string;
|
|
231
|
+
/** Client-facing request key (`gateway.requests.request_id`). */
|
|
232
|
+
requestKey: string;
|
|
233
|
+
receivedAt: string;
|
|
234
|
+
status: string;
|
|
235
|
+
httpStatus: number | null;
|
|
236
|
+
durationMs: number | null;
|
|
237
|
+
errorCode: string | null;
|
|
238
|
+
userId: string | null;
|
|
239
|
+
apiKeyId: string | null;
|
|
240
|
+
modelId: string;
|
|
241
|
+
modelPublicId: string | null;
|
|
242
|
+
requestedModel: string | null;
|
|
243
|
+
operation: string | null;
|
|
244
|
+
publicProtocol: string | null;
|
|
245
|
+
providerId: string | null;
|
|
246
|
+
channelId: string | null;
|
|
247
|
+
upstreamModelId: string | null;
|
|
248
|
+
usage: UsageDetailUsage;
|
|
249
|
+
ratingStatus: UsageRatingStatus;
|
|
250
|
+
charge: UsageDetailCharge | null;
|
|
251
|
+
}
|
|
252
|
+
interface UsageDetailsPage {
|
|
253
|
+
data: UsageDetailRow[];
|
|
254
|
+
nextCursor: string | null;
|
|
255
|
+
}
|
|
256
|
+
declare function validateUsageDetailsQuery(value: unknown): asserts value is UsageDetailsQuery;
|
|
257
|
+
/**
|
|
258
|
+
* Mutually exclusive anomaly buckets; every request lands in at most one,
|
|
259
|
+
* first match wins (settlement_failed > normalization_failed > unpriced >
|
|
260
|
+
* usage_missing > dimension_mismatch). Note that `usage_missing` only covers
|
|
261
|
+
* succeeded requests — failed requests without usage never expected billing —
|
|
262
|
+
* so its count can differ from the summary's `rating.usage_missing`, which
|
|
263
|
+
* has no request-status restriction.
|
|
264
|
+
*/
|
|
265
|
+
declare const USAGE_ANOMALY_CATEGORIES: readonly ["usage_missing", "normalization_failed", "unpriced", "dimension_mismatch", "settlement_failed"];
|
|
266
|
+
type UsageAnomalyCategory = (typeof USAGE_ANOMALY_CATEGORIES)[number];
|
|
267
|
+
interface UsageAnomaliesQuery {
|
|
268
|
+
filters: UsageFilters;
|
|
269
|
+
categories?: UsageAnomalyCategory[];
|
|
270
|
+
/** Page size, 1..200. */
|
|
271
|
+
limit: number;
|
|
272
|
+
cursor?: string;
|
|
273
|
+
}
|
|
274
|
+
interface UsageAnomalyRow {
|
|
275
|
+
category: UsageAnomalyCategory;
|
|
276
|
+
/** Database request id; drill down via the details query. */
|
|
277
|
+
requestId: string;
|
|
278
|
+
requestKey: string;
|
|
279
|
+
receivedAt: string;
|
|
280
|
+
userId: string | null;
|
|
281
|
+
modelId: string;
|
|
282
|
+
modelPublicId: string | null;
|
|
283
|
+
providerId: string | null;
|
|
284
|
+
channelId: string | null;
|
|
285
|
+
upstreamModelId: string | null;
|
|
286
|
+
/** Cause codes, e.g. charge error code or evaluation issue codes. */
|
|
287
|
+
reason: string;
|
|
288
|
+
/**
|
|
289
|
+
* True when the money impact is quantifiable from stored charge amounts
|
|
290
|
+
* (settlement_failed, dimension_mismatch, and billed normalization_failed
|
|
291
|
+
* cases carry a sale amount).
|
|
292
|
+
*/
|
|
293
|
+
amountKnown: boolean;
|
|
294
|
+
}
|
|
295
|
+
interface UsageAnomaliesPage {
|
|
296
|
+
data: UsageAnomalyRow[];
|
|
297
|
+
nextCursor: string | null;
|
|
298
|
+
}
|
|
299
|
+
interface UsageAnomalySummaryQuery {
|
|
300
|
+
filters: UsageFilters;
|
|
301
|
+
/** Optional per-category breakdowns; each adds one grouped aggregate. */
|
|
302
|
+
breakdowns?: Array<"provider" | "channel" | "model">;
|
|
303
|
+
}
|
|
304
|
+
interface UsageAnomalySummaryRow {
|
|
305
|
+
category: UsageAnomalyCategory;
|
|
306
|
+
count: number;
|
|
307
|
+
firstOccurredAt: string;
|
|
308
|
+
lastOccurredAt: string;
|
|
309
|
+
}
|
|
310
|
+
interface UsageAnomalyBreakdownRow {
|
|
311
|
+
category: UsageAnomalyCategory;
|
|
312
|
+
dimension: "provider" | "channel" | "model";
|
|
313
|
+
dimensionId: string | null;
|
|
314
|
+
count: number;
|
|
315
|
+
}
|
|
316
|
+
interface UsageAnomalySummaryPage {
|
|
317
|
+
categories: UsageAnomalySummaryRow[];
|
|
318
|
+
breakdowns: UsageAnomalyBreakdownRow[];
|
|
319
|
+
}
|
|
320
|
+
declare function validateUsageAnomaliesQuery(value: unknown): asserts value is UsageAnomaliesQuery;
|
|
321
|
+
declare function validateUsageAnomalySummaryQuery(value: unknown): asserts value is UsageAnomalySummaryQuery;
|
|
322
|
+
|
|
323
|
+
declare const ADMIN_USER_ROLES: readonly ["admin", "dealer", "user"];
|
|
324
|
+
type AdminUserRole = (typeof ADMIN_USER_ROLES)[number];
|
|
325
|
+
declare const ADMIN_USER_STATUSES: readonly ["active", "banned"];
|
|
326
|
+
type AdminUserStatus = (typeof ADMIN_USER_STATUSES)[number];
|
|
327
|
+
interface AdminUserListQuery {
|
|
328
|
+
/** Matches email, name, or exact user id. */
|
|
329
|
+
query?: string;
|
|
330
|
+
role?: AdminUserRole;
|
|
331
|
+
status?: AdminUserStatus;
|
|
332
|
+
/** Page size, 1..200. */
|
|
333
|
+
limit: number;
|
|
334
|
+
cursor?: string;
|
|
335
|
+
}
|
|
336
|
+
interface AdminUserWalletSummary {
|
|
337
|
+
currency: string;
|
|
338
|
+
balance: MoneyString;
|
|
339
|
+
reservedBalance: MoneyString;
|
|
340
|
+
status: string;
|
|
341
|
+
}
|
|
342
|
+
interface AdminUserSummaryRow {
|
|
343
|
+
userId: string;
|
|
344
|
+
email: string;
|
|
345
|
+
name: string;
|
|
346
|
+
emailVerified: boolean;
|
|
347
|
+
role: string;
|
|
348
|
+
status: string;
|
|
349
|
+
qpsLimit: number;
|
|
350
|
+
createdAt: string;
|
|
351
|
+
/** Non-revoked, unexpired API keys. */
|
|
352
|
+
keyCount: number;
|
|
353
|
+
wallets: AdminUserWalletSummary[];
|
|
354
|
+
lastKeyUsedAt: string | null;
|
|
355
|
+
usageLast30Days: {
|
|
356
|
+
/** Backend snapshot window; absent only on older API versions. */
|
|
357
|
+
windowStart?: string;
|
|
358
|
+
windowEnd?: string;
|
|
359
|
+
requests: number;
|
|
360
|
+
/** Settled sale amounts per currency over the same 30 days. */
|
|
361
|
+
saleByCurrency: Record<string, MoneyString>;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
interface AdminUserKeyRow {
|
|
365
|
+
id: string;
|
|
366
|
+
name: string;
|
|
367
|
+
prefix: string;
|
|
368
|
+
lastFour: string;
|
|
369
|
+
/** Derived: revoked > expired > active. */
|
|
370
|
+
status: "active" | "revoked" | "expired";
|
|
371
|
+
createdAt: string;
|
|
372
|
+
expiresAt: string | null;
|
|
373
|
+
revokedAt: string | null;
|
|
374
|
+
lastUsedAt: string | null;
|
|
375
|
+
rateLimitPerSecond: number | null;
|
|
376
|
+
}
|
|
377
|
+
interface AdminUserDiscountRow {
|
|
378
|
+
id: string;
|
|
379
|
+
modelId: string;
|
|
380
|
+
modelPublicId: string | null;
|
|
381
|
+
operation: string;
|
|
382
|
+
/** Basis points off the public sale price; 2000 = 20% off. */
|
|
383
|
+
discountBps: number;
|
|
384
|
+
status: string;
|
|
385
|
+
effectiveFrom: string;
|
|
386
|
+
effectiveTo: string | null;
|
|
387
|
+
note: string | null;
|
|
388
|
+
}
|
|
389
|
+
interface AdminUserPricingAdjustmentRow {
|
|
390
|
+
id: string;
|
|
391
|
+
/** "user" rules apply to every key of the user; "api_key" rules win over them. */
|
|
392
|
+
subjectType: "user" | "api_key";
|
|
393
|
+
apiKeyId: string | null;
|
|
394
|
+
keyName: string | null;
|
|
395
|
+
keyHint: string | null;
|
|
396
|
+
modelId: string | null;
|
|
397
|
+
modelPublicId: string | null;
|
|
398
|
+
operation: string | null;
|
|
399
|
+
/** Positive decimal multiplier applied to the standard sale price; 1.0000 = unchanged. */
|
|
400
|
+
multiplier: string;
|
|
401
|
+
status: string;
|
|
402
|
+
effectiveFrom: string;
|
|
403
|
+
effectiveTo: string | null;
|
|
404
|
+
note: string | null;
|
|
405
|
+
}
|
|
406
|
+
interface AdminUserDetail extends AdminUserSummaryRow {
|
|
407
|
+
keys: AdminUserKeyRow[];
|
|
408
|
+
discounts: AdminUserDiscountRow[];
|
|
409
|
+
pricingAdjustments: AdminUserPricingAdjustmentRow[];
|
|
410
|
+
}
|
|
411
|
+
interface AdminUserListPage {
|
|
412
|
+
data: AdminUserSummaryRow[];
|
|
413
|
+
/** Present when more users follow; opaque, valid only for the same query. */
|
|
414
|
+
nextCursor: string | null;
|
|
415
|
+
}
|
|
416
|
+
interface AdminUserListCursor {
|
|
417
|
+
createdAt: string;
|
|
418
|
+
userId: string;
|
|
419
|
+
}
|
|
420
|
+
declare function validateAdminUserListQuery(value: unknown): asserts value is AdminUserListQuery;
|
|
421
|
+
declare function encodeAdminUserCursor(cursor: AdminUserListCursor): string;
|
|
422
|
+
declare function parseAdminUserCursor(value: string): AdminUserListCursor | null;
|
|
423
|
+
declare const ADMIN_USER_ACTIVITY_KINDS: readonly ["ledger", "recharge", "hold", "audit"];
|
|
424
|
+
type AdminUserActivityKind = (typeof ADMIN_USER_ACTIVITY_KINDS)[number];
|
|
425
|
+
interface AdminUserActivityRow {
|
|
426
|
+
id: string;
|
|
427
|
+
kind: AdminUserActivityKind;
|
|
428
|
+
occurredAt: string;
|
|
429
|
+
action: string;
|
|
430
|
+
currency: string | null;
|
|
431
|
+
amount: MoneyString | null;
|
|
432
|
+
balanceAfter: MoneyString | null;
|
|
433
|
+
status: string | null;
|
|
434
|
+
referenceId: string | null;
|
|
435
|
+
actorUserId: string | null;
|
|
436
|
+
reason: string | null;
|
|
437
|
+
before: Record<string, unknown> | null;
|
|
438
|
+
after: Record<string, unknown> | null;
|
|
439
|
+
}
|
|
440
|
+
interface AdminUserActivityPage {
|
|
441
|
+
data: AdminUserActivityRow[];
|
|
442
|
+
nextCursor: string | null;
|
|
443
|
+
}
|
|
444
|
+
interface AdminUserWalletOpenInput {
|
|
445
|
+
currency: "CNY" | "USD";
|
|
446
|
+
reason: string;
|
|
447
|
+
}
|
|
448
|
+
interface AdminUserWalletOpenResult {
|
|
449
|
+
walletId: string;
|
|
450
|
+
currency: string;
|
|
451
|
+
created: boolean;
|
|
452
|
+
}
|
|
453
|
+
declare function isMoneyString(value: string): boolean;
|
|
454
|
+
interface AdminUserUpdate {
|
|
455
|
+
role?: AdminUserRole;
|
|
456
|
+
status?: AdminUserStatus;
|
|
457
|
+
qpsLimit?: number;
|
|
458
|
+
/** Required; stored verbatim on the admin audit event. */
|
|
459
|
+
reason: string;
|
|
460
|
+
}
|
|
461
|
+
interface AdminUserUpdateResult {
|
|
462
|
+
userId: string;
|
|
463
|
+
role: string;
|
|
464
|
+
status: string;
|
|
465
|
+
qpsLimit: number;
|
|
466
|
+
updatedAt: string;
|
|
467
|
+
}
|
|
468
|
+
declare function validateAdminUserUpdate(value: unknown): asserts value is AdminUserUpdate;
|
|
469
|
+
interface AdminUserApiKeyUpdate {
|
|
470
|
+
revoked?: boolean;
|
|
471
|
+
/** New per-second rate limit; `null` clears the limit. */
|
|
472
|
+
rateLimitPerSecond?: number | null;
|
|
473
|
+
/** Required; stored verbatim on the admin audit event. */
|
|
474
|
+
reason: string;
|
|
475
|
+
}
|
|
476
|
+
interface AdminUserApiKeyUpdateResult {
|
|
477
|
+
id: string;
|
|
478
|
+
name: string;
|
|
479
|
+
prefix: string;
|
|
480
|
+
lastFour: string;
|
|
481
|
+
status: "active" | "revoked" | "expired";
|
|
482
|
+
rateLimitPerSecond: number | null;
|
|
483
|
+
revokedAt: string | null;
|
|
484
|
+
updatedAt: string;
|
|
485
|
+
}
|
|
486
|
+
declare function validateAdminUserApiKeyUpdate(value: unknown): asserts value is AdminUserApiKeyUpdate;
|
|
487
|
+
interface AdminWalletRechargeInput {
|
|
488
|
+
userId: string;
|
|
489
|
+
/** Single user billing currency: CNY. */
|
|
490
|
+
currency: string;
|
|
491
|
+
/** Positive decimal amount string, at most 8 fraction digits. */
|
|
492
|
+
amount: MoneyString;
|
|
493
|
+
/** External order reference; unique per payment provider "admin". */
|
|
494
|
+
externalOrderId: string;
|
|
495
|
+
/** Required; stored verbatim on the admin audit event. */
|
|
496
|
+
reason: string;
|
|
497
|
+
}
|
|
498
|
+
interface AdminWalletRechargeResult {
|
|
499
|
+
rechargeId: string;
|
|
500
|
+
/** Empty when `created` is false (idempotent retry of a known order). */
|
|
501
|
+
ledgerEntryId: string;
|
|
502
|
+
walletId: string;
|
|
503
|
+
currency: string;
|
|
504
|
+
/** Wallet balance after this operation. */
|
|
505
|
+
balance: MoneyString;
|
|
506
|
+
/** False when the external order was already credited; nothing changed. */
|
|
507
|
+
created: boolean;
|
|
508
|
+
}
|
|
509
|
+
declare function validateAdminWalletRechargeInput(value: unknown): asserts value is AdminWalletRechargeInput;
|
|
510
|
+
|
|
511
|
+
declare const USAGE_FILTER_KINDS: readonly ["model", "user", "apiKey", "provider", "channel", "operation"];
|
|
512
|
+
type UsageFilterKind = (typeof USAGE_FILTER_KINDS)[number];
|
|
513
|
+
interface UsageFilterOption {
|
|
514
|
+
id: string;
|
|
515
|
+
label: string;
|
|
516
|
+
description: string;
|
|
517
|
+
}
|
|
518
|
+
interface UsageFilterOptionsPage {
|
|
519
|
+
data: UsageFilterOption[];
|
|
520
|
+
nextCursor: string | null;
|
|
521
|
+
}
|
|
522
|
+
interface UsageFilterOptionsQuery {
|
|
523
|
+
limit: number;
|
|
524
|
+
query?: string;
|
|
525
|
+
cursor?: string;
|
|
526
|
+
ids?: string[];
|
|
527
|
+
}
|
|
528
|
+
declare function encodeUsageFilterCursor(kind: UsageFilterKind, query: string, id: string): string;
|
|
529
|
+
declare function parseUsageFilterCursor(value: string, kind: UsageFilterKind, query: string): string | null;
|
|
530
|
+
declare function validateUsageFilterOptionsQuery(kind: UsageFilterKind, value: unknown): asserts value is UsageFilterOptionsQuery;
|
|
531
|
+
|
|
532
|
+
declare const BILLING_CURRENCY = "CNY";
|
|
533
|
+
declare const WALLET_MAX_BALANCE_UNITS = 99999999999999999999n;
|
|
534
|
+
declare function moneyToUnits(value: string): bigint;
|
|
535
|
+
declare function moneyFromUnits(value: bigint): string;
|
|
536
|
+
declare function multiplyMoney(value: string, multiplier: string, ...additionalMultipliers: string[]): string;
|
|
537
|
+
|
|
538
|
+
interface ApiErrorPayload {
|
|
539
|
+
error: {
|
|
540
|
+
code: string;
|
|
541
|
+
message: string;
|
|
542
|
+
category?: string;
|
|
543
|
+
retryable?: boolean;
|
|
544
|
+
requestId?: string;
|
|
545
|
+
details?: JsonObject;
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** Upgrade old DB snapshots at the read boundary; authored fields carry their own annotations. */
|
|
550
|
+
declare function normalizeModelParameterSchema(source: Readonly<JsonObject>): JsonObject;
|
|
551
|
+
declare function modelInputDefaults(input: JsonObject): JsonObject;
|
|
552
|
+
declare function orderedSchemaProperties(schema: JsonObject): [string, JsonValue][];
|
|
553
|
+
/** Compatibility projection for existing schema API clients, never a second authoring source. */
|
|
554
|
+
declare function modelInputUi(input: JsonObject): JsonObject;
|
|
555
|
+
|
|
556
|
+
declare const TASK_STATUSES: readonly ["queued", "running", "succeeded", "failed", "cancelling", "cancelled"];
|
|
557
|
+
type TaskStatus = (typeof TASK_STATUSES)[number];
|
|
558
|
+
type TerminalTaskStatus = "succeeded" | "failed" | "cancelled";
|
|
559
|
+
interface TaskProgress {
|
|
560
|
+
percent?: number;
|
|
561
|
+
stage?: string;
|
|
562
|
+
message?: string;
|
|
563
|
+
}
|
|
564
|
+
interface TaskError {
|
|
565
|
+
code: string;
|
|
566
|
+
message: string;
|
|
567
|
+
category?: string;
|
|
568
|
+
retryable?: boolean;
|
|
569
|
+
details?: JsonObject;
|
|
570
|
+
}
|
|
571
|
+
interface TaskUsage {
|
|
572
|
+
components: Array<{
|
|
573
|
+
name: string;
|
|
574
|
+
quantity: number;
|
|
575
|
+
unit: string;
|
|
576
|
+
}>;
|
|
577
|
+
metadata?: JsonObject;
|
|
578
|
+
}
|
|
579
|
+
interface TaskCost {
|
|
580
|
+
amount: string;
|
|
581
|
+
currency: string;
|
|
582
|
+
}
|
|
583
|
+
interface TaskTiming {
|
|
584
|
+
submittedAt: string;
|
|
585
|
+
providerSubmittedAt?: string;
|
|
586
|
+
providerCompletedAt?: string;
|
|
587
|
+
storedAt?: string;
|
|
588
|
+
preparationMs: number | null;
|
|
589
|
+
generationMs: number | null;
|
|
590
|
+
storageMs: number | null;
|
|
591
|
+
totalMs: number | null;
|
|
592
|
+
startSource: "client" | "server";
|
|
593
|
+
}
|
|
594
|
+
/** Repository/console read model. HTTP clients receive TaskReceipt or TaskResult. */
|
|
595
|
+
interface Task<TOutput = JsonValue> {
|
|
596
|
+
id: string;
|
|
597
|
+
/** Original platform request ID, shared with request history. */
|
|
598
|
+
requestId?: string;
|
|
599
|
+
/** Public Run ID, when this Task belongs to a shared-input run. */
|
|
600
|
+
runId?: string;
|
|
601
|
+
model: string;
|
|
602
|
+
operation: string;
|
|
603
|
+
schemaVersion: number;
|
|
604
|
+
/** Model request parameters; native-managed tasks retain the upstream field structure. */
|
|
605
|
+
input?: JsonObject;
|
|
606
|
+
status: TaskStatus;
|
|
607
|
+
/** Regional media availability; execution/billing remain terminal while replicas prepare. */
|
|
608
|
+
deliveryStatus?: "preparing" | "ready";
|
|
609
|
+
progress?: TaskProgress;
|
|
610
|
+
/** Native-managed tasks preserve the final response shape and media URLs; catalog models may normalize model identifiers. */
|
|
611
|
+
output?: TOutput;
|
|
612
|
+
assets: MediaAsset[];
|
|
613
|
+
error?: TaskError;
|
|
614
|
+
usage?: TaskUsage;
|
|
615
|
+
cost?: TaskCost;
|
|
616
|
+
/** Customer billing state; absent on older servers. */
|
|
617
|
+
billingStatus?: "pending" | "succeeded" | "failed" | "refunded" | "unavailable";
|
|
618
|
+
/** Final customer sale settlement. Provider procurement cost is never exposed here. */
|
|
619
|
+
settlement?: NexraSettlement;
|
|
620
|
+
/** Caller-supplied business data, returned unchanged; never sent to the provider. */
|
|
621
|
+
metadata?: JsonObject;
|
|
622
|
+
timing?: TaskTiming;
|
|
623
|
+
/** Server-side Task record creation time (ISO 8601 UTC). */
|
|
624
|
+
createdAt: string;
|
|
625
|
+
/** Latest Task record update, not the generation completion time (ISO 8601 UTC). */
|
|
626
|
+
updatedAt: string;
|
|
627
|
+
/** First worker execution start; absent while queued or cancelled before execution. */
|
|
628
|
+
startedAt?: string;
|
|
629
|
+
/** Terminal succeeded/failed/cancelled time; success follows required asset storage. */
|
|
630
|
+
completedAt?: string;
|
|
631
|
+
/** @deprecated Reserved; no Task expiry policy is currently enforced. Not a media URL expiry. */
|
|
632
|
+
expiresAt?: string;
|
|
633
|
+
}
|
|
634
|
+
/** POST /tasks returns acceptance only, including for idempotent replays. */
|
|
635
|
+
type TaskReceipt = Pick<Task, "id" | "status">;
|
|
636
|
+
/** Public Task result; platform diagnostics and business tags live in RequestDetails. */
|
|
637
|
+
type TaskResult<TOutput = JsonValue> = Pick<Task<TOutput>, "id" | "model" | "status"> & Partial<Pick<Task<TOutput>, "requestId" | "output" | "assets" | "error" | "deliveryStatus" | "settlement">>;
|
|
638
|
+
/** Platform request details, used by both managed Tasks and native proxy requests. */
|
|
639
|
+
interface RequestDetails {
|
|
640
|
+
id: string;
|
|
641
|
+
requestId: string;
|
|
642
|
+
taskId: string | null;
|
|
643
|
+
method: string;
|
|
644
|
+
path: string;
|
|
645
|
+
protocol?: string;
|
|
646
|
+
accessMode?: string | null;
|
|
647
|
+
model: string | null;
|
|
648
|
+
operation: string | null;
|
|
649
|
+
status: string;
|
|
650
|
+
httpStatus: number | null;
|
|
651
|
+
errorCode: string | null;
|
|
652
|
+
/** HTTP duration, never substituted with asynchronous task duration. */
|
|
653
|
+
durationMs: number | null;
|
|
654
|
+
timing?: TaskTiming;
|
|
655
|
+
cost?: TaskCost;
|
|
656
|
+
billingStatus?: Task["billingStatus"];
|
|
657
|
+
settlement?: NexraSettlement;
|
|
658
|
+
metadata?: JsonObject;
|
|
659
|
+
/** Latest known execution update; omitted when not observed. */
|
|
660
|
+
updatedAt?: string;
|
|
661
|
+
runId?: string;
|
|
662
|
+
schemaVersion?: number;
|
|
663
|
+
createdAt?: string;
|
|
664
|
+
startedAt?: string;
|
|
665
|
+
completedAt?: string;
|
|
666
|
+
input: JsonObject | null;
|
|
667
|
+
receivedAt: string;
|
|
668
|
+
finishedAt: string | null;
|
|
669
|
+
}
|
|
670
|
+
declare function taskReceipt(task: TaskReceipt): TaskReceipt;
|
|
671
|
+
declare function taskResult<TOutput>(task: Task<TOutput>): TaskResult<TOutput>;
|
|
672
|
+
type TaskEventType = "state" | "progress" | "preview" | "log" | "usage" | "warning" | "result";
|
|
673
|
+
interface TaskEvent {
|
|
674
|
+
id: string;
|
|
675
|
+
taskId: string;
|
|
676
|
+
sequence: number;
|
|
677
|
+
type: TaskEventType;
|
|
678
|
+
status?: TaskStatus;
|
|
679
|
+
progress?: TaskProgress;
|
|
680
|
+
asset?: MediaAsset;
|
|
681
|
+
message?: string;
|
|
682
|
+
payload?: JsonObject;
|
|
683
|
+
occurredAt: string;
|
|
684
|
+
}
|
|
685
|
+
/** @deprecated Use CreateTaskRequest.callback_url. Kept for existing callers. */
|
|
686
|
+
interface TaskWebhookConfig {
|
|
687
|
+
url: string;
|
|
688
|
+
/** Shared HMAC secret used to verify Nexra callback signatures. */
|
|
689
|
+
secret: string;
|
|
690
|
+
events?: Array<"completed">;
|
|
691
|
+
}
|
|
692
|
+
interface CreateTaskRequest<TInput = Record<string, unknown>> {
|
|
693
|
+
/** @internal Console telemetry only: browser send time before uploads, not execution time. */
|
|
694
|
+
submittedAt?: string;
|
|
695
|
+
model: string;
|
|
696
|
+
input: TInput;
|
|
697
|
+
/** Signed Nexra quote used to lock this input to a sale-price revision. */
|
|
698
|
+
quoteToken?: string;
|
|
699
|
+
/** Optional business identifiers such as orderId, available in request details. Do not include secrets. */
|
|
700
|
+
metadata?: JsonObject;
|
|
701
|
+
/** Platform completion callback, independent of provider callback support. Never sent upstream. */
|
|
702
|
+
callback_url?: string;
|
|
703
|
+
/** @deprecated Use callback_url; do not supply both. */
|
|
704
|
+
webhook?: TaskWebhookConfig;
|
|
705
|
+
/** @deprecated Compatibility check only; the server resolves the current contract. */
|
|
706
|
+
schemaVersion?: number;
|
|
707
|
+
}
|
|
708
|
+
/** One user input fanned out to independent durable model Tasks. */
|
|
709
|
+
interface TaskRun<TOutput = JsonValue> {
|
|
710
|
+
id: string;
|
|
711
|
+
inputMode: string;
|
|
712
|
+
input: JsonObject;
|
|
713
|
+
models: string[];
|
|
714
|
+
repetitions: number;
|
|
715
|
+
tasks: Task<TOutput>[];
|
|
716
|
+
metadata?: JsonObject;
|
|
717
|
+
createdAt: string;
|
|
718
|
+
updatedAt: string;
|
|
719
|
+
}
|
|
720
|
+
interface CreateTaskRunRequest<TInput = Record<string, unknown>> {
|
|
721
|
+
submittedAt?: string;
|
|
722
|
+
models: string[];
|
|
723
|
+
repetitions?: number;
|
|
724
|
+
inputMode: string;
|
|
725
|
+
input: TInput;
|
|
726
|
+
metadata?: JsonObject;
|
|
727
|
+
}
|
|
728
|
+
interface TaskRunListParams {
|
|
729
|
+
status?: TaskStatus;
|
|
730
|
+
model?: string;
|
|
731
|
+
limit?: number;
|
|
732
|
+
cursor?: string;
|
|
733
|
+
}
|
|
734
|
+
interface TaskListParams {
|
|
735
|
+
status?: TaskStatus;
|
|
736
|
+
model?: string;
|
|
737
|
+
limit?: number;
|
|
738
|
+
cursor?: string;
|
|
739
|
+
}
|
|
740
|
+
type TaskPage<TOutput = JsonValue> = CursorPage<Task<TOutput>>;
|
|
741
|
+
interface RunResult<TOutput = JsonValue> {
|
|
742
|
+
taskId: string;
|
|
743
|
+
output: TOutput;
|
|
744
|
+
assets: MediaAsset[];
|
|
745
|
+
usage?: TaskUsage;
|
|
746
|
+
cost?: TaskCost;
|
|
747
|
+
task: TaskResult<TOutput>;
|
|
748
|
+
}
|
|
749
|
+
declare function isTerminalTaskStatus(status: TaskStatus): status is TerminalTaskStatus;
|
|
750
|
+
|
|
751
|
+
type ObservationResult = "success" | "failure" | "excluded" | "rate_limited" | "restricted";
|
|
752
|
+
type AvailabilityBucket = {
|
|
753
|
+
start: string;
|
|
754
|
+
end: string;
|
|
755
|
+
state: "success" | "failure" | "mixed" | "unknown";
|
|
756
|
+
evidence: "measured" | "carried" | "expired" | "none";
|
|
757
|
+
businessSuccess: number;
|
|
758
|
+
businessFailure: number;
|
|
759
|
+
probeSuccess: number;
|
|
760
|
+
probeFailure: number;
|
|
761
|
+
latestAt: string | null;
|
|
762
|
+
coreSuccess: number;
|
|
763
|
+
coreFailure: number;
|
|
764
|
+
expectedSamples: number | null;
|
|
765
|
+
incomplete: boolean;
|
|
766
|
+
};
|
|
767
|
+
type AvailabilityObservation = {
|
|
768
|
+
at: string;
|
|
769
|
+
result: ObservationResult;
|
|
770
|
+
source: "business" | "probe" | "core";
|
|
771
|
+
count?: number;
|
|
772
|
+
};
|
|
773
|
+
type AvailabilityStats = {
|
|
774
|
+
success: number;
|
|
775
|
+
failure: number;
|
|
776
|
+
excluded: number;
|
|
777
|
+
rateLimited: number;
|
|
778
|
+
restricted: number;
|
|
779
|
+
rate: number | null;
|
|
780
|
+
};
|
|
781
|
+
type ProbeTargetConfig = {
|
|
782
|
+
routeId: string;
|
|
783
|
+
enabled: boolean;
|
|
784
|
+
intervalSeconds: number;
|
|
785
|
+
timeoutSeconds: number;
|
|
786
|
+
templateVersion: number;
|
|
787
|
+
input: JsonObject;
|
|
788
|
+
maxUsage?: JsonObject | null;
|
|
789
|
+
currency: string;
|
|
790
|
+
maxCost: string;
|
|
791
|
+
};
|
|
792
|
+
type ProbeRunView = {
|
|
793
|
+
id: string;
|
|
794
|
+
targetId: string;
|
|
795
|
+
status: string;
|
|
796
|
+
startedAt: string | null;
|
|
797
|
+
finishedAt: string | null;
|
|
798
|
+
scheduledAt: string;
|
|
799
|
+
upstreamTaskId: string | null;
|
|
800
|
+
errorCode: string | null;
|
|
801
|
+
stage: string | null;
|
|
802
|
+
durationMs: number | null;
|
|
803
|
+
currency: string;
|
|
804
|
+
reservedCost: string;
|
|
805
|
+
actualCost: string | null;
|
|
806
|
+
costStatus: string;
|
|
807
|
+
};
|
|
808
|
+
type ProbeTargetView = {
|
|
809
|
+
id: string;
|
|
810
|
+
routeId: string;
|
|
811
|
+
channelId: string;
|
|
812
|
+
channelName: string;
|
|
813
|
+
model: string;
|
|
814
|
+
kind: string;
|
|
815
|
+
protocol: string;
|
|
816
|
+
enabled: boolean;
|
|
817
|
+
readiness: string;
|
|
818
|
+
intervalSeconds: number;
|
|
819
|
+
timeoutSeconds: number;
|
|
820
|
+
templateVersion: number;
|
|
821
|
+
input: JsonObject;
|
|
822
|
+
maxUsage?: JsonObject | null;
|
|
823
|
+
currency: string | null;
|
|
824
|
+
maxCost: string | null;
|
|
825
|
+
nextAt: string | null;
|
|
826
|
+
business: AvailabilityStats;
|
|
827
|
+
probes: AvailabilityStats;
|
|
828
|
+
buckets: AvailabilityBucket[];
|
|
829
|
+
latestRun: ProbeRunView | null;
|
|
830
|
+
};
|
|
831
|
+
type AdminOverview = {
|
|
832
|
+
generatedAt: string;
|
|
833
|
+
window: {
|
|
834
|
+
start: string;
|
|
835
|
+
end: string;
|
|
836
|
+
hours: number;
|
|
837
|
+
};
|
|
838
|
+
complete: boolean;
|
|
839
|
+
summary: {
|
|
840
|
+
models: number;
|
|
841
|
+
channels: number;
|
|
842
|
+
tasks24h: number;
|
|
843
|
+
tasksSucceeded24h: number;
|
|
844
|
+
tasksFailed24h: number;
|
|
845
|
+
tasksCancelled24h: number;
|
|
846
|
+
taskSuccessRate: number | null;
|
|
847
|
+
requests5m: number;
|
|
848
|
+
errors5m: number;
|
|
849
|
+
qps: number;
|
|
850
|
+
p95Ms: number | null;
|
|
851
|
+
p99Ms: number | null;
|
|
852
|
+
latencySamples: number;
|
|
853
|
+
requestSuccessRate: number | null;
|
|
854
|
+
requestSamples: number;
|
|
855
|
+
};
|
|
856
|
+
callbacks: {
|
|
857
|
+
pending: number;
|
|
858
|
+
retrying: number;
|
|
859
|
+
failed: number;
|
|
860
|
+
delivered24h: number;
|
|
861
|
+
};
|
|
862
|
+
core: {
|
|
863
|
+
id: string;
|
|
864
|
+
name: string;
|
|
865
|
+
buckets: AvailabilityBucket[];
|
|
866
|
+
latestAt: string | null;
|
|
867
|
+
}[];
|
|
868
|
+
requests: {
|
|
869
|
+
id: string;
|
|
870
|
+
model: string | null;
|
|
871
|
+
path: string;
|
|
872
|
+
status: string;
|
|
873
|
+
httpStatus: number | null;
|
|
874
|
+
durationMs: number | null;
|
|
875
|
+
at: string;
|
|
876
|
+
taskId?: string | null;
|
|
877
|
+
taskDurationMs?: number | null;
|
|
878
|
+
taskStatus?: string | null;
|
|
879
|
+
taskSubmittedAt?: string | null;
|
|
880
|
+
taskCreatedAt?: string | null;
|
|
881
|
+
}[];
|
|
882
|
+
tasks: {
|
|
883
|
+
id: string;
|
|
884
|
+
model: string;
|
|
885
|
+
status: string;
|
|
886
|
+
phase: string | null;
|
|
887
|
+
startedAt: string | null;
|
|
888
|
+
createdAt: string;
|
|
889
|
+
submittedAt?: string | null;
|
|
890
|
+
}[];
|
|
891
|
+
targets: ProbeTargetView[];
|
|
892
|
+
budgets: {
|
|
893
|
+
currency: string;
|
|
894
|
+
dailyLimit: string;
|
|
895
|
+
reserved: string;
|
|
896
|
+
settled: string;
|
|
897
|
+
}[];
|
|
898
|
+
};
|
|
899
|
+
declare function defaultProbeInterval(kind: string, model: string): number;
|
|
900
|
+
declare function defaultProbeTimeout(kind: string): number;
|
|
901
|
+
declare function classifyObservation(status: string, httpStatus: number | null, code?: string): ObservationResult;
|
|
902
|
+
declare function availabilityStats(items: readonly AvailabilityObservation[]): AvailabilityStats;
|
|
903
|
+
/** Buckets carry evidence forward only. Carried states never create observations. */
|
|
904
|
+
declare function availabilityBuckets(items: readonly AvailabilityObservation[], end: Date, hours: number, intervalSeconds: number, core?: boolean): AvailabilityBucket[];
|
|
905
|
+
/** Missing primary meters are unknown, not zero. Optional cache/tool meters need not occur. */
|
|
906
|
+
declare function rateProbeUsage(price: unknown, usage: JsonObject | undefined): string | undefined;
|
|
907
|
+
declare function probeCostExceeds(actual: string, limit: string): boolean;
|
|
908
|
+
|
|
909
|
+
declare class AssetsClient {
|
|
910
|
+
private readonly transport;
|
|
911
|
+
constructor(transport: HttpTransport);
|
|
912
|
+
upload(file: Blob, options?: AssetUploadOptions): Promise<MediaAsset>;
|
|
913
|
+
import(request: AssetImportRequest, signal?: AbortSignal): Promise<MediaAsset>;
|
|
914
|
+
get(assetId: string, signal?: AbortSignal): Promise<MediaAsset>;
|
|
915
|
+
download(asset: MediaAsset | string, signal?: AbortSignal): Promise<Response>;
|
|
916
|
+
stream(asset: MediaAsset | string, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
declare class ModelsClient {
|
|
920
|
+
private readonly transport;
|
|
921
|
+
constructor(transport: HttpTransport);
|
|
922
|
+
search(params?: ModelSearchParams, signal?: AbortSignal): Promise<CursorPage<TaskModelSummary>>;
|
|
923
|
+
get(model: string, signal?: AbortSignal): Promise<TaskModel>;
|
|
924
|
+
schema(model: string, signal?: AbortSignal): Promise<ModelSchema>;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
interface CreateTaskOptions<TInput = Record<string, unknown>> {
|
|
928
|
+
input: TInput;
|
|
929
|
+
quoteToken?: string;
|
|
930
|
+
submittedAt?: string;
|
|
931
|
+
metadata?: JsonObject;
|
|
932
|
+
callback_url?: string;
|
|
933
|
+
/** @deprecated Use callback_url; do not supply both. */
|
|
934
|
+
webhook?: TaskWebhookConfig;
|
|
935
|
+
schemaVersion?: number;
|
|
936
|
+
idempotencyKey?: string;
|
|
937
|
+
signal?: AbortSignal;
|
|
938
|
+
}
|
|
939
|
+
interface WatchTaskOptions {
|
|
940
|
+
signal?: AbortSignal;
|
|
941
|
+
lastEventId?: string;
|
|
942
|
+
maxReconnects?: number;
|
|
943
|
+
}
|
|
944
|
+
interface WaitTaskOptions extends WatchTaskOptions {
|
|
945
|
+
timeoutMs?: number;
|
|
946
|
+
pollIntervalMs?: number;
|
|
947
|
+
onEvent?: (event: TaskEvent) => void | Promise<void>;
|
|
948
|
+
}
|
|
949
|
+
interface RunTaskOptions<TInput = Record<string, unknown>> extends CreateTaskOptions<TInput>, WaitTaskOptions {
|
|
950
|
+
cancelOnAbort?: boolean;
|
|
951
|
+
}
|
|
952
|
+
declare class TasksClient {
|
|
953
|
+
private readonly transport;
|
|
954
|
+
private readonly assets;
|
|
955
|
+
constructor(transport: HttpTransport, assets: AssetsClient);
|
|
956
|
+
create<TOutput = JsonValue, TInput = Record<string, unknown>>(model: string, options: CreateTaskOptions<TInput>): Promise<TaskReceipt>;
|
|
957
|
+
get<TOutput = JsonValue>(taskId: string, signal?: AbortSignal): Promise<TaskResult<TOutput>>;
|
|
958
|
+
list<TOutput = JsonValue>(params?: TaskListParams, signal?: AbortSignal): Promise<CursorPage<TaskResult<TOutput>>>;
|
|
959
|
+
cancel<TOutput = JsonValue>(taskId: string, signal?: AbortSignal): Promise<TaskReceipt>;
|
|
960
|
+
watch(taskId: string, options?: WatchTaskOptions): AsyncGenerator<TaskEvent>;
|
|
961
|
+
wait<TOutput = JsonValue>(taskId: string, options?: WaitTaskOptions): Promise<TaskResult<TOutput>>;
|
|
962
|
+
run<TOutput = JsonValue, TInput = Record<string, unknown>>(model: string, options: RunTaskOptions<TInput>): Promise<RunResult<TOutput>>;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
declare class NexraClient {
|
|
966
|
+
readonly assets: AssetsClient;
|
|
967
|
+
readonly catalog: CatalogClient;
|
|
968
|
+
readonly models: ModelsClient;
|
|
969
|
+
readonly tasks: TasksClient;
|
|
970
|
+
constructor(options?: NexraClientOptions);
|
|
971
|
+
run<TOutput = JsonValue, TInput = Record<string, unknown>>(model: string, options: RunTaskOptions<TInput>): Promise<RunResult<TOutput>>;
|
|
972
|
+
}
|
|
973
|
+
declare function createNexra(options?: NexraClientOptions): NexraClient;
|
|
974
|
+
|
|
975
|
+
declare class NexraApiError extends Error {
|
|
976
|
+
readonly status: number;
|
|
977
|
+
readonly code: string;
|
|
978
|
+
readonly requestId?: string;
|
|
979
|
+
readonly retryable: boolean;
|
|
980
|
+
readonly details?: ApiErrorPayload["error"]["details"];
|
|
981
|
+
constructor(message: string, options: {
|
|
982
|
+
status: number;
|
|
983
|
+
code?: string;
|
|
984
|
+
requestId?: string;
|
|
985
|
+
retryable?: boolean;
|
|
986
|
+
details?: ApiErrorPayload["error"]["details"];
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
declare class NexraTaskError extends Error {
|
|
990
|
+
readonly task: TaskResult<unknown>;
|
|
991
|
+
constructor(task: TaskResult<unknown>);
|
|
992
|
+
}
|
|
993
|
+
declare class NexraWaitTimeoutError extends Error {
|
|
994
|
+
readonly taskId: string;
|
|
995
|
+
readonly timeoutMs: number;
|
|
996
|
+
constructor(taskId: string, timeoutMs: number);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
interface VerifyWebhookOptions {
|
|
1000
|
+
toleranceSeconds?: number;
|
|
1001
|
+
now?: Date;
|
|
1002
|
+
}
|
|
1003
|
+
/** @deprecated Only verifies legacy signed webhooks, not callback_url notifications. */
|
|
1004
|
+
declare function verifyWebhook(request: Request, secret: string, options?: VerifyWebhookOptions): Promise<boolean>;
|
|
1005
|
+
|
|
1006
|
+
export { ADMIN_USER_ACTIVITY_KINDS, ADMIN_USER_ROLES, ADMIN_USER_STATUSES, type AdminOverview, type AdminUserActivityKind, type AdminUserActivityPage, type AdminUserActivityRow, type AdminUserApiKeyUpdate, type AdminUserApiKeyUpdateResult, type AdminUserDetail, type AdminUserDiscountRow, type AdminUserKeyRow, type AdminUserListCursor, type AdminUserListPage, type AdminUserListQuery, type AdminUserPricingAdjustmentRow, type AdminUserRole, type AdminUserStatus, type AdminUserSummaryRow, type AdminUserUpdate, type AdminUserUpdateResult, type AdminUserWalletOpenInput, type AdminUserWalletOpenResult, type AdminUserWalletSummary, type AdminWalletRechargeInput, type AdminWalletRechargeResult, type ApiErrorPayload, type AssetImportRequest, type AssetInput, type AssetReference, type AssetUploadOptions, AssetsClient, type AvailabilityBucket, type AvailabilityObservation, type AvailabilityStats, BILLING_CURRENCY, BillingMetric, CatalogClient, type CreateTaskOptions, type CreateTaskRequest, type CreateTaskRunRequest, CursorPage, HttpTransport, JsonObject, JsonValue, MEDIA_KINDS, MONEY_STRING_PATTERN, type MediaAsset, type MediaAssetStatus, type MediaKind, ModelSchema, ModelSearchParams, ModelsClient, type MoneyString, NexraApiError, NexraClient, NexraClientOptions, NexraSettlement, NexraTaskError, NexraWaitTimeoutError, type ObservationResult, type ProbeRunView, type ProbeTargetConfig, type ProbeTargetView, type RequestDetails, type RunResult, type RunTaskOptions, TASK_STATUSES, TOKEN_METRICS, type Task, type TaskCost, type TaskError, type TaskEvent, type TaskEventType, type TaskListParams, TaskModel, TaskModelSummary, type TaskPage, type TaskProgress, type TaskReceipt, type TaskResult, type TaskRun, type TaskRunListParams, type TaskStatus, type TaskTiming, type TaskUsage, type TaskWebhookConfig, TasksClient, type TerminalTaskStatus, USAGE_AMOUNT_KINDS, USAGE_ANOMALY_CATEGORIES, USAGE_FILTER_KINDS, USAGE_FILTER_SELECTION_LIMIT, USAGE_GROUP_BYS, USAGE_NORMALIZATION_STATUSES, USAGE_RATING_STATUSES, USAGE_SOURCES, type UploadDeliveryRegion, type UsageAmountKind, type UsageAnomaliesPage, type UsageAnomaliesQuery, type UsageAnomalyBreakdownRow, type UsageAnomalyCategory, type UsageAnomalyRow, type UsageAnomalySummaryPage, type UsageAnomalySummaryQuery, type UsageAnomalySummaryRow, type UsageDetailCharge, type UsageDetailRow, type UsageDetailUsage, type UsageDetailsPage, type UsageDetailsQuery, type UsageFilterKind, type UsageFilterOption, type UsageFilterOptionsPage, type UsageFilterOptionsQuery, type UsageFilters, type UsageGroupBy, type UsageNormalizationStatus, type UsageRatingStatus, type UsageSource, type UsageSummaryAmount, type UsageSummaryGroup, type UsageSummaryPage, type UsageSummaryQuery, type UsageSummaryRow, type UsageTimeWindow, type VerifyWebhookOptions, WALLET_MAX_BALANCE_UNITS, type WaitTaskOptions, type WatchTaskOptions, availabilityBuckets, availabilityStats, classifyObservation, createNexra, defaultProbeInterval, defaultProbeTimeout, encodeAdminUserCursor, encodeUsageFilterCursor, encodeUsageKeysetCursor, encodeUsageSummaryCursor, isMoneyString, isTerminalTaskStatus, modelInputDefaults, modelInputUi, modelUploadRegion, moneyFromUnits, moneyToUnits, multiplyMoney, normalizeModelParameterSchema, orderedSchemaProperties, parseAdminUserCursor, parseUsageFilterCursor, parseUsageKeysetCursor, parseUsageSummaryCursor, probeCostExceeds, rateProbeUsage, taskReceipt, taskResult, uploadedMediaInput, uploadedMediaUrl, validateAdminUserApiKeyUpdate, validateAdminUserListQuery, validateAdminUserUpdate, validateAdminWalletRechargeInput, validateUsageAnomaliesQuery, validateUsageAnomalySummaryQuery, validateUsageDetailsQuery, validateUsageFilterOptionsQuery, validateUsageFilters, validateUsageSummaryQuery, verifyWebhook };
|