@onlist/sdk 0.1.0 → 0.3.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 +207 -13
- package/dist/index.cjs +349 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +524 -12
- package/dist/index.d.ts +524 -12
- package/dist/index.js +337 -28
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,390 @@
|
|
|
1
1
|
import OpenAI, { ClientOptions } from 'openai';
|
|
2
2
|
|
|
3
|
+
/** Shared options for the REST resources (marketplace and account). */
|
|
4
|
+
interface RequestOptions {
|
|
5
|
+
apiKey?: string | null;
|
|
6
|
+
baseURL: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
/** Maximum retry attempts for failed requests. Defaults to 2. */
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Response types for the account API (`/api/v1/*`).
|
|
14
|
+
*
|
|
15
|
+
* Field names mirror the wire format one-for-one, which is OpenRouter's, so
|
|
16
|
+
* code written against OpenRouter's responses reads the same fields here.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The deprecated per-key rate limit descriptor on {@link CurrentKey}.
|
|
20
|
+
*
|
|
21
|
+
* Onlist has no per-key request-rate limit — only spend budgets — so
|
|
22
|
+
* `requests` is always `-1`. Do not use it to drive client-side throttling.
|
|
23
|
+
*/
|
|
24
|
+
interface RateLimit {
|
|
25
|
+
requests: number;
|
|
26
|
+
interval: string;
|
|
27
|
+
note: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An inference key (`sk-...`) as returned by the `apiKeys` resource.
|
|
31
|
+
*
|
|
32
|
+
* `limit`, `limit_remaining` and `limit_reset` move together: either all
|
|
33
|
+
* three are set, or all three are `null` (no spend budget). Amounts are USD.
|
|
34
|
+
* `created_at` / `expires_at` are RFC 3339 UTC strings, or `null` for
|
|
35
|
+
* "never".
|
|
36
|
+
*/
|
|
37
|
+
interface APIKey {
|
|
38
|
+
hash: string;
|
|
39
|
+
name: string;
|
|
40
|
+
label: string;
|
|
41
|
+
disabled: boolean;
|
|
42
|
+
limit: number | null;
|
|
43
|
+
limit_remaining: number | null;
|
|
44
|
+
limit_reset: string | null;
|
|
45
|
+
include_byok_in_limit: boolean;
|
|
46
|
+
usage: number;
|
|
47
|
+
usage_daily: number;
|
|
48
|
+
usage_weekly: number;
|
|
49
|
+
usage_monthly: number;
|
|
50
|
+
byok_usage: number;
|
|
51
|
+
byok_usage_daily: number;
|
|
52
|
+
byok_usage_weekly: number;
|
|
53
|
+
byok_usage_monthly: number;
|
|
54
|
+
created_at: string | null;
|
|
55
|
+
updated_at: string | null;
|
|
56
|
+
expires_at: string | null;
|
|
57
|
+
external_user: string | null;
|
|
58
|
+
creator_user_id: string | null;
|
|
59
|
+
workspace_id: string | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The credential used for the request, from `apiKeys.current()`.
|
|
63
|
+
*
|
|
64
|
+
* Every field is optional because the endpoint answers for both credential
|
|
65
|
+
* types and they carry different information: a management key has no usage
|
|
66
|
+
* and no budget (reporting `0` would read as "an inference key that has
|
|
67
|
+
* never spent"), so those fields are simply absent from its projection.
|
|
68
|
+
* Branch on `is_management_key`.
|
|
69
|
+
*/
|
|
70
|
+
interface CurrentKey extends Partial<APIKey> {
|
|
71
|
+
is_free_tier?: boolean;
|
|
72
|
+
is_management_key?: boolean;
|
|
73
|
+
is_provisioning_key?: boolean;
|
|
74
|
+
rate_limit?: RateLimit;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The result of `apiKeys.create()`.
|
|
78
|
+
*
|
|
79
|
+
* `key` is the full secret in plaintext and is returned **only here, only
|
|
80
|
+
* once** — the server keeps a hash. Store it before discarding this object.
|
|
81
|
+
* `data` is the same key object later reads return.
|
|
82
|
+
*/
|
|
83
|
+
interface CreatedKey {
|
|
84
|
+
key: string;
|
|
85
|
+
data: APIKey;
|
|
86
|
+
}
|
|
87
|
+
/** Parameters for `apiKeys.create()`. */
|
|
88
|
+
interface CreateKeyParams {
|
|
89
|
+
/** Spend budget in USD. Omit for no budget. */
|
|
90
|
+
limit?: number;
|
|
91
|
+
/** `"daily"`, `"weekly"`, or omitted for a lifetime total. `"monthly"` is rejected. */
|
|
92
|
+
limit_reset?: string;
|
|
93
|
+
/** Expiry as a Unix timestamp. Omit to never expire. */
|
|
94
|
+
expires_at?: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Patch for `apiKeys.update()`.
|
|
98
|
+
*
|
|
99
|
+
* Three states: an omitted (or `undefined`) field is left unchanged, and an
|
|
100
|
+
* explicit `null` clears the value. `name` and `disabled` therefore accept
|
|
101
|
+
* no `null` — the server reads `{"name": null}` as an empty name (400) and
|
|
102
|
+
* `{"disabled": null}` as `false`, which would silently re-enable a key you
|
|
103
|
+
* only meant to leave alone.
|
|
104
|
+
*/
|
|
105
|
+
interface UpdateKeyParams {
|
|
106
|
+
name?: string;
|
|
107
|
+
disabled?: boolean;
|
|
108
|
+
limit?: number | null;
|
|
109
|
+
limit_reset?: string | null;
|
|
110
|
+
expires_at?: number | null;
|
|
111
|
+
}
|
|
112
|
+
/** Parameters for `apiKeys.list()`. */
|
|
113
|
+
interface ListKeysParams {
|
|
114
|
+
/** Number of keys to skip. Pages are a fixed 100 and no total is returned. */
|
|
115
|
+
offset?: number;
|
|
116
|
+
/** Include disabled keys in the result. */
|
|
117
|
+
include_disabled?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Account balance, in USD.
|
|
121
|
+
*
|
|
122
|
+
* Remaining balance is `total_credits - total_usage`: the endpoint reports
|
|
123
|
+
* lifetime totals rather than a single "balance" number, matching
|
|
124
|
+
* OpenRouter.
|
|
125
|
+
*/
|
|
126
|
+
interface Credits {
|
|
127
|
+
total_credits: number;
|
|
128
|
+
total_usage: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Cost and timing for a single completed call, from `generations.get()`.
|
|
132
|
+
*
|
|
133
|
+
* Fields Onlist has no data for are `null` rather than `0`: `upstream_id`,
|
|
134
|
+
* `http_referer`, `user_agent`, `origin`, `api_type`, `cache_discount` and
|
|
135
|
+
* `native_tokens_reasoning`. For reconciliation, "not measured" and
|
|
136
|
+
* "measured as zero" are different statements.
|
|
137
|
+
*
|
|
138
|
+
* `latency` is time-to-first-token in milliseconds and is `null` for
|
|
139
|
+
* non-streamed calls, which never measure it. `generation_time` is total
|
|
140
|
+
* wall time in milliseconds. `total_cost` and `usage` are the same USD
|
|
141
|
+
* amount under both of OpenRouter's names.
|
|
142
|
+
*/
|
|
143
|
+
interface Generation {
|
|
144
|
+
id: string;
|
|
145
|
+
model: string;
|
|
146
|
+
provider_name: string | null;
|
|
147
|
+
streamed: boolean;
|
|
148
|
+
latency: number | null;
|
|
149
|
+
generation_time: number;
|
|
150
|
+
created_at: string | null;
|
|
151
|
+
tokens_prompt: number;
|
|
152
|
+
tokens_completion: number;
|
|
153
|
+
native_tokens_prompt: number;
|
|
154
|
+
native_tokens_completion: number;
|
|
155
|
+
native_tokens_cached: number | null;
|
|
156
|
+
native_tokens_reasoning: number | null;
|
|
157
|
+
total_cost: number;
|
|
158
|
+
usage: number;
|
|
159
|
+
cache_discount: number | null;
|
|
160
|
+
finish_reason: string | null;
|
|
161
|
+
native_finish_reason: string | null;
|
|
162
|
+
is_byok: boolean;
|
|
163
|
+
upstream_id: string | null;
|
|
164
|
+
http_referer: string | null;
|
|
165
|
+
user_agent: string | null;
|
|
166
|
+
origin: string | null;
|
|
167
|
+
api_type: string | null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* One day × model × provider bucket from `activity.list()`.
|
|
171
|
+
*
|
|
172
|
+
* `date` is a `YYYY-MM-DD` UTC day and `usage` is USD. Only complete days
|
|
173
|
+
* appear — today is still accumulating, and this endpoint exists for
|
|
174
|
+
* reconciliation.
|
|
175
|
+
*/
|
|
176
|
+
interface ActivityRow {
|
|
177
|
+
date: string;
|
|
178
|
+
model: string;
|
|
179
|
+
model_permaslug: string;
|
|
180
|
+
endpoint_id: string;
|
|
181
|
+
provider_name: string | null;
|
|
182
|
+
usage: number;
|
|
183
|
+
byok_usage_inference: number;
|
|
184
|
+
requests: number;
|
|
185
|
+
prompt_tokens: number;
|
|
186
|
+
completion_tokens: number;
|
|
187
|
+
reasoning_tokens: number;
|
|
188
|
+
}
|
|
189
|
+
/** Parameters for `activity.list()`. */
|
|
190
|
+
interface ActivityParams {
|
|
191
|
+
/** Restrict to one `YYYY-MM-DD` UTC day inside the 30-day window. */
|
|
192
|
+
date?: string;
|
|
193
|
+
/** Restrict to one inference key. A hash from another account yields an empty list. */
|
|
194
|
+
api_key_hash?: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The result of `oauth.exchange()`.
|
|
198
|
+
*
|
|
199
|
+
* `key` is a new inference key in plaintext, returned once. `user_id` is
|
|
200
|
+
* always `null` on Onlist: on OpenRouter it carries the calling
|
|
201
|
+
* application's own external user identifier, which Onlist has no concept
|
|
202
|
+
* of.
|
|
203
|
+
*/
|
|
204
|
+
interface ExchangedKey {
|
|
205
|
+
key: string;
|
|
206
|
+
user_id: string | null;
|
|
207
|
+
}
|
|
208
|
+
/** An S256 PKCE pair from `generatePkce()`. */
|
|
209
|
+
interface PkcePair {
|
|
210
|
+
/** Kept in memory and passed back to `oauth.exchange()`. */
|
|
211
|
+
verifier: string;
|
|
212
|
+
/** Sent to `/auth` when opening the browser flow. */
|
|
213
|
+
challenge: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Account resources — the OpenRouter-compatible `/api/v1/*` face.
|
|
218
|
+
*
|
|
219
|
+
* Namespaces follow the wire path segments (`credits`, `generations`,
|
|
220
|
+
* `apiKeys`, `activity`) and methods use a fixed verb set
|
|
221
|
+
* (`list`/`get`/`create`/`update`/`delete`). Two departures, both forced:
|
|
222
|
+
* `GET /api/v1/key` has no matching verb so it is `apiKeys.current()`, and
|
|
223
|
+
* `/api/v1/auth/*` would read as client authentication config so the
|
|
224
|
+
* namespace is `oauth`.
|
|
225
|
+
*
|
|
226
|
+
* Most of these endpoints require a **management key** (`mgmt_...`). The SDK
|
|
227
|
+
* does not inspect key prefixes locally — it sends whatever credential it
|
|
228
|
+
* was given and surfaces the server's 403 as `PermissionDeniedError`.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/** Options for creating the account resources. */
|
|
232
|
+
type AccountOptions = RequestOptions;
|
|
233
|
+
/**
|
|
234
|
+
* Generate an S256 PKCE `{verifier, challenge}` pair.
|
|
235
|
+
*
|
|
236
|
+
* Send the challenge to `/auth` when starting the browser flow, keep the
|
|
237
|
+
* verifier in memory, and pass it back to `oauth.exchange()`:
|
|
238
|
+
*
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const { verifier, challenge } = await generatePkce();
|
|
241
|
+
* window.location.href =
|
|
242
|
+
* `https://onlist.io/auth?callback_url=${cb}` +
|
|
243
|
+
* `&code_challenge=${challenge}&code_challenge_method=S256`;
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
declare function generatePkce(): Promise<PkcePair>;
|
|
247
|
+
/**
|
|
248
|
+
* Exchange a PKCE authorization code for an inference key, with no client.
|
|
249
|
+
*
|
|
250
|
+
* `client.oauth.exchange()` does the same thing, but constructing an
|
|
251
|
+
* {@link Onlist} requires an API key — and an app running the "Sign in with
|
|
252
|
+
* Onlist" flow does not have one yet. That is the entire point of the flow,
|
|
253
|
+
* so it gets a credential-free entry point:
|
|
254
|
+
*
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const { verifier, challenge } = await generatePkce();
|
|
257
|
+
* // ...user approves in the browser, your callback receives ?code=...
|
|
258
|
+
* const result = await exchangeAuthCode(code, { codeVerifier: verifier });
|
|
259
|
+
* const client = new Onlist({ apiKey: result.key });
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* Single-use: the code is consumed even when the verifier turns out to be
|
|
263
|
+
* wrong, so a failure means restarting the browser flow.
|
|
264
|
+
*/
|
|
265
|
+
declare function exchangeAuthCode(code: string, opts?: {
|
|
266
|
+
codeVerifier?: string;
|
|
267
|
+
baseURL?: string;
|
|
268
|
+
timeout?: number;
|
|
269
|
+
}): Promise<ExchangedKey>;
|
|
270
|
+
/** Account balance. Requires a management key. */
|
|
271
|
+
declare class AccountCredits {
|
|
272
|
+
private readonly _opts;
|
|
273
|
+
constructor(_opts: AccountOptions);
|
|
274
|
+
/** Get lifetime credits purchased and credits used, in USD. */
|
|
275
|
+
get(): Promise<Credits>;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Per-call cost and timing.
|
|
279
|
+
*
|
|
280
|
+
* Accepts either credential type: an inference key can look up only the
|
|
281
|
+
* calls it made, a management key any call on the account.
|
|
282
|
+
*/
|
|
283
|
+
declare class AccountGenerations {
|
|
284
|
+
private readonly _opts;
|
|
285
|
+
constructor(_opts: AccountOptions);
|
|
286
|
+
/**
|
|
287
|
+
* Look up one call by request ID.
|
|
288
|
+
*
|
|
289
|
+
* @param requestId The value of the `X-Oneapi-Request-Id` response header
|
|
290
|
+
* from the original call.
|
|
291
|
+
*/
|
|
292
|
+
get(requestId: string): Promise<Generation>;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Manage inference keys (`sk-...`). Requires a management key.
|
|
296
|
+
*
|
|
297
|
+
* The exception is {@link current}, which answers for whichever credential
|
|
298
|
+
* made the request.
|
|
299
|
+
*/
|
|
300
|
+
declare class AccountApiKeys {
|
|
301
|
+
private readonly _opts;
|
|
302
|
+
constructor(_opts: AccountOptions);
|
|
303
|
+
/** Describe the credential this client is using. */
|
|
304
|
+
current(): Promise<CurrentKey>;
|
|
305
|
+
/**
|
|
306
|
+
* List inference keys.
|
|
307
|
+
*
|
|
308
|
+
* Pages are a fixed 100 keys and no total is returned: request
|
|
309
|
+
* `offset += 100` until you get a short page.
|
|
310
|
+
*/
|
|
311
|
+
list(params?: ListKeysParams): Promise<APIKey[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Create an inference key.
|
|
314
|
+
*
|
|
315
|
+
* The plaintext secret is on `.key` of the result and is never retrievable
|
|
316
|
+
* again.
|
|
317
|
+
*
|
|
318
|
+
* @param name Display name for the key. Required.
|
|
319
|
+
*/
|
|
320
|
+
create(name: string, params?: CreateKeyParams): Promise<CreatedKey>;
|
|
321
|
+
/** Get one inference key by its `hash`. */
|
|
322
|
+
get(hash: string): Promise<APIKey>;
|
|
323
|
+
/**
|
|
324
|
+
* Update an inference key. Omitted fields are left unchanged.
|
|
325
|
+
*
|
|
326
|
+
* For `limit`, `limit_reset` and `expires_at`, passing `null` clears the
|
|
327
|
+
* value; leaving the field out leaves it alone.
|
|
328
|
+
*/
|
|
329
|
+
update(hash: string, patch: UpdateKeyParams): Promise<APIKey>;
|
|
330
|
+
/** Delete an inference key. Resolves to `true` on success. */
|
|
331
|
+
delete(hash: string): Promise<boolean>;
|
|
332
|
+
}
|
|
333
|
+
/** Daily usage rollups. Requires a management key. */
|
|
334
|
+
declare class AccountActivity {
|
|
335
|
+
private readonly _opts;
|
|
336
|
+
constructor(_opts: AccountOptions);
|
|
337
|
+
/**
|
|
338
|
+
* List usage grouped by day, model and provider.
|
|
339
|
+
*
|
|
340
|
+
* Covers the last 30 complete UTC days; today is excluded.
|
|
341
|
+
*/
|
|
342
|
+
list(params?: ActivityParams): Promise<ActivityRow[]>;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Sign in with Onlist — the PKCE authorization-code exchange.
|
|
346
|
+
*
|
|
347
|
+
* Only the exchange lives here. The authorization step itself happens in the
|
|
348
|
+
* user's browser at `https://onlist.io/auth`; there is no SDK call for it,
|
|
349
|
+
* because the SDK has no session to authorize with.
|
|
350
|
+
*/
|
|
351
|
+
declare class AccountOAuth {
|
|
352
|
+
private readonly _opts;
|
|
353
|
+
constructor(_opts: AccountOptions);
|
|
354
|
+
/**
|
|
355
|
+
* Exchange an authorization code for a new inference key.
|
|
356
|
+
*
|
|
357
|
+
* Unauthenticated, and single-use: the code is consumed even when the
|
|
358
|
+
* verifier turns out to be wrong, so a failure means restarting the
|
|
359
|
+
* browser flow.
|
|
360
|
+
*
|
|
361
|
+
* @param code The `code` query parameter from the callback URL.
|
|
362
|
+
* @param codeVerifier The verifier from {@link generatePkce}. Required
|
|
363
|
+
* whenever the authorization request carried a challenge.
|
|
364
|
+
*/
|
|
365
|
+
exchange(code: string, codeVerifier?: string): Promise<ExchangedKey>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Model pricing in USD per million tokens. */
|
|
3
369
|
interface Pricing {
|
|
4
370
|
prompt: string;
|
|
5
371
|
completion: string;
|
|
6
372
|
request?: string | null;
|
|
7
373
|
}
|
|
374
|
+
/** Model architecture metadata. */
|
|
8
375
|
interface Architecture {
|
|
9
376
|
modality?: string | null;
|
|
10
377
|
input_modalities?: string[] | null;
|
|
11
378
|
output_modalities?: string[] | null;
|
|
12
379
|
tokenizer?: string | null;
|
|
13
380
|
}
|
|
381
|
+
/** Top-provider context limits for a model. */
|
|
14
382
|
interface TopProvider {
|
|
15
383
|
context_length?: number | null;
|
|
16
384
|
max_completion_tokens?: number | null;
|
|
17
385
|
is_moderated?: boolean | null;
|
|
18
386
|
}
|
|
387
|
+
/** A model listed in the marketplace catalog. */
|
|
19
388
|
interface Model {
|
|
20
389
|
id: string;
|
|
21
390
|
name?: string | null;
|
|
@@ -32,8 +401,8 @@ interface Model {
|
|
|
32
401
|
quantization?: string | null;
|
|
33
402
|
top_provider?: TopProvider | null;
|
|
34
403
|
is_ready?: boolean | null;
|
|
35
|
-
[key: string]: unknown;
|
|
36
404
|
}
|
|
405
|
+
/** A provider's offer for a specific model. */
|
|
37
406
|
interface ProviderOffer {
|
|
38
407
|
listing_id?: number | null;
|
|
39
408
|
provider_id?: number | null;
|
|
@@ -44,8 +413,8 @@ interface ProviderOffer {
|
|
|
44
413
|
price_input_usd?: string | null;
|
|
45
414
|
price_output_usd?: string | null;
|
|
46
415
|
availability_7d?: number | null;
|
|
47
|
-
[key: string]: unknown;
|
|
48
416
|
}
|
|
417
|
+
/** Detailed model info including all provider offers. */
|
|
49
418
|
interface ModelDetail {
|
|
50
419
|
id: string;
|
|
51
420
|
name?: string | null;
|
|
@@ -57,8 +426,8 @@ interface ModelDetail {
|
|
|
57
426
|
pricing?: Pricing | null;
|
|
58
427
|
description?: string | null;
|
|
59
428
|
providers: ProviderOffer[];
|
|
60
|
-
[key: string]: unknown;
|
|
61
429
|
}
|
|
430
|
+
/** Paginated list of models. */
|
|
62
431
|
interface ModelListResponse {
|
|
63
432
|
data: Model[];
|
|
64
433
|
total?: number | null;
|
|
@@ -66,6 +435,7 @@ interface ModelListResponse {
|
|
|
66
435
|
limit?: number | null;
|
|
67
436
|
}
|
|
68
437
|
|
|
438
|
+
/** A provider (seller) on the marketplace. */
|
|
69
439
|
interface Provider {
|
|
70
440
|
id?: number | null;
|
|
71
441
|
slug: string;
|
|
@@ -79,59 +449,170 @@ interface Provider {
|
|
|
79
449
|
sample_count?: number | null;
|
|
80
450
|
max_rpm?: number | null;
|
|
81
451
|
availability_7d?: number | null;
|
|
82
|
-
[key: string]: unknown;
|
|
83
452
|
}
|
|
453
|
+
/** Detailed provider info including their listings. */
|
|
84
454
|
interface ProviderDetail extends Provider {
|
|
85
455
|
listings: Record<string, unknown>[];
|
|
86
456
|
}
|
|
457
|
+
/** Paginated list of providers. */
|
|
87
458
|
interface ProviderListResponse {
|
|
88
459
|
items: Provider[];
|
|
89
460
|
}
|
|
90
461
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
462
|
+
/** A single entry in the model usage leaderboard. */
|
|
463
|
+
interface ModelRanking {
|
|
464
|
+
rank: number;
|
|
465
|
+
model_name: string;
|
|
466
|
+
author: string;
|
|
467
|
+
author_icon: string | null;
|
|
468
|
+
total_tokens: string;
|
|
469
|
+
total_requests: number;
|
|
470
|
+
growth_pct: number | null;
|
|
471
|
+
}
|
|
472
|
+
/** A single data point in the model usage chart series. */
|
|
473
|
+
interface ModelSeriesPoint {
|
|
474
|
+
bucket: string;
|
|
475
|
+
value: number;
|
|
476
|
+
type: string;
|
|
477
|
+
}
|
|
478
|
+
/** Response from GET /api/mkt/rankings/models. */
|
|
479
|
+
interface ModelRankingsResponse {
|
|
480
|
+
leaderboard: ModelRanking[];
|
|
481
|
+
series: ModelSeriesPoint[];
|
|
482
|
+
top_models: string[];
|
|
483
|
+
sort: string;
|
|
484
|
+
window: string;
|
|
485
|
+
start_date: string;
|
|
486
|
+
end_date: string;
|
|
487
|
+
}
|
|
488
|
+
/** Query parameters for the model rankings endpoint. */
|
|
489
|
+
interface ModelRankingsParams {
|
|
490
|
+
sort?: "popular" | "trending";
|
|
491
|
+
window?: "day" | "week" | "month";
|
|
492
|
+
limit?: number;
|
|
493
|
+
offset?: number;
|
|
494
|
+
}
|
|
495
|
+
/** A single entry in the app rankings list. */
|
|
496
|
+
interface AppRanking {
|
|
497
|
+
app_id: number;
|
|
498
|
+
url_key: string;
|
|
499
|
+
slug: string | null;
|
|
500
|
+
title: string;
|
|
501
|
+
description: string | null;
|
|
502
|
+
domain: string;
|
|
503
|
+
icon_url: string | null;
|
|
504
|
+
categories: string[];
|
|
505
|
+
rank: number;
|
|
506
|
+
total_requests: number;
|
|
507
|
+
total_tokens: string;
|
|
508
|
+
growth_pct: number | null;
|
|
509
|
+
}
|
|
510
|
+
/** Response from GET /api/mkt/apps. */
|
|
511
|
+
interface AppRankingsResponse {
|
|
512
|
+
apps: AppRanking[];
|
|
513
|
+
page: number;
|
|
514
|
+
limit: number;
|
|
515
|
+
has_more: boolean;
|
|
516
|
+
sort: string;
|
|
517
|
+
window: string;
|
|
518
|
+
start_date: string;
|
|
519
|
+
end_date: string;
|
|
95
520
|
}
|
|
521
|
+
/** Query parameters for the app rankings endpoint. */
|
|
522
|
+
interface AppRankingsParams {
|
|
523
|
+
sort?: "popular" | "trending";
|
|
524
|
+
window?: "day" | "week" | "month";
|
|
525
|
+
category?: string;
|
|
526
|
+
subcategory?: string;
|
|
527
|
+
page?: number;
|
|
528
|
+
limit?: number;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Options for creating a Marketplace client. */
|
|
532
|
+
type MarketplaceOptions = RequestOptions;
|
|
533
|
+
/** Access to marketplace model data. */
|
|
96
534
|
declare class MarketplaceModels {
|
|
97
535
|
private readonly _opts;
|
|
98
536
|
constructor(_opts: MarketplaceOptions);
|
|
537
|
+
/** List models in the marketplace catalog. */
|
|
99
538
|
list(params?: {
|
|
100
539
|
limit?: number;
|
|
101
540
|
offset?: number;
|
|
102
541
|
q?: string;
|
|
103
542
|
}): Promise<ModelListResponse>;
|
|
543
|
+
/** Get detailed info for a specific model, including provider offers. */
|
|
104
544
|
get(modelId: string): Promise<ModelDetail>;
|
|
105
|
-
private _fetch;
|
|
106
545
|
}
|
|
546
|
+
/** Access to marketplace provider data. */
|
|
107
547
|
declare class MarketplaceProviders {
|
|
108
548
|
private readonly _opts;
|
|
109
549
|
constructor(_opts: MarketplaceOptions);
|
|
550
|
+
/** List providers on the marketplace. */
|
|
110
551
|
list(params?: {
|
|
111
552
|
sort?: string;
|
|
112
553
|
q?: string;
|
|
113
554
|
}): Promise<ProviderListResponse>;
|
|
555
|
+
/** Get detailed info for a specific provider. */
|
|
114
556
|
get(slug: string): Promise<ProviderDetail>;
|
|
115
|
-
private _fetch;
|
|
116
557
|
}
|
|
558
|
+
/** Access to marketplace rankings (models and apps). */
|
|
559
|
+
declare class MarketplaceRankings {
|
|
560
|
+
private readonly _opts;
|
|
561
|
+
constructor(_opts: MarketplaceOptions);
|
|
562
|
+
/** Get the model usage leaderboard and chart series. */
|
|
563
|
+
models(params?: ModelRankingsParams): Promise<ModelRankingsResponse>;
|
|
564
|
+
/** Get the app rankings list. */
|
|
565
|
+
apps(params?: AppRankingsParams): Promise<AppRankingsResponse>;
|
|
566
|
+
}
|
|
567
|
+
/** Client for the Onlist marketplace public API. */
|
|
117
568
|
declare class Marketplace {
|
|
569
|
+
/** Browse and search models. */
|
|
118
570
|
readonly models: MarketplaceModels;
|
|
571
|
+
/** Browse and search providers. */
|
|
119
572
|
readonly providers: MarketplaceProviders;
|
|
573
|
+
/** Model and app usage rankings. */
|
|
574
|
+
readonly rankings: MarketplaceRankings;
|
|
120
575
|
constructor(opts: MarketplaceOptions);
|
|
121
576
|
}
|
|
122
577
|
|
|
578
|
+
/** Options for creating an Onlist client. */
|
|
123
579
|
interface OnlistOptions extends Omit<ClientOptions, "apiKey" | "baseURL"> {
|
|
580
|
+
/** API key. Falls back to ONLIST_API_KEY then OPENAI_API_KEY env vars. */
|
|
124
581
|
apiKey?: string | null;
|
|
582
|
+
/**
|
|
583
|
+
* Management key (`mgmt_...`) for the account API. Falls back to
|
|
584
|
+
* ONLIST_MANAGEMENT_KEY, then to the API key.
|
|
585
|
+
*/
|
|
586
|
+
managementKey?: string | null;
|
|
587
|
+
/** Base URL for the API. Defaults to https://onlist.io/v1. */
|
|
125
588
|
baseURL?: string | null;
|
|
589
|
+
/** Maximum retry attempts for marketplace and account API calls. Defaults to 2. */
|
|
590
|
+
maxRetries?: number;
|
|
126
591
|
}
|
|
592
|
+
/** Onlist API client, extending the OpenAI SDK with marketplace and account features. */
|
|
127
593
|
declare class Onlist extends OpenAI {
|
|
594
|
+
/** Access to marketplace data: models, providers, and rankings. */
|
|
128
595
|
readonly marketplace: Marketplace;
|
|
596
|
+
/** Account balance. */
|
|
597
|
+
readonly credits: AccountCredits;
|
|
598
|
+
/** Cost and timing for individual calls. */
|
|
599
|
+
readonly generations: AccountGenerations;
|
|
600
|
+
/** Inference key management. */
|
|
601
|
+
readonly apiKeys: AccountApiKeys;
|
|
602
|
+
/** Daily usage rollups. */
|
|
603
|
+
readonly activity: AccountActivity;
|
|
604
|
+
/** Sign in with Onlist — the PKCE code exchange. */
|
|
605
|
+
readonly oauth: AccountOAuth;
|
|
606
|
+
/** The credential the account API is using. */
|
|
607
|
+
readonly managementKey: string | undefined;
|
|
129
608
|
constructor(opts?: OnlistOptions);
|
|
130
609
|
}
|
|
131
610
|
|
|
611
|
+
/** Base error class for all Onlist SDK errors. */
|
|
132
612
|
declare class OnlistError extends Error {
|
|
133
613
|
constructor(message: string);
|
|
134
614
|
}
|
|
615
|
+
/** Error thrown when an API request fails. */
|
|
135
616
|
declare class APIError extends OnlistError {
|
|
136
617
|
readonly status: number;
|
|
137
618
|
readonly type: string | null;
|
|
@@ -146,23 +627,47 @@ declare class APIError extends OnlistError {
|
|
|
146
627
|
body?: unknown;
|
|
147
628
|
});
|
|
148
629
|
}
|
|
630
|
+
/** Error thrown when the API key is invalid or missing. */
|
|
149
631
|
declare class AuthenticationError extends APIError {
|
|
150
632
|
constructor(message?: string, opts?: Partial<ConstructorParameters<typeof APIError>[1]>);
|
|
151
633
|
}
|
|
634
|
+
/** Error thrown when the account balance is insufficient. */
|
|
152
635
|
declare class InsufficientBalanceError extends APIError {
|
|
153
636
|
constructor(message?: string, opts?: Partial<ConstructorParameters<typeof APIError>[1]>);
|
|
154
637
|
}
|
|
638
|
+
/** Error thrown when the request is rate-limited. */
|
|
155
639
|
declare class RateLimitError extends APIError {
|
|
156
640
|
constructor(message?: string, opts?: Partial<ConstructorParameters<typeof APIError>[1]>);
|
|
157
641
|
}
|
|
642
|
+
/** Error thrown when no matching provider is available. */
|
|
158
643
|
declare class ProviderError extends APIError {
|
|
159
644
|
constructor(message: string, opts: ConstructorParameters<typeof APIError>[1]);
|
|
160
645
|
}
|
|
646
|
+
/** Error thrown when a requested resource is not found. */
|
|
647
|
+
declare class NotFoundError extends APIError {
|
|
648
|
+
constructor(message?: string, opts?: Partial<ConstructorParameters<typeof APIError>[1]>);
|
|
649
|
+
}
|
|
650
|
+
/** Error thrown when the request is malformed or its parameters are rejected. */
|
|
651
|
+
declare class BadRequestError extends APIError {
|
|
652
|
+
constructor(message?: string, opts?: Partial<ConstructorParameters<typeof APIError>[1]>);
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Error thrown when the credential is valid but not allowed here.
|
|
656
|
+
*
|
|
657
|
+
* Most commonly: an inference key (`sk-...`) was used on an endpoint that
|
|
658
|
+
* only accepts a management key (`mgmt_...`). The server's message is passed
|
|
659
|
+
* through unchanged.
|
|
660
|
+
*/
|
|
661
|
+
declare class PermissionDeniedError extends APIError {
|
|
662
|
+
constructor(message?: string, opts?: Partial<ConstructorParameters<typeof APIError>[1]>);
|
|
663
|
+
}
|
|
161
664
|
|
|
665
|
+
/** Maximum price limits per token type (USD per million tokens). */
|
|
162
666
|
interface MaxPrice {
|
|
163
667
|
prompt?: number;
|
|
164
668
|
completion?: number;
|
|
165
669
|
}
|
|
670
|
+
/** Provider routing configuration for the Onlist marketplace. */
|
|
166
671
|
interface ProviderRouting {
|
|
167
672
|
only?: string[];
|
|
168
673
|
sort?: "price" | "throughput";
|
|
@@ -173,6 +678,13 @@ interface ProviderRouting {
|
|
|
173
678
|
max_price?: MaxPrice;
|
|
174
679
|
}
|
|
175
680
|
|
|
176
|
-
declare
|
|
681
|
+
declare module "openai/resources/chat/completions/completions" {
|
|
682
|
+
interface ChatCompletionCreateParamsBase {
|
|
683
|
+
/** Onlist provider routing configuration. */
|
|
684
|
+
provider?: ProviderRouting;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
declare const VERSION = "0.3.0";
|
|
177
689
|
|
|
178
|
-
export { APIError, type Architecture, AuthenticationError, InsufficientBalanceError, Marketplace, MarketplaceModels, type MarketplaceOptions, MarketplaceProviders, type MaxPrice, type Model, type ModelDetail, type ModelListResponse, Onlist, OnlistError, type OnlistOptions, type Pricing, type Provider, type ProviderDetail, ProviderError, type ProviderListResponse, type ProviderOffer, type ProviderRouting, RateLimitError, type TopProvider, VERSION };
|
|
690
|
+
export { APIError, type APIKey, AccountActivity, AccountApiKeys, AccountCredits, AccountGenerations, AccountOAuth, type AccountOptions, type ActivityParams, type ActivityRow, type AppRanking, type AppRankingsParams, type AppRankingsResponse, type Architecture, AuthenticationError, BadRequestError, type CreateKeyParams, type CreatedKey, type Credits, type CurrentKey, type ExchangedKey, type Generation, InsufficientBalanceError, type ListKeysParams, Marketplace, MarketplaceModels, type MarketplaceOptions, MarketplaceProviders, MarketplaceRankings, type MaxPrice, type Model, type ModelDetail, type ModelListResponse, type ModelRanking, type ModelRankingsParams, type ModelRankingsResponse, type ModelSeriesPoint, NotFoundError, Onlist, OnlistError, type OnlistOptions, PermissionDeniedError, type PkcePair, type Pricing, type Provider, type ProviderDetail, ProviderError, type ProviderListResponse, type ProviderOffer, type ProviderRouting, type RateLimit, RateLimitError, type TopProvider, type UpdateKeyParams, VERSION, exchangeAuthCode, generatePkce };
|