@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/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @byte_fluffy/nexra-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Nexra Task API. It includes task execution, model discovery,
|
|
4
|
+
asset upload/download, webhook verification, authoritative catalog quotes, and the
|
|
5
|
+
browser-safe public model catalog.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @byte_fluffy/nexra-sdk@next
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createNexra, getModelSpec } from "@byte_fluffy/nexra-sdk";
|
|
13
|
+
|
|
14
|
+
const nexra = createNexra({ apiKey: process.env.NEXRA_API_KEY });
|
|
15
|
+
const spec = getModelSpec("gpt-image-2");
|
|
16
|
+
const input = {
|
|
17
|
+
model: spec!.id,
|
|
18
|
+
prompt: "A paper boat on a blue table",
|
|
19
|
+
size: "1024x1024",
|
|
20
|
+
quality: "medium",
|
|
21
|
+
};
|
|
22
|
+
const quote = await nexra.catalog.quote({
|
|
23
|
+
modelId: spec!.id,
|
|
24
|
+
operation: "image.generate",
|
|
25
|
+
input,
|
|
26
|
+
});
|
|
27
|
+
const result = await nexra.run(spec!.id, { input, quoteToken: quote.quoteToken });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The default API base URL is `https://api.nexra-ai.com/v1`. When overriding
|
|
31
|
+
`baseUrl`, include the `/v1` API prefix.
|
|
32
|
+
|
|
33
|
+
Static catalog APIs are also available from `@byte_fluffy/nexra-sdk/catalog`.
|
|
34
|
+
Exact non-negative decimal helpers are available from
|
|
35
|
+
`@byte_fluffy/nexra-sdk/decimal`.
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
interface CursorPage<T> {
|
|
7
|
+
data: T[];
|
|
8
|
+
nextCursor?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const BILLING_METRICS: readonly ["requests", "input_tokens", "cached_input_tokens", "cache_write_tokens", "cache_creation_5m_input_tokens", "cache_creation_1h_input_tokens", "cache_read_input_tokens", "output_tokens", "input_characters", "input_utf8_bytes", "input_images", "output_images", "input_audio_seconds", "output_audio_seconds", "input_video_seconds", "output_video_seconds", "provider_credits", "web_search_requests"];
|
|
12
|
+
type BillingMetric = (typeof BILLING_METRICS)[number];
|
|
13
|
+
declare const BILLING_EXPORT_DIMENSIONS: readonly ["resolution", "duration", "layer_decomposition", "with_audio", "has_input_video", "hd", "prompt_extend", "modality", "tier", "quality", "image_count", "input_token_tier", "input_modality", "service_tier", "inference_geo", "speed", "region_scope", "has_reference_image", "mode"];
|
|
14
|
+
type UsageComponentEvidence = {
|
|
15
|
+
source: "provider_native" | "request_derived" | "response_derived" | "tariff_equivalent" | "unknown";
|
|
16
|
+
paths?: string[];
|
|
17
|
+
calculation?: string;
|
|
18
|
+
};
|
|
19
|
+
interface MeteredUsageComponent {
|
|
20
|
+
metric: BillingMetric;
|
|
21
|
+
quantity: number;
|
|
22
|
+
dimensions?: Record<string, JsonPrimitive>;
|
|
23
|
+
evidence?: UsageComponentEvidence;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Provider evidence is normalized into independent metered components instead
|
|
27
|
+
* of one canonical model response. This keeps protocol conversion separate
|
|
28
|
+
* from billing and allows one request to carry differently-dimensioned usage.
|
|
29
|
+
*/
|
|
30
|
+
interface NormalizedUsageV1 {
|
|
31
|
+
schemaVersion: 1;
|
|
32
|
+
components: MeteredUsageComponent[];
|
|
33
|
+
billingEvidenceComplete?: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface MeteredPriceRate {
|
|
36
|
+
metric: BillingMetric;
|
|
37
|
+
unitSize: number;
|
|
38
|
+
unitPrice: string;
|
|
39
|
+
rounding: "proportional" | "ceil";
|
|
40
|
+
includedQuantity?: number;
|
|
41
|
+
dimensions?: Record<string, JsonPrimitive>;
|
|
42
|
+
}
|
|
43
|
+
interface MeteredPriceRuleV1 {
|
|
44
|
+
schemaVersion: 1;
|
|
45
|
+
type: "metered";
|
|
46
|
+
rates: MeteredPriceRate[];
|
|
47
|
+
}
|
|
48
|
+
type PriceRule = MeteredPriceRuleV1;
|
|
49
|
+
interface PriceEvaluationLine {
|
|
50
|
+
evidence?: UsageComponentEvidence;
|
|
51
|
+
metric: BillingMetric;
|
|
52
|
+
quantity: number;
|
|
53
|
+
unitSize: number;
|
|
54
|
+
unitPrice: string;
|
|
55
|
+
rounding: "proportional" | "ceil";
|
|
56
|
+
includedQuantity: number;
|
|
57
|
+
dimensions?: Record<string, JsonPrimitive>;
|
|
58
|
+
amount: string;
|
|
59
|
+
discountedAmount?: string;
|
|
60
|
+
}
|
|
61
|
+
/** Preserve frozen row order when distributing the eight-decimal remainder. */
|
|
62
|
+
declare function allocateDiscountedPriceLines(lines: readonly PriceEvaluationLine[], saleAmount: string): PriceEvaluationLine[];
|
|
63
|
+
interface PriceEvaluationIssue {
|
|
64
|
+
code: "dimension_mismatch" | "ambiguous_rate" | "missing_usage";
|
|
65
|
+
metric: BillingMetric;
|
|
66
|
+
componentIndex: number;
|
|
67
|
+
}
|
|
68
|
+
interface PriceEvaluation {
|
|
69
|
+
status: "rated" | "incomplete";
|
|
70
|
+
amount: string;
|
|
71
|
+
lines: PriceEvaluationLine[];
|
|
72
|
+
issues: PriceEvaluationIssue[];
|
|
73
|
+
}
|
|
74
|
+
declare function validateNormalizedUsage(value: unknown): asserts value is NormalizedUsageV1;
|
|
75
|
+
/**
|
|
76
|
+
* Deterministically rates normalized usage without mutating wallets or billing
|
|
77
|
+
* records. Amounts are rounded half-up to the database's eight-decimal money
|
|
78
|
+
* scale per line; ceil rates round usage units before multiplying the price.
|
|
79
|
+
*/
|
|
80
|
+
declare function evaluatePriceRule(ruleValue: unknown, usageValue: unknown): PriceEvaluation;
|
|
81
|
+
declare function validatePriceRule(value: unknown): asserts value is PriceRule;
|
|
82
|
+
|
|
83
|
+
type MeteringKind = "token" | "non_token" | "mixed";
|
|
84
|
+
type UsageEvidenceStatus = "complete" | "partial" | "missing" | "invalid" | "not_expected";
|
|
85
|
+
interface MeteringContract {
|
|
86
|
+
schemaVersion: 1;
|
|
87
|
+
kind: MeteringKind;
|
|
88
|
+
metrics: ReadonlyArray<{
|
|
89
|
+
metric: BillingMetric;
|
|
90
|
+
requirement: "required" | "conditional" | "informational";
|
|
91
|
+
whenFeature?: string;
|
|
92
|
+
}>;
|
|
93
|
+
}
|
|
94
|
+
interface UsageEvidenceAssessment {
|
|
95
|
+
kind: MeteringKind | "unknown";
|
|
96
|
+
evidenceStatus: UsageEvidenceStatus;
|
|
97
|
+
expectedMetrics: BillingMetric[];
|
|
98
|
+
observedMetrics: BillingMetric[];
|
|
99
|
+
missingMetrics: BillingMetric[];
|
|
100
|
+
issues: string[];
|
|
101
|
+
}
|
|
102
|
+
declare function validateMeteringContract(value: unknown): asserts value is MeteringContract;
|
|
103
|
+
/** Evidence completeness is independent of sale/cost prices and delivery success. */
|
|
104
|
+
declare function assessUsageEvidence(contract: unknown, usage: unknown, features?: Readonly<Record<string, boolean>>): UsageEvidenceAssessment;
|
|
105
|
+
|
|
106
|
+
type ModelModality = "language" | "embedding" | "reranker" | "image" | "video" | "audio" | "world" | "multimodal" | "other";
|
|
107
|
+
interface ModelEndpointSummary {
|
|
108
|
+
key: string;
|
|
109
|
+
label: string;
|
|
110
|
+
operation: string;
|
|
111
|
+
protocol: string;
|
|
112
|
+
method: string;
|
|
113
|
+
path: string;
|
|
114
|
+
capabilities: string[];
|
|
115
|
+
/** Task execution of this native endpoint, not a second model parameter definition. */
|
|
116
|
+
sourceEndpointKey?: string | null;
|
|
117
|
+
}
|
|
118
|
+
interface ModelCapabilitySummary {
|
|
119
|
+
inputModalities: string[];
|
|
120
|
+
outputModalities: string[];
|
|
121
|
+
/** User-facing input patterns such as text-to-video or image-to-image. */
|
|
122
|
+
inputModes: string[];
|
|
123
|
+
features: string[];
|
|
124
|
+
}
|
|
125
|
+
interface ModelDateVersion {
|
|
126
|
+
id: string;
|
|
127
|
+
label: string;
|
|
128
|
+
date?: string;
|
|
129
|
+
isLatest?: boolean;
|
|
130
|
+
}
|
|
131
|
+
interface TaskModelSummary {
|
|
132
|
+
requestSuccessBuckets?: {
|
|
133
|
+
start: string;
|
|
134
|
+
end: string;
|
|
135
|
+
succeeded: number;
|
|
136
|
+
total: number;
|
|
137
|
+
}[];
|
|
138
|
+
id: string;
|
|
139
|
+
slug: string;
|
|
140
|
+
displayName: string;
|
|
141
|
+
summary?: string;
|
|
142
|
+
modality: ModelModality;
|
|
143
|
+
operation: string;
|
|
144
|
+
category: string;
|
|
145
|
+
capabilities: ModelCapabilitySummary;
|
|
146
|
+
tags: string[];
|
|
147
|
+
endpoints: ModelEndpointSummary[];
|
|
148
|
+
schemaVersion: number;
|
|
149
|
+
status: "active";
|
|
150
|
+
thumbnailUrl?: string;
|
|
151
|
+
featured?: boolean;
|
|
152
|
+
family?: string;
|
|
153
|
+
versionLabel?: string;
|
|
154
|
+
isRecommended?: boolean;
|
|
155
|
+
dateVersions?: readonly ModelDateVersion[];
|
|
156
|
+
}
|
|
157
|
+
interface TaskModel extends TaskModelSummary {
|
|
158
|
+
description?: string;
|
|
159
|
+
regions: string[];
|
|
160
|
+
metadata?: JsonObject;
|
|
161
|
+
/** Public list and customer-facing sale prices. Channel costs are never exposed here. */
|
|
162
|
+
pricing?: {
|
|
163
|
+
official: Array<{
|
|
164
|
+
operation: string;
|
|
165
|
+
currency: string;
|
|
166
|
+
rule: PriceRule;
|
|
167
|
+
}>;
|
|
168
|
+
sale: Array<{
|
|
169
|
+
operation: string;
|
|
170
|
+
currency: string;
|
|
171
|
+
rule: PriceRule;
|
|
172
|
+
}>;
|
|
173
|
+
};
|
|
174
|
+
familyVersions?: readonly {
|
|
175
|
+
slug: string;
|
|
176
|
+
displayName: string;
|
|
177
|
+
versionLabel?: string;
|
|
178
|
+
isRecommended?: boolean;
|
|
179
|
+
}[];
|
|
180
|
+
}
|
|
181
|
+
interface ModelSchema {
|
|
182
|
+
model: string;
|
|
183
|
+
version: number;
|
|
184
|
+
dialect: "https://json-schema.org/draft/2020-12/schema" | string;
|
|
185
|
+
inputSchema: JsonObject;
|
|
186
|
+
outputSchema: JsonObject;
|
|
187
|
+
/** Native wire parameters outside the request body. */
|
|
188
|
+
headersSchema?: JsonObject;
|
|
189
|
+
pathSchema?: JsonObject;
|
|
190
|
+
querySchema?: JsonObject;
|
|
191
|
+
/** Final native response for an upstream API that creates an asynchronous job. */
|
|
192
|
+
resultSchema?: JsonObject;
|
|
193
|
+
/** @deprecated Compatibility projection; presentation annotations live on inputSchema fields as x-ui. */
|
|
194
|
+
uiSchema: JsonObject;
|
|
195
|
+
/** @deprecated Compatibility projection; defaults live on inputSchema fields. */
|
|
196
|
+
defaults: JsonObject;
|
|
197
|
+
examples: JsonValue[];
|
|
198
|
+
}
|
|
199
|
+
interface ModelResourceOption {
|
|
200
|
+
id: string;
|
|
201
|
+
label: string;
|
|
202
|
+
description?: string;
|
|
203
|
+
previewUrl?: string;
|
|
204
|
+
}
|
|
205
|
+
interface ModelResourceList {
|
|
206
|
+
resource: string;
|
|
207
|
+
status: "ready" | "unavailable";
|
|
208
|
+
data: readonly ModelResourceOption[];
|
|
209
|
+
message?: string;
|
|
210
|
+
}
|
|
211
|
+
interface ModelSearchParams {
|
|
212
|
+
/** Browse published catalog definitions even when execution is not ready. */
|
|
213
|
+
includeUnavailable?: boolean;
|
|
214
|
+
query?: string;
|
|
215
|
+
modality?: ModelModality;
|
|
216
|
+
operation?: string;
|
|
217
|
+
category?: string;
|
|
218
|
+
limit?: number;
|
|
219
|
+
cursor?: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
type NexraBillingCurrency = "CNY";
|
|
223
|
+
interface NexraModelOperation {
|
|
224
|
+
operation: string;
|
|
225
|
+
inputModalities: readonly string[];
|
|
226
|
+
outputModalities: readonly string[];
|
|
227
|
+
inputSchema: JsonObject;
|
|
228
|
+
outputSchema: JsonObject;
|
|
229
|
+
metering: MeteringContract;
|
|
230
|
+
}
|
|
231
|
+
interface NexraModelSpec {
|
|
232
|
+
id: string;
|
|
233
|
+
contractVersion: number;
|
|
234
|
+
developer: string;
|
|
235
|
+
displayName: string;
|
|
236
|
+
summary?: string;
|
|
237
|
+
kind: ModelModality;
|
|
238
|
+
family?: string;
|
|
239
|
+
versionLabel?: string;
|
|
240
|
+
aliases: readonly string[];
|
|
241
|
+
capabilities: ModelCapabilitySummary;
|
|
242
|
+
operations: readonly NexraModelOperation[];
|
|
243
|
+
}
|
|
244
|
+
interface NexraModelSpecFilter {
|
|
245
|
+
kind?: ModelModality;
|
|
246
|
+
operation?: string;
|
|
247
|
+
}
|
|
248
|
+
interface NexraSalePrice {
|
|
249
|
+
modelId: string;
|
|
250
|
+
operation: string;
|
|
251
|
+
currency: NexraBillingCurrency;
|
|
252
|
+
priceRevision: string;
|
|
253
|
+
effectiveFrom: string;
|
|
254
|
+
rule: PriceRule;
|
|
255
|
+
}
|
|
256
|
+
interface CreateNexraQuoteRequest {
|
|
257
|
+
modelId: string;
|
|
258
|
+
operation: string;
|
|
259
|
+
input: JsonObject;
|
|
260
|
+
}
|
|
261
|
+
interface NexraQuote {
|
|
262
|
+
quoteToken: string;
|
|
263
|
+
modelId: string;
|
|
264
|
+
contractVersion: number;
|
|
265
|
+
priceRevision: string;
|
|
266
|
+
currency: NexraBillingCurrency;
|
|
267
|
+
amount: string;
|
|
268
|
+
maximumAmount?: string;
|
|
269
|
+
accuracy: "exact" | "estimated";
|
|
270
|
+
expiresAt: string;
|
|
271
|
+
}
|
|
272
|
+
interface NexraSettlement {
|
|
273
|
+
amount: string;
|
|
274
|
+
currency: NexraBillingCurrency;
|
|
275
|
+
priceRevision: string;
|
|
276
|
+
billingStatus: "pending" | "succeeded" | "failed" | "refunded" | "unavailable";
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface NexraClientOptions {
|
|
280
|
+
apiKey?: string;
|
|
281
|
+
baseUrl?: string;
|
|
282
|
+
fetch?: FetchLike;
|
|
283
|
+
headers?: HeadersInit;
|
|
284
|
+
maxRetries?: number;
|
|
285
|
+
}
|
|
286
|
+
type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
287
|
+
interface RequestOptions {
|
|
288
|
+
retryable?: boolean;
|
|
289
|
+
}
|
|
290
|
+
declare class HttpTransport {
|
|
291
|
+
readonly baseUrl: string;
|
|
292
|
+
private readonly apiKey?;
|
|
293
|
+
private readonly fetchImplementation;
|
|
294
|
+
private readonly defaultHeaders;
|
|
295
|
+
private readonly maxRetries;
|
|
296
|
+
constructor(options: NexraClientOptions);
|
|
297
|
+
url(path: string): string;
|
|
298
|
+
json<T>(path: string, init?: RequestInit, options?: RequestOptions): Promise<T>;
|
|
299
|
+
response(path: string, init?: RequestInit, options?: RequestOptions): Promise<Response>;
|
|
300
|
+
}
|
|
301
|
+
declare function jsonBody(value: unknown): Pick<RequestInit, "body" | "headers">;
|
|
302
|
+
declare function queryString(values: Record<string, string | number | undefined>): string;
|
|
303
|
+
declare function sleep(milliseconds: number, signal?: AbortSignal | null): Promise<void>;
|
|
304
|
+
|
|
305
|
+
declare class CatalogClient {
|
|
306
|
+
private readonly transport;
|
|
307
|
+
constructor(transport: HttpTransport);
|
|
308
|
+
quote(request: CreateNexraQuoteRequest, signal?: AbortSignal): Promise<NexraQuote>;
|
|
309
|
+
}
|
|
310
|
+
declare function getModelSpec(modelId: string): NexraModelSpec | undefined;
|
|
311
|
+
declare function listModelSpecs(filter?: NexraModelSpecFilter): readonly NexraModelSpec[];
|
|
312
|
+
|
|
313
|
+
export { type NormalizedUsageV1 as A, type BillingMetric as B, type CursorPage as C, type PriceEvaluationIssue as D, type PriceEvaluationLine as E, type FetchLike as F, type PriceRule as G, HttpTransport as H, type UsageEvidenceAssessment as I, type JsonObject as J, type UsageEvidenceStatus as K, allocateDiscountedPriceLines as L, type ModelSearchParams as M, type NexraSettlement as N, assessUsageEvidence as O, type PriceEvaluation as P, evaluatePriceRule as Q, getModelSpec as R, jsonBody as S, type TaskModelSummary as T, type UsageComponentEvidence as U, listModelSpecs as V, queryString as W, sleep as X, validateMeteringContract as Y, validateNormalizedUsage as Z, validatePriceRule as _, type JsonValue as a, type TaskModel as b, type ModelSchema as c, CatalogClient as d, type NexraClientOptions as e, BILLING_EXPORT_DIMENSIONS as f, BILLING_METRICS as g, type CreateNexraQuoteRequest as h, type JsonPrimitive as i, type MeteredPriceRate as j, type MeteredPriceRuleV1 as k, type MeteredUsageComponent as l, type MeteringContract as m, type MeteringKind as n, type ModelCapabilitySummary as o, type ModelDateVersion as p, type ModelEndpointSummary as q, type ModelModality as r, type ModelResourceList as s, type ModelResourceOption as t, type NexraBillingCurrency as u, type NexraModelOperation as v, type NexraModelSpec as w, type NexraModelSpecFilter as x, type NexraQuote as y, type NexraSalePrice as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { d as CatalogClient, h as CreateNexraQuoteRequest, u as NexraBillingCurrency, v as NexraModelOperation, w as NexraModelSpec, x as NexraModelSpecFilter, y as NexraQuote, z as NexraSalePrice, N as NexraSettlement, R as getModelSpec, V as listModelSpecs } from './catalog-mytCeh5t.js';
|