bios-sdk 0.1.0 → 0.1.1-dev.13

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 CHANGED
@@ -14,7 +14,7 @@ npm install bios-sdk
14
14
  import { BiOS } from 'bios-sdk';
15
15
 
16
16
  const client = new BiOS({
17
- apiKey: 'usf-...',
17
+ apiKey: 'bios-...',
18
18
  });
19
19
 
20
20
  // Search for models
@@ -40,12 +40,28 @@ console.log(`Job ${job.id} created`);
40
40
 
41
41
  ### API Key (recommended)
42
42
 
43
+ API keys start with `bios-` (legacy `usf-` keys stay valid).
44
+
43
45
  ```typescript
44
46
  const client = new BiOS({
45
- apiKey: 'usf-...',
47
+ apiKey: 'bios-...',
46
48
  });
47
49
  ```
48
50
 
51
+ ### Environment Variables
52
+
53
+ When `apiKey` or `baseUrl` is omitted from the config, the SDK reads them
54
+ from the environment:
55
+
56
+ ```bash
57
+ export BIOS_API_KEY=bios-...
58
+ export BIOS_BASE_URL=https://api.usbios.ai # optional; this is the default
59
+ ```
60
+
61
+ ```typescript
62
+ const client = new BiOS({}); // uses BIOS_API_KEY / BIOS_BASE_URL
63
+ ```
64
+
49
65
  ### JWT Access Token
50
66
 
51
67
  ```typescript
@@ -68,8 +84,8 @@ without an explicit replay acknowledgement from the endpoint.
68
84
 
69
85
  ```typescript
70
86
  const client = new BiOS({
71
- apiKey: 'usf-control-plane-key',
72
- inferenceKey: 'sk-usf-deployment-key',
87
+ apiKey: 'bios-control-plane-key',
88
+ inferenceKey: 'sk-bios-deployment-key',
73
89
  // inferenceBaseUrl: 'https://api-dev.usbios.ai', // explicit in dev
74
90
  });
75
91
 
@@ -275,11 +291,11 @@ try {
275
291
 
276
292
  | Option | Default | Description |
277
293
  |--------|---------|-------------|
278
- | `apiKey` | | API key (`usf-...`) |
294
+ | `apiKey` | `BIOS_API_KEY` env var | API key (`bios-...`; legacy `usf-...` keys stay valid) |
279
295
  | `accessToken` | — | JWT access token |
280
296
  | `orgId` | — | Organization ID (auto-resolved with API keys) |
281
297
  | `workspaceId` | — | Workspace ID (auto-resolved with API keys) |
282
- | `baseUrl` | `https://api.usbios.ai` | Canonical production hostname (release-gated; this documentation does not assert current availability). During prelaunch/dev, pass `https://api-dev.usbios.ai` explicitly. |
298
+ | `baseUrl` | `BIOS_BASE_URL` env var, then `https://api.usbios.ai` | Canonical production hostname (release-gated; this documentation does not assert current availability). During prelaunch/dev, pass `https://api-dev.usbios.ai` explicitly. |
283
299
  | `timeout` | `30000` | Request timeout in ms |
284
300
 
285
301
  ## Requirements
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BiOSConfig, ApiErrorBody } from './types.js';
1
+ import type { BiOSConfig, ApiErrorBody, AvailableGpuAlternative } from './types.js';
2
2
  /**
3
3
  * Typed error thrown by every SDK method when the API returns a non-2xx status.
4
4
  *
@@ -12,6 +12,22 @@ import type { BiOSConfig, ApiErrorBody } from './types.js';
12
12
  * }
13
13
  * }
14
14
  * ```
15
+ *
16
+ * Availability rejections are self-recoverable: when the selected GPU is no
17
+ * longer bookable at submit time the API answers 409 with a machine code and
18
+ * the currently bookable alternatives, and the SDK surfaces them typed:
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * try {
23
+ * await client.training.create({ ...req, gpu_type: 'A100_80GB' });
24
+ * } catch (err) {
25
+ * if (err instanceof ApiError && err.code === 'SELECTED_GPU_UNAVAILABLE') {
26
+ * const next = err.availableGpus?.[0];
27
+ * if (next) await client.training.create({ ...req, gpu_type: next.gpu_type });
28
+ * }
29
+ * }
30
+ * ```
15
31
  */
