@visgate_ai/client 0.2.20 → 0.3.3

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
@@ -1,6 +1,6 @@
1
1
  # @visgate_ai/client
2
2
 
3
- JavaScript/TypeScript SDK for the [Visgate API](https://visgateai.com) — one client for image and video generation across Fal, Replicate, and Runway.
3
+ JavaScript/TypeScript SDK for the [Visgate API](https://visgateai.com) — one client for image and video generation across Fal, Replicate, Runway, and RunPod deployments.
4
4
 
5
5
  Works in Node.js (18+), browsers, and with React, Vite, Next.js, and vanilla JS.
6
6
 
@@ -33,7 +33,7 @@ console.log(result.imageUrl);
33
33
 
34
34
  ## Features
35
35
 
36
- - **One client, three providers.** Fal, Replicate, and Runway behind a single API.
36
+ - **One client, multi-provider.** Fal, Replicate, Runway, and RunPod deployments behind a single API.
37
37
  - **Managed and BYOK modes.** Use Visgate-managed keys or bring your own.
38
38
  - **Promise-based API.** All methods return Promises; use `async/await` or `.then()`.
39
39
  - **Automatic retries.** Transient errors (429, 5xx) are retried with exponential backoff.
@@ -86,6 +86,7 @@ const client = new Client({
86
86
  falKey: "fal_...",
87
87
  replicateKey: "r8_...",
88
88
  runwayKey: "rw_...",
89
+ runpodKey: "rpa_...",
89
90
  });
90
91
  ```
91
92
 
@@ -205,6 +206,36 @@ const keys = await client.providers.listKeys();
205
206
  const balances = await client.providers.balances();
206
207
  ```
207
208
 
209
+ ### Deployments (RunPod BYOK)
210
+
211
+ ```javascript
212
+ // Create deployment from HuggingFace model
213
+ const created = await client.deployments.create({
214
+ hfModelId: "stabilityai/stable-diffusion-xl-base-1.0",
215
+ gpuTier: "medium",
216
+ task: "text2img",
217
+ });
218
+
219
+ // List deployments and select one
220
+ const list = await client.deployments.list();
221
+ const dep = list.deployments[0];
222
+
223
+ // Get current status/details
224
+ const detail = await client.deployments.get(dep.deploymentId);
225
+ console.log(detail.status, detail.endpointUrl);
226
+
227
+ // Run inference on ready deployment
228
+ const run = await client.deployments.run(dep.deploymentId, {
229
+ prompt: "cinematic cat portrait",
230
+ });
231
+ console.log(run);
232
+
233
+ // Optional helpers
234
+ const logs = await client.deployments.getLogs(dep.deploymentId);
235
+ const cost = await client.deployments.getCost(dep.deploymentId);
236
+ const gpus = await client.deployments.listGpus();
237
+ ```
238
+
208
239
  ### Health Check
209
240
 
210
241
  ```javascript
@@ -242,6 +273,7 @@ try {
242
273
  | `falKey` | — | Fal BYOK key |
243
274
  | `replicateKey` | — | Replicate BYOK key |
244
275
  | `runwayKey` | — | Runway BYOK key |
276
+ | `runpodKey` | — | RunPod BYOK key (`X-Runpod-Key`) |
245
277
 
246
278
  ## AsyncClient
247
279
 
@@ -256,7 +288,7 @@ const result = await client.generate("a sunset");
256
288
 
257
289
  ## Repository structure
258
290
 
259
- - **`src/`** — @visgate_ai/client (client library): `generate`, `images`, `videos`, `models`, `requests` (async status), `usage`, `providers`, `billing`
291
+ - **`src/`** — @visgate_ai/client (client library): `generate`, `images`, `videos`, `models`, `requests` (async status), `usage`, `providers`, `deployments`, `billing`
260
292
  - **`server-proxy/`** — `@visgate_ai/server-proxy`: server-side proxy for Next.js and other Node runtimes. Install with `npm install @visgate_ai/server-proxy` or use locally from this repo.
261
293
  - **`examples/`** — Next.js, vanilla, and Vite examples
262
294
 
package/dist/index.cjs CHANGED
@@ -326,6 +326,183 @@ var Models = class {
326
326
  }
327
327
  };
328
328
 
329
+ // src/resources/deployments.ts
330
+ function deploymentInfoFromResponse(data) {
331
+ return {
332
+ deploymentId: data.deployment_id ?? data.deploymentId ?? "",
333
+ modelId: data.model_id ?? data.modelId,
334
+ status: data.status ?? "unknown",
335
+ endpointUrl: data.endpoint_url ?? data.endpointUrl,
336
+ provider: data.provider ?? "runpod",
337
+ createdAt: data.created_at ?? data.createdAt,
338
+ gpuAllocated: data.gpu_allocated ?? data.gpuAllocated,
339
+ modelVramGb: data.model_vram_gb ?? data.modelVramGb,
340
+ readyAt: data.ready_at ?? data.readyAt,
341
+ error: data.error ?? null
342
+ };
343
+ }
344
+ function deploymentListResponseFromResponse(data) {
345
+ const deployments = data.deployments ?? [];
346
+ return { deployments: deployments.map(deploymentInfoFromResponse) };
347
+ }
348
+ function deploymentGpuInfoFromResponse(data) {
349
+ return {
350
+ id: data.id ?? "",
351
+ displayName: data.display_name ?? data.displayName ?? "",
352
+ memoryGb: data.memory_gb ?? data.memoryGb ?? 0,
353
+ secureCloud: Boolean(data.secure_cloud ?? data.secureCloud),
354
+ communityCloud: Boolean(data.community_cloud ?? data.communityCloud),
355
+ bidPricePerHr: data.bid_price_per_hr ?? data.bidPricePerHr,
356
+ pricePerHr: data.price_per_hr ?? data.pricePerHr
357
+ };
358
+ }
359
+ function deploymentGpuListResponseFromResponse(data) {
360
+ const gpus = data.gpus ?? [];
361
+ return { gpus: gpus.map(deploymentGpuInfoFromResponse) };
362
+ }
363
+ function deploymentLogsResponseFromResponse(data) {
364
+ const rawLogs = data.logs ?? [];
365
+ return {
366
+ deploymentId: data.deployment_id ?? data.deploymentId ?? "",
367
+ logs: rawLogs.map((entry) => ({
368
+ timestamp: entry.timestamp ?? "",
369
+ level: entry.level ?? "INFO",
370
+ message: entry.message ?? ""
371
+ }))
372
+ };
373
+ }
374
+ function deploymentCostResponseFromResponse(data) {
375
+ return {
376
+ deploymentId: data.deployment_id ?? data.deploymentId ?? "",
377
+ status: data.status ?? "unknown",
378
+ gpuAllocated: data.gpu_allocated ?? data.gpuAllocated,
379
+ hoursRunning: data.hours_running ?? data.hoursRunning,
380
+ pricePerHourUsd: data.price_per_hour_usd ?? data.pricePerHourUsd,
381
+ estimatedCostUsd: data.estimated_cost_usd ?? data.estimatedCostUsd,
382
+ note: data.note ?? null
383
+ };
384
+ }
385
+ var Deployments = class {
386
+ constructor(_client) {
387
+ this._client = _client;
388
+ }
389
+ async create(options) {
390
+ const data = await this._client._request("POST", "/deployments", {
391
+ body: JSON.stringify({
392
+ model_name: options.modelName,
393
+ hf_model_id: options.hfModelId,
394
+ gpu_tier: options.gpuTier,
395
+ region: options.region,
396
+ hf_token: options.hfToken,
397
+ runpod_key: options.runpodKey,
398
+ webhook_url: options.webhookUrl,
399
+ cache_scope: options.cacheScope,
400
+ provider: options.provider,
401
+ task: options.task,
402
+ user_s3_url: options.userS3Url,
403
+ user_aws_access_key_id: options.userAwsAccessKeyId,
404
+ user_aws_secret_access_key: options.userAwsSecretAccessKey,
405
+ user_aws_endpoint_url: options.userAwsEndpointUrl
406
+ })
407
+ });
408
+ return deploymentInfoFromResponse(data);
409
+ }
410
+ async list() {
411
+ const data = await this._client._request("GET", "/deployments");
412
+ return deploymentListResponseFromResponse(data);
413
+ }
414
+ async get(deploymentId) {
415
+ const data = await this._client._request(
416
+ "GET",
417
+ `/deployments/${encodeURIComponent(deploymentId)}`
418
+ );
419
+ return deploymentInfoFromResponse(data);
420
+ }
421
+ async delete(deploymentId) {
422
+ await this._client._request("DELETE", `/deployments/${encodeURIComponent(deploymentId)}`);
423
+ }
424
+ async run(deploymentId, input) {
425
+ const data = await this._client._request("POST", `/deployments/${encodeURIComponent(deploymentId)}/run`, {
426
+ body: JSON.stringify({ input })
427
+ });
428
+ return data;
429
+ }
430
+ async getLogs(deploymentId) {
431
+ const data = await this._client._request(
432
+ "GET",
433
+ `/deployments/${encodeURIComponent(deploymentId)}/logs`
434
+ );
435
+ return deploymentLogsResponseFromResponse(data);
436
+ }
437
+ async getCost(deploymentId) {
438
+ const data = await this._client._request(
439
+ "GET",
440
+ `/deployments/${encodeURIComponent(deploymentId)}/cost`
441
+ );
442
+ return deploymentCostResponseFromResponse(data);
443
+ }
444
+ async listGpus() {
445
+ const data = await this._client._request("GET", "/deployments/gpus");
446
+ return deploymentGpuListResponseFromResponse(data);
447
+ }
448
+ /**
449
+ * Streams deployment status events (SSE).
450
+ * Returns an abort function to stop streaming.
451
+ */
452
+ streamStatus(deploymentId, onEvent, onError) {
453
+ const controller = new AbortController();
454
+ const base = this._client.baseUrl.replace(/\/$/, "");
455
+ const url = `${base}/deployments/${encodeURIComponent(deploymentId)}/stream`;
456
+ const headers = {};
457
+ if (this._client.apiKey) headers.Authorization = `Bearer ${this._client.apiKey}`;
458
+ void (async () => {
459
+ try {
460
+ const response = await fetch(url, {
461
+ method: "GET",
462
+ headers,
463
+ signal: controller.signal
464
+ });
465
+ if (!response.ok || !response.body) {
466
+ throw new Error(`SSE stream failed with status ${response.status}`);
467
+ }
468
+ const decoder = new TextDecoder();
469
+ const reader = response.body.getReader();
470
+ let buffer = "";
471
+ while (true) {
472
+ const { value, done } = await reader.read();
473
+ if (done) break;
474
+ buffer += decoder.decode(value, { stream: true });
475
+ const events = buffer.split("\n\n");
476
+ buffer = events.pop() ?? "";
477
+ for (const rawEvent of events) {
478
+ const dataLine = rawEvent.split("\n").find((line) => line.startsWith("data:"));
479
+ if (!dataLine) continue;
480
+ const payload = dataLine.slice(5).trim();
481
+ if (!payload) continue;
482
+ try {
483
+ const parsed = JSON.parse(payload);
484
+ onEvent({
485
+ deploymentId: parsed.deployment_id ?? parsed.deploymentId ?? deploymentId,
486
+ status: parsed.status,
487
+ endpointUrl: parsed.endpoint_url ?? parsed.endpointUrl,
488
+ estimatedRemainingSeconds: parsed.estimated_remaining_seconds,
489
+ error: parsed.error
490
+ });
491
+ } catch {
492
+ }
493
+ }
494
+ }
495
+ } catch (err) {
496
+ if (!controller.signal.aborted) {
497
+ const error = err instanceof Error ? err : new Error(String(err));
498
+ onError?.(error);
499
+ }
500
+ }
501
+ })();
502
+ return () => controller.abort();
503
+ }
504
+ };
505
+
329
506
  // src/resources/providers.ts
330
507
  function providerKeyInfoFromResponse(data) {
331
508
  return {
@@ -593,7 +770,7 @@ var DEFAULT_BASE_URL = "https://visgateai.com/api/v1";
593
770
  var DEFAULT_TIMEOUT = 12e4;
594
771
  var DEFAULT_MAX_RETRIES = 2;
595
772
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
596
- var SDK_VERSION = "0.2.2";
773
+ var SDK_VERSION = "0.3.3";
597
774
  function getVersion() {
598
775
  try {
599
776
  if (typeof __VERSION__ !== "undefined") return __VERSION__;
@@ -610,6 +787,7 @@ function buildHeaders(apiKey, options) {
610
787
  if (options.falKey) headers["X-Fal-Key"] = options.falKey;
611
788
  if (options.replicateKey) headers["X-Replicate-Key"] = options.replicateKey;
612
789
  if (options.runwayKey) headers["X-Runway-Key"] = options.runwayKey;
790
+ if (options.runpodKey) headers["X-Runpod-Key"] = options.runpodKey;
613
791
  return headers;
614
792
  }
615
793
  function backoff(attempt) {
@@ -674,7 +852,8 @@ var Client = class {
674
852
  this.headers = buildHeaders(this.apiKey, options.proxyUrl ? {} : {
675
853
  falKey: options.falKey,
676
854
  replicateKey: options.replicateKey,
677
- runwayKey: options.runwayKey
855
+ runwayKey: options.runwayKey,
856
+ runpodKey: options.runpodKey
678
857
  });
679
858
  this.images = new Images(this);
680
859
  this.models = new Models(this);
@@ -682,6 +861,7 @@ var Client = class {
682
861
  this.requests = new Requests(this);
683
862
  this.usage = new Usage(this);
684
863
  this.providers = new Providers(this);
864
+ this.deployments = new Deployments(this);
685
865
  this.billing = new Billing(this);
686
866
  this._generate = new Generate(this);
687
867
  }
@@ -771,12 +951,13 @@ var AsyncClient = class extends Client {
771
951
  };
772
952
 
773
953
  // src/index.ts
774
- var VERSION = "0.2.2";
954
+ var VERSION = "0.3.3";
775
955
 
776
956
  exports.AsyncClient = AsyncClient;
777
957
  exports.AuthenticationError = AuthenticationError;
778
958
  exports.Billing = Billing;
779
959
  exports.Client = Client;
960
+ exports.Deployments = Deployments;
780
961
  exports.Generate = Generate;
781
962
  exports.Images = Images;
782
963
  exports.Models = Models;
@@ -793,6 +974,12 @@ exports.VisgateConnectionError = VisgateConnectionError;
793
974
  exports.VisgateError = VisgateError;
794
975
  exports.VisgateTimeoutError = VisgateTimeoutError;
795
976
  exports.billingInfoFromResponse = billingInfoFromResponse;
977
+ exports.deploymentCostResponseFromResponse = deploymentCostResponseFromResponse;
978
+ exports.deploymentGpuInfoFromResponse = deploymentGpuInfoFromResponse;
979
+ exports.deploymentGpuListResponseFromResponse = deploymentGpuListResponseFromResponse;
980
+ exports.deploymentInfoFromResponse = deploymentInfoFromResponse;
981
+ exports.deploymentListResponseFromResponse = deploymentListResponseFromResponse;
982
+ exports.deploymentLogsResponseFromResponse = deploymentLogsResponseFromResponse;
796
983
  exports.featuredSectionFromResponse = featuredSectionFromResponse;
797
984
  exports.generateResultFromResponse = generateResultFromResponse;
798
985
  exports.imageResultFromResponse = imageResultFromResponse;