@vargai/gateway 0.1.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 +170 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14272 -0
- package/dist/provider.d.ts +11 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/schemas.d.ts +3 -0
- package/dist/schemas.d.ts.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @vargai/gateway
|
|
2
|
+
|
|
3
|
+
typescript client for varg gateway api — unified proxy over fal, elevenlabs, replicate, higgsfield.
|
|
4
|
+
|
|
5
|
+
## installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @vargai/gateway
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { VargClient } from "@vargai/gateway";
|
|
15
|
+
|
|
16
|
+
const client = new VargClient({
|
|
17
|
+
apiKey: "varg_xxx",
|
|
18
|
+
baseUrl: "https://api.varg.ai/v1", // optional, defaults to this
|
|
19
|
+
providerKeys: {
|
|
20
|
+
// optional BYOK
|
|
21
|
+
fal: "fal_xxx",
|
|
22
|
+
elevenlabs: "el_xxx",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// generate video
|
|
27
|
+
const videoJob = await client.createVideo({
|
|
28
|
+
model: "kling-v2.6",
|
|
29
|
+
prompt: "cat jumping over fence",
|
|
30
|
+
duration: 5,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// poll until complete
|
|
34
|
+
const result = await client.waitForJob(videoJob.job_id);
|
|
35
|
+
console.log(result.output?.url);
|
|
36
|
+
|
|
37
|
+
// or check manually
|
|
38
|
+
const job = await client.getJob(videoJob.job_id);
|
|
39
|
+
if (job.status === "completed") {
|
|
40
|
+
console.log(job.output?.url);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## api
|
|
45
|
+
|
|
46
|
+
### `createVideo(params)`
|
|
47
|
+
|
|
48
|
+
generate video. returns job reference.
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const job = await client.createVideo({
|
|
52
|
+
model: "kling-v2.6",
|
|
53
|
+
prompt: "warrior princess on cliff",
|
|
54
|
+
duration: 5,
|
|
55
|
+
aspect_ratio: "16:9",
|
|
56
|
+
files: [{ url: "https://s3.varg.ai/u/..." }], // optional reference images
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### `createImage(params)`
|
|
61
|
+
|
|
62
|
+
generate image. returns job reference.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const job = await client.createImage({
|
|
66
|
+
model: "flux-schnell",
|
|
67
|
+
prompt: "cyberpunk cityscape",
|
|
68
|
+
aspect_ratio: "16:9",
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `createSpeech(params)`
|
|
73
|
+
|
|
74
|
+
text-to-speech. returns job reference.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const job = await client.createSpeech({
|
|
78
|
+
model: "eleven_turbo_v2_5",
|
|
79
|
+
text: "hello world",
|
|
80
|
+
voice: "rachel",
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `createMusic(params)`
|
|
85
|
+
|
|
86
|
+
generate music. returns job reference.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const job = await client.createMusic({
|
|
90
|
+
model: "elevenlabs",
|
|
91
|
+
prompt: "epic orchestral theme",
|
|
92
|
+
duration: 30,
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### `uploadFile(file, mediaType)`
|
|
97
|
+
|
|
98
|
+
upload file (image, video, audio). returns file reference.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const file = Bun.file("./hero.png");
|
|
102
|
+
const upload = await client.uploadFile(file, "image/png");
|
|
103
|
+
console.log(upload.url); // use in files array
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `getJob(id)`
|
|
107
|
+
|
|
108
|
+
get job status and output.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const job = await client.getJob("job_a1b2c3");
|
|
112
|
+
if (job.status === "completed") {
|
|
113
|
+
console.log(job.output?.url);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `waitForJob(id, opts?)`
|
|
118
|
+
|
|
119
|
+
poll until job completes. returns final job.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const job = await client.waitForJob("job_a1b2c3", {
|
|
123
|
+
pollIntervalMs: 2000, // default
|
|
124
|
+
maxAttempts: 150, // default (5 minutes)
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `cancelJob(id)`
|
|
129
|
+
|
|
130
|
+
cancel a running job.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
await client.cancelJob("job_a1b2c3");
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## schemas
|
|
137
|
+
|
|
138
|
+
all schemas are exported for validation:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import {
|
|
142
|
+
VideoRequestSchema,
|
|
143
|
+
ImageRequestSchema,
|
|
144
|
+
SpeechRequestSchema,
|
|
145
|
+
MusicRequestSchema,
|
|
146
|
+
JobResponseSchema,
|
|
147
|
+
FileUploadResponseSchema,
|
|
148
|
+
} from "@vargai/gateway";
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## errors
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { VargGatewayError } from "@vargai/gateway";
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
await client.createVideo({ model: "invalid", prompt: "test" });
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof VargGatewayError) {
|
|
160
|
+
console.log(error.message);
|
|
161
|
+
console.log(error.statusCode); // 400, 401, 404, 502, etc.
|
|
162
|
+
console.log(error.field); // validation error field
|
|
163
|
+
console.log(error.provider); // provider that failed
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## license
|
|
169
|
+
|
|
170
|
+
mit
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type FileUploadResponse, type ImageRequest, type JobResponse, type MusicRequest, type SpeechRequest, type VideoRequest } from "./schemas.ts";
|
|
2
|
+
export interface VargClientConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
providerKeys?: {
|
|
6
|
+
fal?: string;
|
|
7
|
+
elevenlabs?: string;
|
|
8
|
+
higgsfield?: string;
|
|
9
|
+
replicate?: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface WaitForJobOptions {
|
|
13
|
+
pollIntervalMs?: number;
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class VargGatewayError extends Error {
|
|
17
|
+
statusCode?: number | undefined;
|
|
18
|
+
field?: string | undefined;
|
|
19
|
+
provider?: string | undefined;
|
|
20
|
+
constructor(message: string, statusCode?: number | undefined, field?: string | undefined, provider?: string | undefined);
|
|
21
|
+
}
|
|
22
|
+
export declare class VargClient {
|
|
23
|
+
private apiKey;
|
|
24
|
+
private baseUrl;
|
|
25
|
+
private providerKeys;
|
|
26
|
+
constructor(config: VargClientConfig);
|
|
27
|
+
private getHeaders;
|
|
28
|
+
private handleResponse;
|
|
29
|
+
createVideo(params: VideoRequest): Promise<JobResponse>;
|
|
30
|
+
createImage(params: ImageRequest): Promise<JobResponse>;
|
|
31
|
+
createSpeech(params: SpeechRequest): Promise<JobResponse>;
|
|
32
|
+
createMusic(params: MusicRequest): Promise<JobResponse>;
|
|
33
|
+
uploadFile(file: Blob | Buffer, mediaType: string): Promise<FileUploadResponse>;
|
|
34
|
+
getJob(id: string): Promise<JobResponse>;
|
|
35
|
+
cancelJob(id: string): Promise<void>;
|
|
36
|
+
waitForJob(id: string, options?: WaitForJobOptions): Promise<JobResponse>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAEvB,KAAK,YAAY,EAEjB,KAAK,WAAW,EAEhB,KAAK,YAAY,EAEjB,KAAK,aAAa,EAElB,KAAK,YAAY,EAElB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IAGhC,UAAU,CAAC,EAAE,MAAM;IACnB,KAAK,CAAC,EAAE,MAAM;IACd,QAAQ,CAAC,EAAE,MAAM;gBAHxB,OAAO,EAAE,MAAM,EACR,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,KAAK,CAAC,EAAE,MAAM,YAAA,EACd,QAAQ,CAAC,EAAE,MAAM,YAAA;CAK3B;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAmC;gBAE3C,MAAM,EAAE,gBAAgB;IAMpC,OAAO,CAAC,UAAU;YAsBJ,cAAc;IAuBtB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;IAUzD,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2B/E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAQxC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBpC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;CAgBhF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { VargClient, VargGatewayError } from "./client.ts";
|
|
2
|
+
export type { VargClientConfig, WaitForJobOptions } from "./client.ts";
|
|
3
|
+
export { createVarg } from "./provider.ts";
|
|
4
|
+
export type { VargProvider } from "./provider.ts";
|
|
5
|
+
export { ErrorResponseSchema, FileInputSchema, FileUploadResponseSchema, ImageRequestSchema, JobResponseSchema, JobStatusSchema, MusicRequestSchema, SpeechRequestSchema, VideoRequestSchema, } from "./schemas.ts";
|
|
6
|
+
export type { ErrorResponse, FileInput, FileUploadResponse, ImageRequest, JobResponse, JobStatus, MusicRequest, SpeechRequest, VideoRequest, } from "./schemas.ts";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,cAAc,CAAC"}
|