16
32
  export declare class ApiError extends Error {
17
33
  /** HTTP status code (e.g. 401, 404, 500). */
@@ -20,8 +36,26 @@ export declare class ApiError extends Error {
20
36
  readonly code: string | undefined;
21
37
  /** Server-assigned request ID for support / debugging. */
22
38
  readonly requestId: string | undefined;
39
+ /**
40
+ * The full parsed error response body. Availability rejections carry
41
+ * structured recovery data here (`available_gpus`, `checked_at`).
42
+ */
43
+ readonly body: ApiErrorBody;
44
+ /**
45
+ * Bookable-now GPU alternatives on availability rejections
46
+ * (SELECTED_GPU_UNAVAILABLE / CAPACITY_UNAVAILABLE); undefined otherwise.
47
+ * Every entry fit the requested model when `checkedAt` was stamped —
48
+ * resubmit with one of these and nothing else changed.
49
+ */
50
+ readonly availableGpus: AvailableGpuAlternative[] | undefined;
51
+ /** Availability snapshot time behind an availability rejection. */
52
+ readonly checkedAt: string | undefined;
23
53
  constructor(status: number, body: ApiErrorBody);
24
54
  }
55
+ /** Default API key from `BIOS_API_KEY` when the config omits one. @internal */
56
+ export declare function envApiKey(): string | undefined;
57
+ /** Default base URL from `BIOS_BASE_URL` when the config omits one. @internal */
58
+ export declare function envBaseUrl(): string | undefined;
25
59
  export declare class HttpClient {
26
60
  private readonly baseUrl;
27
61
  private readonly apiKey;
package/dist/client.js CHANGED
@@ -15,6 +15,22 @@ import { VERSION } from './index.js';
15
15
  * }
16
16
  * }
