@visgate_ai/client 0.2.22 → 0.3.4

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,219 @@ 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
+
506
+ // src/resources/hf-models.ts
507
+ var HF_API_BASE = "https://huggingface.co/api/models";
508
+ function normalizeModel(raw) {
509
+ const id = raw.id ?? raw.modelId ?? "";
510
+ return {
511
+ id,
512
+ modelId: raw.modelId ?? id,
513
+ pipelineTag: raw.pipeline_tag ?? "",
514
+ libraryName: raw.library_name,
515
+ likes: raw.likes,
516
+ downloads: raw.downloads
517
+ };
518
+ }
519
+ var HfModels = class {
520
+ async list(options = {}) {
521
+ const task = options.task ?? "text-to-image";
522
+ const limit = Math.min(Math.max(options.limit ?? 50, 1), 100);
523
+ const params = new URLSearchParams();
524
+ params.set("pipeline_tag", task);
525
+ params.set("limit", String(limit));
526
+ if (options.search && options.search.trim()) {
527
+ params.set("search", options.search.trim());
528
+ }
529
+ const url = `${HF_API_BASE}?${params.toString()}`;
530
+ const response = await fetch(url);
531
+ if (!response.ok) {
532
+ throw new Error(`Hugging Face API error: ${response.status} ${response.statusText}`);
533
+ }
534
+ const data = await response.json();
535
+ if (!Array.isArray(data)) {
536
+ return [];
537
+ }
538
+ return data.map((item) => normalizeModel(item));
539
+ }
540
+ };
541
+
329
542
  // src/resources/providers.ts
330
543
  function providerKeyInfoFromResponse(data) {
331
544
  return {
@@ -593,7 +806,7 @@ var DEFAULT_BASE_URL = "https://visgateai.com/api/v1";
593
806
  var DEFAULT_TIMEOUT = 12e4;
594
807
  var DEFAULT_MAX_RETRIES = 2;
595
808
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
596
- var SDK_VERSION = "0.2.2";
809
+ var SDK_VERSION = "0.3.3";
597
810
  function getVersion() {
598
811
  try {
599
812
  if (typeof __VERSION__ !== "undefined") return __VERSION__;
@@ -610,6 +823,7 @@ function buildHeaders(apiKey, options) {
610
823
  if (options.falKey) headers["X-Fal-Key"] = options.falKey;
611
824
  if (options.replicateKey) headers["X-Replicate-Key"] = options.replicateKey;
612
825
  if (options.runwayKey) headers["X-Runway-Key"] = options.runwayKey;
826
+ if (options.runpodKey) headers["X-Runpod-Key"] = options.runpodKey;
613
827
  return headers;
614
828
  }
615
829
  function backoff(attempt) {
@@ -674,7 +888,8 @@ var Client = class {
674
888
  this.headers = buildHeaders(this.apiKey, options.proxyUrl ? {} : {
675
889
  falKey: options.falKey,
676
890
  replicateKey: options.replicateKey,
677
- runwayKey: options.runwayKey
891
+ runwayKey: options.runwayKey,
892
+ runpodKey: options.runpodKey
678
893
  });
679
894
  this.images = new Images(this);
680
895
  this.models = new Models(this);
@@ -682,6 +897,8 @@ var Client = class {
682
897
  this.requests = new Requests(this);
683
898
  this.usage = new Usage(this);
684
899
  this.providers = new Providers(this);
900
+ this.deployments = new Deployments(this);
901
+ this.hfModels = new HfModels();
685
902
  this.billing = new Billing(this);
686
903
  this._generate = new Generate(this);
687
904
  }
@@ -771,13 +988,15 @@ var AsyncClient = class extends Client {
771
988
  };
772
989
 
773
990
  // src/index.ts
774
- var VERSION = "0.2.2";
991
+ var VERSION = "0.3.4";
775
992
 
776
993
  exports.AsyncClient = AsyncClient;
777
994
  exports.AuthenticationError = AuthenticationError;
778
995
  exports.Billing = Billing;
779
996
  exports.Client = Client;
997
+ exports.Deployments = Deployments;
780
998
  exports.Generate = Generate;
999
+ exports.HfModels = HfModels;
781
1000
  exports.Images = Images;
782
1001
  exports.Models = Models;
783
1002
  exports.ProviderError = ProviderError;
@@ -793,6 +1012,12 @@ exports.VisgateConnectionError = VisgateConnectionError;
793
1012
  exports.VisgateError = VisgateError;
794
1013
  exports.VisgateTimeoutError = VisgateTimeoutError;
795
1014
  exports.billingInfoFromResponse = billingInfoFromResponse;
1015
+ exports.deploymentCostResponseFromResponse = deploymentCostResponseFromResponse;
1016
+ exports.deploymentGpuInfoFromResponse = deploymentGpuInfoFromResponse;
1017
+ exports.deploymentGpuListResponseFromResponse = deploymentGpuListResponseFromResponse;
1018
+ exports.deploymentInfoFromResponse = deploymentInfoFromResponse;
1019
+ exports.deploymentListResponseFromResponse = deploymentListResponseFromResponse;
1020
+ exports.deploymentLogsResponseFromResponse = deploymentLogsResponseFromResponse;
796
1021
  exports.featuredSectionFromResponse = featuredSectionFromResponse;
797
1022
  exports.generateResultFromResponse = generateResultFromResponse;
798
1023
  exports.imageResultFromResponse = imageResultFromResponse;