runbios-sdk 0.2.1-dev.62

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/dist/client.js ADDED
@@ -0,0 +1,408 @@
1
+ import { VERSION } from './index.js';
2
+ // ============================================================================
3
+ // ApiError
4
+ // ============================================================================
5
+ /**
6
+ * Typed error thrown by every SDK method when the API returns a non-2xx status.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * try {
11
+ * await client.training.get('bad_id');
12
+ * } catch (err) {
13
+ * if (err instanceof ApiError && err.status === 404) {
14
+ * console.log('Job not found');
15
+ * }
16
+ * }
17
+ * ```
18
+ *
19
+ * Availability rejections are self-recoverable: when the selected GPU is no
20
+ * longer bookable at submit time the API answers 409 with a machine code and
21
+ * the currently bookable alternatives, and the SDK surfaces them typed:
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * try {
26
+ * await client.training.create({ ...req, gpu_type: 'A100_80GB' });
27
+ * } catch (err) {
28
+ * if (err instanceof ApiError && err.code === 'SELECTED_GPU_UNAVAILABLE') {
29
+ * const next = err.availableGpus?.[0];
30
+ * if (next) await client.training.create({ ...req, gpu_type: next.gpu_type });
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ export class ApiError extends Error {
36
+ /** HTTP status code (e.g. 401, 404, 500). */
37
+ status;
38
+ /** Machine-readable error code from the API, if provided. */
39
+ code;
40
+ /** Server-assigned request ID for support / debugging. */
41
+ requestId;
42
+ /**
43
+ * The full parsed error response body. Availability rejections carry
44
+ * structured recovery data here (`available_gpus`, `checked_at`).
45
+ */
46
+ body;
47
+ /**
48
+ * Bookable-now GPU alternatives on availability rejections
49
+ * (SELECTED_GPU_UNAVAILABLE / CAPACITY_UNAVAILABLE); undefined otherwise.
50
+ * Every entry fit the requested model when `checkedAt` was stamped —
51
+ * resubmit with one of these and nothing else changed.
52
+ */
53
+ availableGpus;
54
+ /** Availability snapshot time behind an availability rejection. */
55
+ checkedAt;
56
+ constructor(status, body) {
57
+ const err = body.error;
58
+ const nested = typeof err === 'object' && err !== null ? err : null;
59
+ const msg = body.detail
60
+ || (nested ? String(nested.message || nested.detail || '') : '')
61
+ || (typeof err === 'string' ? err : '')
62
+ || body.message
63
+ || `API error ${status}`;
64
+ super(msg);
65
+ this.name = 'ApiError';
66
+ this.status = status;
67
+ this.code = (nested ? String(nested.code || '') : body.code) || undefined;
68
+ this.requestId = body.request_id;
69
+ this.body = body;
70
+ const flat = nestedErrorBody(body);
71
+ const alts = flat.available_gpus ?? flat.available_alternatives;
72
+ this.availableGpus = Array.isArray(alts) && alts.length > 0 ? alts : undefined;
73
+ this.checkedAt = flat.checked_at;
74
+ }
75
+ }
76
+ /**
77
+ * Flatten the standard `{ error: { ... } }` envelope over the legacy top-level
78
+ * fields so structured capacity data is found in either shape. @internal
79
+ */
80
+ function nestedErrorBody(body) {
81
+ const err = body.error;
82
+ if (typeof err === 'object' && err !== null) {
83
+ return { ...body, ...err };
84
+ }
85
+ return body;
86
+ }
87
+ /**
88
+ * The one transient GPU-rejection code: the GPU is not in stock right now, so
89
+ * waiting or joining the capacity queue can still succeed.
90
+ */
91
+ export const CAPACITY_UNAVAILABLE_CODE = 'CAPACITY_UNAVAILABLE';
92
+ /**
93
+ * The permanent GPU-rejection codes (HTTP 400). Each is a fixed fact about the
94
+ * request: the model does not fit on that GPU type, the count is below the
95
+ * model's minimum, the count cannot split the model, or the serving engine
96
+ * cannot run that card at all. Stock is irrelevant to all four, so the capacity
97
+ * queue is never offered for them and retrying the same request never helps.
98
+ */
99
+ export const PERMANENT_GPU_CODES = [
100
+ 'GPU_TYPE_TOO_SMALL',
101
+ 'GPU_COUNT_BELOW_MINIMUM',
102
+ 'GPU_COUNT_INVALID',
103
+ 'GPU_TYPE_UNSUPPORTED',
104
+ ];
105
+ /**
106
+ * Typed error for the standard GPU-rejection body, shared by training and
107
+ * inference. Covers BOTH the 409 stock miss and the 400 permanent rejections,
108
+ * so one `catch` reaches every case that carries recovery data. Carries the
109
+ * rejection class (`reason`), the explicit server-computed `minimumRequirement`
110
+ * (min_gpus / valid_counts, never pick below them), and the canonical bookable
111
+ * alternatives via {@link ApiError.availableGpus}. Instanceof-compatible with
112
+ * ApiError so existing handlers keep working.
113
+ *
114
+ * Branch on {@link GpuRejectionError.queueOffered} (or `.permanent`), never on
115
+ * the status or the code, to decide whether offering "wait for capacity" makes
116
+ * sense. `CapacityUnavailableError` is a kept alias of this class.
117
+ */
118
+ export class GpuRejectionError extends ApiError {
119
+ /**
120
+ * insufficient_stock | below_model_minimum | invalid_gpu_count |
121
+ * model_too_large | gpu_unsupported.
122
+ */
123
+ reason;
124
+ /** The explicit minimum block for the model (selected type + per-type table). */
125
+ minimumRequirement;
126
+ /** The selection the rejection was about. */
127
+ selected;
128
+ /**
129
+ * True only when waiting for capacity is a real option. False for every
130
+ * permanent rejection: do not offer the queue, and do not retry unchanged.
131
+ */
132
+ queueOffered;
133
+ /** Whether the capacity queue may be joined instead. */
134
+ queueEligible;
135
+ /**
136
+ * 1-based rank of the gpu_priorities entry the rejection is about, when it
137
+ * came from a submitted ladder.
138
+ */
139
+ gpuPrioritiesEntry;
140
+ constructor(status, body) {
141
+ super(status, body);
142
+ const flat = nestedErrorBody(body);
143
+ this.reason = flat.reason;
144
+ this.minimumRequirement = flat.minimum_requirement;
145
+ this.selected = flat.selected;
146
+ this.gpuPrioritiesEntry = flat.gpu_priorities_entry;
147
+ // A body from an older service carries no queue_offered; treat its absence
148
+ // as "offered" only when the code is the stock-miss code, so a permanent
149
+ // rejection is never silently turned back into a queue offer.
150
+ this.queueOffered = flat.queue_offered !== undefined
151
+ ? flat.queue_offered === true
152
+ : !isPermanentGpuCode(this.code);
153
+ this.queueEligible = flat.queue_eligible === true && this.queueOffered;
154
+ this.name = this.permanent ? 'GpuRejectionError' : 'CapacityUnavailableError';
155
+ }
156
+ /**
157
+ * True when the request can never succeed as submitted, whatever happens to
158
+ * stock. Only a different GPU type or count helps.
159
+ */
160
+ get permanent() {
161
+ return isPermanentGpuCode(this.code) || this.queueOffered === false;
162
+ }
163
+ }
164
+ /**
165
+ * Historical name for {@link GpuRejectionError}. It is the SAME class, so
166
+ * `err instanceof CapacityUnavailableError` still catches every rejection,
167
+ * including the permanent ones that now answer 400 with their own codes.
168
+ */
169
+ export const CapacityUnavailableError = GpuRejectionError;
170
+ /**
171
+ * Machine codes the services answer with while a surface is pre-launch
172
+ * (HTTP 403): TRAINING_COMING_SOON from POST /api/training/jobs,
173
+ * DATASETS_COMING_SOON from the dataset creation endpoints (upload,
174
+ * uploads/initiate, register-hf, integration import).
175
+ */
176
+ export const COMING_SOON_CODES = ['TRAINING_COMING_SOON', 'DATASETS_COMING_SOON'];
177
+ /**
178
+ * Raised when a pre-launch surface rejects a creation call: fine-tuning and
179
+ * datasets launch soon, so training.create and dataset upload/import/register
180
+ * answer 403 with one of {@link COMING_SOON_CODES}. Read and lifecycle methods
181
+ * (list, get, status, stop, resume, delete, preview) are unaffected.
182
+ *
183
+ * The service is the authority: the SDK never blocks client-side, so when the
184
+ * gate lifts at launch every SDK version works again without an upgrade. This
185
+ * verdict is a deliberate product state, not an outage — retrying in a loop
186
+ * cannot succeed while the gate is on.
187
+ */
188
+ export class ComingSoonError extends ApiError {
189
+ constructor(status, body) {
190
+ super(status, body);
191
+ this.name = 'ComingSoonError';
192
+ }
193
+ }
194
+ /** Whether a machine code is one of the permanent GPU rejections. */
195
+ export function isPermanentGpuCode(code) {
196
+ return typeof code === 'string' && PERMANENT_GPU_CODES.includes(code);
197
+ }
198
+ /**
199
+ * The machine code that goes with a rejection `reason`, mirroring the service's
200
+ * mapping so a client-synthesized rejection is indistinguishable from the
201
+ * server's. An unknown reason falls back to the stock-miss code.
202
+ */
203
+ export function gpuRejectionCodeForReason(reason) {
204
+ switch (reason) {
205
+ case 'model_too_large': return 'GPU_TYPE_TOO_SMALL';
206
+ case 'below_model_minimum': return 'GPU_COUNT_BELOW_MINIMUM';
207
+ case 'invalid_gpu_count': return 'GPU_COUNT_INVALID';
208
+ case 'gpu_unsupported': return 'GPU_TYPE_UNSUPPORTED';
209
+ default: return CAPACITY_UNAVAILABLE_CODE;
210
+ }
211
+ }
212
+ /**
213
+ * Map a non-2xx body to the most specific typed error. The service is the
214
+ * authority: any GPU-rejection code becomes {@link GpuRejectionError} so
215
+ * callers read `.availableGpus`/`.minimumRequirement`/`.queueOffered` without
216
+ * string matching. @internal
217
+ */
218
+ export function buildApiError(status, body) {
219
+ const err = body.error;
220
+ const nested = typeof err === 'object' && err !== null ? err : null;
221
+ const code = (nested ? String(nested.code || '') : body.code) || undefined;
222
+ if (code === CAPACITY_UNAVAILABLE_CODE || isPermanentGpuCode(code)) {
223
+ return new GpuRejectionError(status, body);
224
+ }
225
+ if (code && COMING_SOON_CODES.includes(code)) {
226
+ return new ComingSoonError(status, body);
227
+ }
228
+ return new ApiError(status, body);
229
+ }
230
+ // ============================================================================
231
+ // Environment defaults
232
+ // ============================================================================
233
+ /**
234
+ * Read an environment variable, tolerating browser bundles where `process`
235
+ * does not exist. Returns undefined for missing or empty values.
236
+ */
237
+ function envVar(name) {
238
+ if (typeof process === 'undefined' || !process.env)
239
+ return undefined;
240
+ const value = process.env[name];
241
+ return value && value.trim() !== '' ? value.trim() : undefined;
242
+ }
243
+ /**
244
+ * Default API key when the config omits one. Falls back to the
245
+ * `RUNBIOS_API_KEY` environment variable (legacy: `BIOS_API_KEY`). @internal
246
+ */
247
+ export function envApiKey() {
248
+ return envVar('RUNBIOS_API_KEY') ?? envVar('BIOS_API_KEY');
249
+ }
250
+ /**
251
+ * Inference key when the config omits one. Falls back to the
252
+ * `RUNBIOS_INFERENCE_KEY` environment variable (legacy: `BIOS_INFERENCE_KEY`),
253
+ * then to the API key at the call site: a platform key carrying the serverless
254
+ * scope calls `/v1` directly. @internal
255
+ */
256
+ export function envInferenceKey() {
257
+ return envVar('RUNBIOS_INFERENCE_KEY') ?? envVar('BIOS_INFERENCE_KEY');
258
+ }
259
+ /**
260
+ * Default base URL when the config omits one. Falls back to the
261
+ * `RUNBIOS_BASE_URL` environment variable (legacy: `BIOS_BASE_URL`). @internal
262
+ */
263
+ export function envBaseUrl() {
264
+ return envVar('RUNBIOS_BASE_URL') ?? envVar('BIOS_BASE_URL');
265
+ }
266
+ // ============================================================================
267
+ // HttpClient — shared HTTP transport used by resource modules via composition
268
+ // ============================================================================
269
+ export class HttpClient {
270
+ baseUrl;
271
+ apiKey;
272
+ accessToken;
273
+ orgId;
274
+ workspaceIdValue;
275
+ timeout;
276
+ constructor(config) {
277
+ // Default host stays api.runbios.ai for now; cutover to api.runbios.ai is
278
+ // planned once its DNS exists.
279
+ this.baseUrl = (config.baseUrl || envBaseUrl() || 'https://api-dev.runbios.ai').replace(/\/+$/, '');
280
+ this.apiKey = config.apiKey ?? envApiKey();
281
+ this.accessToken = config.accessToken;
282
+ this.orgId = config.orgId;
283
+ this.workspaceIdValue = config.workspaceId;
284
+ this.timeout = config.timeout ?? 30_000;
285
+ if (!this.apiKey && !this.accessToken) {
286
+ throw new Error('RunBiOS: either apiKey or accessToken is required (or set the RUNBIOS_API_KEY environment variable)');
287
+ }
288
+ }
289
+ /** Workspace configured on the client, used by multipart/control-plane helpers. */
290
+ get workspaceId() {
291
+ return this.workspaceIdValue;
292
+ }
293
+ // --------------------------------------------------------------------------
294
+ // Internal helpers
295
+ // --------------------------------------------------------------------------
296
+ buildHeaders(extra) {
297
+ const h = {
298
+ 'User-Agent': `bios-sdk/${VERSION}`,
299
+ ...extra,
300
+ };
301
+ if (this.apiKey) {
302
+ h['X-API-Key'] = this.apiKey;
303
+ }
304
+ else if (this.accessToken) {
305
+ h['Authorization'] = `Bearer ${this.accessToken}`;
306
+ }
307
+ if (this.orgId)
308
+ h['X-Org-ID'] = this.orgId;
309
+ if (this.workspaceIdValue)
310
+ h['X-Workspace-ID'] = this.workspaceIdValue;
311
+ return h;
312
+ }
313
+ // --------------------------------------------------------------------------
314
+ // Public request methods — used by resource classes via composition
315
+ // --------------------------------------------------------------------------
316
+ /**
317
+ * Send a JSON request and parse the response.
318
+ * Throws {@link ApiError} on non-2xx responses.
319
+ */
320
+ async request(method, path, body, extraHeaders) {
321
+ const url = `${this.baseUrl}${path}`;
322
+ const headers = this.buildHeaders({
323
+ 'Content-Type': 'application/json',
324
+ 'Accept': 'application/json',
325
+ ...extraHeaders,
326
+ });
327
+ const controller = new AbortController();
328
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
329
+ let res;
330
+ try {
331
+ res = await fetch(url, {
332
+ method,
333
+ headers,
334
+ body: body !== undefined ? JSON.stringify(body) : undefined,
335
+ signal: controller.signal,
336
+ });
337
+ }
338
+ catch (err) {
339
+ if (err instanceof DOMException && err.name === 'AbortError') {
340
+ throw new ApiError(0, { error: `Request timed out after ${this.timeout}ms` });
341
+ }
342
+ throw err;
343
+ }
344
+ finally {
345
+ clearTimeout(timeoutId);
346
+ }
347
+ const data = await res.json().catch(() => ({}));
348
+ if (!res.ok) {
349
+ throw buildApiError(res.status, data);
350
+ }
351
+ return data;
352
+ }
353
+ /** Send a GET request. */
354
+ fetchGet(path, extraHeaders) {
355
+ return this.request('GET', path, undefined, extraHeaders);
356
+ }
357
+ /** Send a POST request with a JSON body. */
358
+ fetchPost(path, body, extraHeaders) {
359
+ return this.request('POST', path, body, extraHeaders);
360
+ }
361
+ /** Send a PATCH request with a JSON body. */
362
+ fetchPatch(path, body, extraHeaders) {
363
+ return this.request('PATCH', path, body, extraHeaders);
364
+ }
365
+ /** Send a PUT request with a JSON body. */
366
+ fetchPut(path, body, extraHeaders) {
367
+ return this.request('PUT', path, body, extraHeaders);
368
+ }
369
+ /** Send a DELETE request. */
370
+ fetchDelete(path, body, extraHeaders) {
371
+ return this.request('DELETE', path, body, extraHeaders);
372
+ }
373
+ /**
374
+ * Upload a file via multipart/form-data.
375
+ * The caller is responsible for constructing the FormData.
376
+ * Throws {@link ApiError} on non-2xx responses.
377
+ */
378
+ async fetchUpload(path, formData) {
379
+ const url = `${this.baseUrl}${path}`;
380
+ // Do NOT set Content-Type — fetch sets the boundary automatically for FormData.
381
+ const headers = this.buildHeaders({ 'Accept': 'application/json' });
382
+ const controller = new AbortController();
383
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
384
+ let res;
385
+ try {
386
+ res = await fetch(url, {
387
+ method: 'POST',
388
+ headers,
389
+ body: formData,
390
+ signal: controller.signal,
391
+ });
392
+ }
393
+ catch (err) {
394
+ if (err instanceof DOMException && err.name === 'AbortError') {
395
+ throw new ApiError(0, { error: `Upload timed out after ${this.timeout}ms` });
396
+ }
397
+ throw err;
398
+ }
399
+ finally {
400
+ clearTimeout(timeoutId);
401
+ }
402
+ const data = await res.json().catch(() => ({}));
403
+ if (!res.ok) {
404
+ throw buildApiError(res.status, data);
405
+ }
406
+ return data;
407
+ }
408
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * runbios-sdk — Official TypeScript SDK for the Run BiOS fine-tuning platform.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { RunBiOS } from 'runbios-sdk';
7
+ *
8
+ * const client = new RunBiOS({
9
+ * apiKey: 'bios-...',
10
+ * });
11
+ *
12
+ * // Search for models
13
+ * const models = await client.models.search({ query: 'llama' });
14
+ *
15
+ * // Create a training job
16
+ * const job = await client.training.create({
17
+ * model: 'meta-llama/Llama-3.1-8B-Instruct',
18
+ * datasetId: 'ds_abc123',
19
+ * method: 'sft',
20
+ * adapter: 'lora',
21
+ * });
22
+ * ```
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ import type { BiOSConfig, ApiKeyIntrospection } from './types.js';
27
+ import { Models } from './resources/models.js';
28
+ import { Datasets } from './resources/datasets.js';
29
+ import { Training } from './resources/training.js';
30
+ import { Wallet } from './resources/wallet.js';
31
+ import { GPU } from './resources/gpu.js';
32
+ import { Inference } from './resources/inference.js';
33
+ /**
34
+ * SDK version. Sent as part of the User-Agent header.
35
+ * Must match package.json "version" -- enforced by a contract test.
36
+ */
37
+ export declare const VERSION = "0.2.1-dev.62";
38
+ export declare class RunBiOS {
39
+ /** Search models, fetch configs, check adapter compatibility. */
40
+ readonly models: Models;
41
+ /** Upload, import, preview, and manage training datasets. */
42
+ readonly datasets: Datasets;
43
+ /** Create, monitor, stop, and resume fine-tuning jobs. */
44
+ readonly training: Training;
45
+ /** Check wallet balance. */
46
+ readonly wallet: Wallet;
47
+ /** View GPU pricing and get hardware recommendations. */
48
+ readonly gpu: GPU;
49
+ /**
50
+ * Model-serving inference. Validate, create, monitor, stop, and delete
51
+ * serving deployments, plus OpenAI-compatible non-streaming and SSE calls.
52
+ */
53
+ readonly inference: Inference;
54
+ /** @internal */
55
+ private readonly _http;
56
+ constructor(config: BiOSConfig);
57
+ introspect(): Promise<ApiKeyIntrospection>;
58
+ }
59
+ /** @deprecated Use {@link RunBiOS}. */
60
+ export { RunBiOS as BiOS };
61
+ export { ApiError, GpuRejectionError, CapacityUnavailableError, ComingSoonError, CAPACITY_UNAVAILABLE_CODE, COMING_SOON_CODES, PERMANENT_GPU_CODES, isPermanentGpuCode, gpuRejectionCodeForReason, } from './client.js';
62
+ export { Models } from './resources/models.js';
63
+ export { Datasets } from './resources/datasets.js';
64
+ export { Training } from './resources/training.js';
65
+ export { Wallet } from './resources/wallet.js';
66
+ export { GPU, type GPURecommendation } from './resources/gpu.js';
67
+ export { Inference, validateChatRequest, parseSSE, buildInferenceRequest, contextSizingBasis, type ContextSizingBasis, CONTEXT_DEFAULT_CEILING, CONTEXT_EDITABLE_FLOOR, type ChatMessage, type FunctionTool, type ChatCompletionParams, type ChatCompletionResponse, type ChatCompletionChunk, } from './resources/inference.js';
68
+ export type { BiOSConfig, PaginatedResponse, ApiErrorBody, AvailableGpuAlternative, CapacityMinimumRequirement, InferenceBookingAccepted, Model, ModelSearchParams, ModelSearchResponse, ModelDetailResponse, ModelConfig, Dataset, DatasetListParams, DatasetListResponse, DatasetUploadParams, DatasetPreview, DatasetPreviewParams, DatasetImportHFParams, DatasetRegisterHFParams, DatasetHubSearchParams, DatasetHubPreviewParams, DatasetValidation, DatasetFormatVariant, DatasetFormatSpec, DatasetFormatSpecs, DatasetStorageUsage, TrainingMethod, RLHFAlgorithm, AdapterType, TrainingJobStatus, TrainingStatusFilter, TrainingCreateParams, TrainingListParams, TrainingListResponse, TrainingJob, TrainingMetrics, MetricPoint, MetricGraphConfig, TrainingCheckpoint, TrainingLogs, TrainingLogEntry, TrainingStopResponse, TrainingResumeResponse, CanonicalTrainingRequest, TrainingPreflightDataset, TrainingPreflightWarning, TrainingPreflightResponse, TrainingCapabilityChoice, TrainingConfigFieldCapability, TrainingCapabilities, GPUChoice, WalletBalance, Transaction, TransactionListResponse, TransactionListParams, GPUInfo, GPUPricingResponse, GPUOptionsParams, GPUOption, GPUOptionSuggestion, GPUOptionsResponse, InferenceStatus, InferenceCreateParams, InferenceUpdateParams, InferenceDeployment, InferenceDeploymentSummary, InferenceCreateResponse, InferenceListResponse, InferenceUpdateResponse, InferenceLifecycleResponse, InferenceDeleteResponse, InferenceGPUOptionMarket, InferenceGPUOption, InferenceGPUAlternative, InferenceGPUOptionsParams, InferenceGPUOptionsResponse, InferenceCanonicalRequest, InferencePreflightWarning, InferencePreflightResponse, AdapterCompatibility, AdapterCompatibilityResponse, AdapterCompatibilityParams, SupportedArchitecture, ArchitectureScope, SupportedArchitecturesResponse, ApiKey, ApiKeyScope, ApiKeyIntrospection, Organization, OrgMember, OrgInvite, Workspace, Integration, IntegrationCreateParams, StorageUsage, StorageObject, } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * runbios-sdk — Official TypeScript SDK for the Run BiOS fine-tuning platform.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { RunBiOS } from 'runbios-sdk';
7
+ *
8
+ * const client = new RunBiOS({
9
+ * apiKey: 'bios-...',
10
+ * });
11
+ *
12
+ * // Search for models
13
+ * const models = await client.models.search({ query: 'llama' });
14
+ *
15
+ * // Create a training job
16
+ * const job = await client.training.create({
17
+ * model: 'meta-llama/Llama-3.1-8B-Instruct',
18
+ * datasetId: 'ds_abc123',
19
+ * method: 'sft',
20
+ * adapter: 'lora',
21
+ * });
22
+ * ```
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ import { HttpClient, envInferenceKey } from './client.js';
27
+ import { Models } from './resources/models.js';
28
+ import { Datasets } from './resources/datasets.js';
29
+ import { Training } from './resources/training.js';
30
+ import { Wallet } from './resources/wallet.js';
31
+ import { GPU } from './resources/gpu.js';
32
+ import { Inference } from './resources/inference.js';
33
+ /**
34
+ * SDK version. Sent as part of the User-Agent header.
35
+ * Must match package.json "version" -- enforced by a contract test.
36
+ */
37
+ export const VERSION = '0.2.1-dev.62';
38
+ export class RunBiOS {
39
+ /** Search models, fetch configs, check adapter compatibility. */
40
+ models;
41
+ /** Upload, import, preview, and manage training datasets. */
42
+ datasets;
43
+ /** Create, monitor, stop, and resume fine-tuning jobs. */
44
+ training;
45
+ /** Check wallet balance. */
46
+ wallet;
47
+ /** View GPU pricing and get hardware recommendations. */
48
+ gpu;
49
+ /**
50
+ * Model-serving inference. Validate, create, monitor, stop, and delete
51
+ * serving deployments, plus OpenAI-compatible non-streaming and SSE calls.
52
+ */
53
+ inference;
54
+ /** @internal */
55
+ _http;
56
+ constructor(config) {
57
+ const http = new HttpClient(config);
58
+ this._http = http;
59
+ this.models = new Models(http);
60
+ this.datasets = new Datasets(http);
61
+ this.training = new Training(http);
62
+ this.wallet = new Wallet(http);
63
+ this.gpu = new GPU(http);
64
+ // Inference-key resolution, most specific first:
65
+ // 1. an explicit inferenceKey (a per-deployment sk-bios-... key)
66
+ // 2. RUNBIOS_INFERENCE_KEY from the environment (legacy: BIOS_INFERENCE_KEY)
67
+ // 3. the control-plane apiKey / RUNBIOS_API_KEY (legacy: BIOS_API_KEY)
68
+ // (3) exists because a workspace platform key carrying the serverless scope
69
+ // calls /v1 directly, so new RunBiOS({ apiKey }).inference.chatCompletions()
70
+ // must work without passing the same key twice. Inference applies (2)/(3)
71
+ // itself; passing apiKey here only supplies the config-level fallback.
72
+ this.inference = new Inference({
73
+ inferenceKey: config.inferenceKey || envInferenceKey() || config.apiKey,
74
+ baseUrl: config.inferenceBaseUrl || config.baseUrl,
75
+ timeout: config.inferenceTimeout,
76
+ }, http);
77
+ }
78
+ async introspect() {
79
+ return this._http.fetchGet('/api/api-keys/introspect');
80
+ }
81
+ }
82
+ /** @deprecated Use {@link RunBiOS}. */
83
+ export { RunBiOS as BiOS };
84
+ // ---------------------------------------------------------------------------
85
+ // Re-exports
86
+ // ---------------------------------------------------------------------------
87
+ export { ApiError, GpuRejectionError, CapacityUnavailableError, ComingSoonError, CAPACITY_UNAVAILABLE_CODE, COMING_SOON_CODES, PERMANENT_GPU_CODES, isPermanentGpuCode, gpuRejectionCodeForReason, } from './client.js';
88
+ export { Models } from './resources/models.js';
89
+ export { Datasets } from './resources/datasets.js';
90
+ export { Training } from './resources/training.js';
91
+ export { Wallet } from './resources/wallet.js';
92
+ export { GPU } from './resources/gpu.js';
93
+ export { Inference, validateChatRequest, parseSSE, buildInferenceRequest, contextSizingBasis, CONTEXT_DEFAULT_CEILING, CONTEXT_EDITABLE_FLOOR, } from './resources/inference.js';