17
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
+ * ```
18
34
  */
19
35
  export class ApiError extends Error {
20
36
  /** HTTP status code (e.g. 401, 404, 500). */
@@ -23,6 +39,20 @@ export class ApiError extends Error {
23
39
  code;
24
40
  /** Server-assigned request ID for support / debugging. */
25
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;
26
56
  constructor(status, body) {
27
57
  const err = body.error;
28
58
  const nested = typeof err === 'object' && err !== null ? err : null;
@@ -36,9 +66,34 @@ export class ApiError extends Error {
36
66
  this.status = status;
37
67
  this.code = (nested ? String(nested.code || '') : body.code) || undefined;
38
68
  this.requestId = body.request_id;
69
+ this.body = body;
70
+ const alts = body.available_gpus ?? body.available_alternatives;
71
+ this.availableGpus = Array.isArray(alts) && alts.length > 0 ? alts : undefined;
72
+ this.checkedAt = body.checked_at;
39
73
  }
40
74
  }
41
75
  // ============================================================================
76
+ // Environment defaults
77
+ // ============================================================================
78
+ /**
79
+ * Read an environment variable, tolerating browser bundles where `process`
80
+ * does not exist. Returns undefined for missing or empty values.
81
+ */
82
+ function envVar(name) {
83
+ if (typeof process === 'undefined' || !process.env)
84
+ return undefined;
85
+ const value = process.env[name];
86
+ return value && value.trim() !== '' ? value.trim() : undefined;
87
+ }
88
+ /** Default API key from `BIOS_API_KEY` when the config omits one. @internal */
89
+ export function envApiKey() {
90
+ return envVar('BIOS_API_KEY');
91
+ }
92
+ /** Default base URL from `BIOS_BASE_URL` when the config omits one. @internal */
93
+ export function envBaseUrl() {
94
+ return envVar('BIOS_BASE_URL');
95
+ }
96
+ // ============================================================================
42
97
  // HttpClient — shared HTTP transport used by resource modules via composition
43
98
  // ============================================================================
44
99
  export class HttpClient {
@@ -49,14 +104,14 @@ export class HttpClient {
49
104
  workspaceIdValue;
50
105
  timeout;
51
106
  constructor(config) {
52
- this.baseUrl = (config.baseUrl || 'https://api.usbios.ai').replace(/\/+$/, '');
53
- this.apiKey = config.apiKey;
107
+ this.baseUrl = (config.baseUrl || envBaseUrl() || 'https://api-dev.usbios.ai').replace(/\/+$/, '');
108
+ this.apiKey = config.apiKey ?? envApiKey();
54
109
  this.accessToken = config.accessToken;
55
110
  this.orgId = config.orgId;
56
111
  this.workspaceIdValue = config.workspaceId;
57
112
  this.timeout = config.timeout ?? 30_000;
58
113
  if (!this.apiKey && !this.accessToken) {
59
- throw new Error('BiOS: either apiKey or accessToken is required');
114
+ throw new Error('BiOS: either apiKey or accessToken is required (or set the BIOS_API_KEY environment variable)');
60
115
  }
61
116
  }
62
117
  /** Workspace configured on the client, used by multipart/control-plane helpers. */
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * import { BiOS } from 'bios-sdk';
7
7
  *
8
8
  * const client = new BiOS({
9
- * apiKey: 'usf-...',
9
+ * apiKey: 'bios-...',
10
10
  * });
11
11
  *
12
12
  * // Search for models
@@ -30,8 +30,11 @@ import { Training } from './resources/training.js';
30
30
  import { Wallet } from './resources/wallet.js';
31
31
  import { GPU } from './resources/gpu.js';
32
32
  import { Inference } from './resources/inference.js';
33
- /** SDK version. Sent as part of the User-Agent header. */
34
- export declare const VERSION = "1.0.2";
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.1.1";
35
38
  export declare class BiOS {
36
39
  /** Search models, fetch configs, check adapter compatibility. */
37
40
  readonly models: Models;
@@ -60,4 +63,4 @@ export { Training } from './resources/training.js';
60
63
  export { Wallet } from './resources/wallet.js';
61
64
  export { GPU, type GPURecommendation } from './resources/gpu.js';
62
65
  export { Inference, validateChatRequest, parseSSE, type ChatMessage, type FunctionTool, type ChatCompletionParams, type ChatCompletionResponse, type ChatCompletionChunk, } from './resources/inference.js';
63
- export type { BiOSConfig, PaginatedResponse, ApiErrorBody, Model, ModelSearchParams, ModelSearchResponse, 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, TransactionListParams, GPUInfo, GPUPricingResponse, GPUOptionsParams, GPUOption, GPUOptionSuggestion, GPUOptionsResponse, InferenceStatus, InferenceCreateParams, InferenceUpdateParams, InferenceDeployment, 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';
66
+ export type { BiOSConfig, PaginatedResponse, ApiErrorBody, AvailableGpuAlternative, Model, ModelSearchParams, ModelSearchResponse, 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, TransactionListParams, GPUInfo, GPUPricingResponse, GPUOptionsParams, GPUOption, GPUOptionSuggestion, GPUOptionsResponse, InferenceStatus, InferenceCreateParams, InferenceUpdateParams, InferenceDeployment, 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 CHANGED
@@ -6,7 +6,7 @@
6
6
  * import { BiOS } from 'bios-sdk';
7
7
  *
8
8
  * const client = new BiOS({
9
- * apiKey: 'usf-...',
9
+ * apiKey: 'bios-...',
10
10
  * });
11
11
  *
12
12
  * // Search for models
@@ -30,8 +30,11 @@ import { Training } from './resources/training.js';
30
30
  import { Wallet } from './resources/wallet.js';
31
31
  import { GPU } from './resources/gpu.js';
32
32
  import { Inference } from './resources/inference.js';
33
- /** SDK version. Sent as part of the User-Agent header. */
34
- export const VERSION = '1.0.2';
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.1.1';
35
38
  export class BiOS {
36
39
  /** Search models, fetch configs, check adapter compatibility. */
37
40
  models;
@@ -1,4 +1,4 @@
1
- import { ApiError } from '../client.js';
1
+ import { ApiError, envBaseUrl } from '../client.js';
2
2
  import { normalizeGPUPlacement } from './gpu-priorities.js';
3
3
  const FUNCTION_NAME = /^[A-Za-z0-9_-]{1,64}$/;
4
4
  const ROLES = new Set(['system', 'developer', 'user', 'assistant', 'tool', 'function']);
@@ -280,7 +280,7 @@ export class Inference {
280
280
  _http;
281
281
  constructor(config = {}, http) {
282
282
  this.key = config.inferenceKey;
283
- this.baseUrl = (config.baseUrl || 'https://api.usbios.ai').replace(/\/+$/, '');
283
+ this.baseUrl = (config.baseUrl || envBaseUrl() || 'https://api-dev.usbios.ai').replace(/\/+$/, '');
284
284
  this.timeout = config.timeout ?? 900_000;
285
285
  this._http = http;
286
286
  }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Configuration for initializing the BIOS SDK client. */
2
2
  export interface BiOSConfig {
3
- /** API key for authentication (prefix: usf-). Mutually exclusive with accessToken. */
3
+ /** API key for authentication (prefix: bios-; legacy usf- keys stay valid). Falls back to the BIOS_API_KEY environment variable. Mutually exclusive with accessToken. */
4
4
  apiKey?: string;
5
5
  /** JWT access token for authentication. Mutually exclusive with apiKey. */
6
6
  accessToken?: string;
@@ -8,13 +8,13 @@ export interface BiOSConfig {
8
8
  orgId?: string;
9
9
  /** Workspace ID. Optional when using API keys (resolved from the key). Can override for multi-workspace keys. */
10
10
  workspaceId?: string;
11
- /** Base URL for the API. Defaults to the canonical https://api.usbios.ai hostname. */
11
+ /** Base URL for the API. Falls back to the BIOS_BASE_URL environment variable, then the canonical https://api-dev.usbios.ai hostname. */
12
12
  baseUrl?: string;
13
13
  /** Request timeout in milliseconds. Defaults to 30000. */
14
14
  timeout?: number;
15
15
  /** Default per-deployment inference key. Can be overridden per inference call. */
16
16
  inferenceKey?: string;
17
- /** Inference base URL. Defaults to baseUrl, then https://api.usbios.ai. */
17
+ /** Inference base URL. Defaults to baseUrl, then https://api-dev.usbios.ai. */
18
18
  inferenceBaseUrl?: string;
19
19
  /** End-to-end inference timeout in milliseconds. Defaults to 15 minutes. */
20
20
  inferenceTimeout?: number;
@@ -38,6 +38,27 @@ export interface ApiErrorBody {
38
38
  message?: string;
39
39
  code?: string;
40
40
  request_id?: string;
41
+ /**
42
+ * Bookable-now GPU alternatives, present on availability rejections
43
+ * (SELECTED_GPU_UNAVAILABLE / CAPACITY_UNAVAILABLE): each entry fits the
44
+ * requested model's minimum requirements and was in stock at `checked_at`.
45
+ * Pick one and resubmit — nothing else about the request needs to change.
46
+ */
47
+ available_gpus?: AvailableGpuAlternative[];
48
+ /** Same contract as `available_gpus`; some surfaces use this field name. */
49
+ available_alternatives?: AvailableGpuAlternative[];
50
+ /** When the availability snapshot behind the rejection was taken. */
51
+ checked_at?: string;
52
+ }
53
+ /** One bookable-now GPU alternative carried on an availability rejection. */
54
+ export interface AvailableGpuAlternative {
55
+ gpu_type: string;
56
+ gpu_count?: number;
57
+ available_count?: number;
58
+ price_per_hour_cents?: number;
59
+ provider?: string;
60
+ region?: string;
61
+ tier?: string;
41
62
  }
42
63
  /** A model returned from the HuggingFace-backed model search. */
43
64
  export interface Model {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bios-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-dev.13",
4
4
  "description": "Official TypeScript SDK for the BIOS training and deployment platform API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,15 +26,18 @@
26
26
  },
27
27
  "keywords": [
28
28
  "bios-sdk",
29
+ "bios",
29
30
  "fine-tuning",
30
31
  "deployment",
32
+ "fine-tuning",
31
33
  "inference",
32
34
  "llm",
33
35
  "machine-learning",
34
- "sdk"
36
+ "sdk",
37
+ "usbios"
35
38
  ],
36
39
  "author": "BIOS <bios@us.inc>",
37
- "homepage": "https://bios.us.com",
40
+ "homepage": "https://usbios.ai",
38
41
  "license": "MIT",
39
42
  "engines": {
40
43
  "node": ">=18.0.0"