@apicity/kie 0.6.6 → 0.7.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 +61 -1
- package/dist/src/chat.d.ts.map +1 -1
- package/dist/src/chat.js +12 -49
- package/dist/src/chat.js.map +1 -1
- package/dist/src/claude.d.ts.map +1 -1
- package/dist/src/claude.js +15 -51
- package/dist/src/claude.js.map +1 -1
- package/dist/src/example.d.ts.map +1 -1
- package/dist/src/example.js +30 -4
- package/dist/src/example.js.map +1 -1
- package/dist/src/gemini-31-pro.d.ts.map +1 -1
- package/dist/src/gemini-31-pro.js +17 -36
- package/dist/src/gemini-31-pro.js.map +1 -1
- package/dist/src/gemini.d.ts.map +1 -1
- package/dist/src/gemini.js +17 -36
- package/dist/src/gemini.js.map +1 -1
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/kie.d.ts.map +1 -1
- package/dist/src/kie.js +79 -398
- package/dist/src/kie.js.map +1 -1
- package/dist/src/middleware.d.ts +2 -0
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/middleware.js +85 -1
- package/dist/src/middleware.js.map +1 -1
- package/dist/src/model-schemas.d.ts.map +1 -1
- package/dist/src/model-schemas.js +14 -9
- package/dist/src/model-schemas.js.map +1 -1
- package/dist/src/paid-endpoints.d.ts.map +1 -1
- package/dist/src/paid-endpoints.js +12 -0
- package/dist/src/paid-endpoints.js.map +1 -1
- package/dist/src/paygate.d.ts +1 -0
- package/dist/src/paygate.d.ts.map +1 -1
- package/dist/src/paygate.js +12 -0
- package/dist/src/paygate.js.map +1 -1
- package/dist/src/request.d.ts +33 -3
- package/dist/src/request.d.ts.map +1 -1
- package/dist/src/request.js +99 -36
- package/dist/src/request.js.map +1 -1
- package/dist/src/responses.d.ts.map +1 -1
- package/dist/src/responses.js +30 -52
- package/dist/src/responses.js.map +1 -1
- package/dist/src/sse.d.ts +6 -1
- package/dist/src/sse.d.ts.map +1 -1
- package/dist/src/sse.js +51 -5
- package/dist/src/sse.js.map +1 -1
- package/dist/src/suno.d.ts +33 -0
- package/dist/src/suno.d.ts.map +1 -1
- package/dist/src/suno.js +96 -34
- package/dist/src/suno.js.map +1 -1
- package/dist/src/transport.d.ts +40 -0
- package/dist/src/transport.d.ts.map +1 -0
- package/dist/src/transport.js +136 -0
- package/dist/src/transport.js.map +1 -0
- package/dist/src/types.d.ts +11 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/veo.d.ts +62 -0
- package/dist/src/veo.d.ts.map +1 -1
- package/dist/src/veo.js +47 -7
- package/dist/src/veo.js.map +1 -1
- package/dist/src/with-paid-gate.d.ts.map +1 -1
- package/dist/src/with-paid-gate.js +2 -0
- package/dist/src/with-paid-gate.js.map +1 -1
- package/dist/src/zod.d.ts +140 -6
- package/dist/src/zod.d.ts.map +1 -1
- package/dist/src/zod.js +98 -11
- package/dist/src/zod.js.map +1 -1
- package/package.json +1 -1
package/dist/src/kie.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KieError, } from "./types.js";
|
|
2
|
-
import { CreateTaskRequestSchema, DownloadUrlRequestSchema, UploadMediaRequestSchema, FileUrlUploadRequestSchema, FileBase64UploadRequestSchema, GeminiOmniVideoRequestSchema, GeminiOmniAudioCreateRequestSchema, GeminiOmniCharacterCreateRequestSchema, GeminiOmniCharacterCreateResponseSchema, FluxKontextGenerateRequestSchema, Gpt4oImageGenerateRequestSchema, MjGenerateRequestSchema, RunwayGenerateRequestSchema, RunwayExtendRequestSchema, RunwayRecordDetailResponseSchema, FluxKontextRecordInfoRequestSchema, FluxKontextRecordInfoResponseSchema, GrokImageToVideoRequestSchema, RecordInfoRequestSchema, Gpt4oImageRecordInfoResponseSchema, Seedance2MiniRecordInfoResponseSchema, Seedance2MiniRequestSchema, } from "./zod.js";
|
|
2
|
+
import { CreateTaskRequestSchema, DownloadUrlRequestSchema, UploadMediaRequestSchema, FileUrlUploadRequestSchema, FileBase64UploadRequestSchema, GeminiOmniVideoRequestSchema, GeminiOmniAudioCreateRequestSchema, GeminiOmniCharacterCreateRequestSchema, GeminiOmniCharacterCreateResponseSchema, FluxKontextGenerateRequestSchema, Gpt4oImageGenerateRequestSchema, MjGenerateRequestSchema, MjRecordInfoRequestSchema, MjRecordInfoResponseSchema, RunwayGenerateRequestSchema, RunwayExtendRequestSchema, RunwayRecordDetailResponseSchema, FluxKontextRecordInfoRequestSchema, FluxKontextRecordInfoResponseSchema, GrokImageToVideoRequestSchema, RecordInfoRequestSchema, Gpt4oImageRecordInfoResponseSchema, Seedance2MiniRecordInfoResponseSchema, Seedance2MiniRequestSchema, } from "./zod.js";
|
|
3
3
|
import { modelInputSchemas } from "./model-schemas.js";
|
|
4
4
|
import { createVeoProvider } from "./veo.js";
|
|
5
5
|
import { createSunoProvider } from "./suno.js";
|
|
@@ -11,7 +11,7 @@ import { createGemini31ProProvider } from "./gemini-31-pro.js";
|
|
|
11
11
|
import { attachExamples } from "./example.js";
|
|
12
12
|
import { createReplayStore } from "./paygate.js";
|
|
13
13
|
import { withPaidGate } from "./with-paid-gate.js";
|
|
14
|
-
import { kieRequest } from "./request.js";
|
|
14
|
+
import { createKieTransport, kieRequest } from "./request.js";
|
|
15
15
|
const MIME_TYPES = {
|
|
16
16
|
jpg: "image/jpeg",
|
|
17
17
|
jpeg: "image/jpeg",
|
|
@@ -94,6 +94,22 @@ export function createKie(opts) {
|
|
|
94
94
|
const uploadBaseURL = opts.uploadBaseURL ?? "https://kieai.redpandaai.co";
|
|
95
95
|
const doFetch = opts.fetch ?? fetch;
|
|
96
96
|
const timeout = opts.timeout ?? 30000;
|
|
97
|
+
const transport = createKieTransport({
|
|
98
|
+
baseURL,
|
|
99
|
+
apiKey: opts.apiKey,
|
|
100
|
+
doFetch,
|
|
101
|
+
timeout,
|
|
102
|
+
requestFailedPrefix: "Kie request failed",
|
|
103
|
+
});
|
|
104
|
+
const uploadTransport = createKieTransport({
|
|
105
|
+
baseURL: uploadBaseURL,
|
|
106
|
+
apiKey: opts.apiKey,
|
|
107
|
+
doFetch,
|
|
108
|
+
timeout,
|
|
109
|
+
errorPrefix: "Kie upload error",
|
|
110
|
+
requestFailedPrefix: "Kie upload failed",
|
|
111
|
+
jsonContentType: false,
|
|
112
|
+
});
|
|
97
113
|
const paygate = opts.paygate
|
|
98
114
|
? {
|
|
99
115
|
...opts.paygate,
|
|
@@ -106,323 +122,65 @@ export function createKie(opts) {
|
|
|
106
122
|
validateGrokImageToVideoRequest(req);
|
|
107
123
|
validateSeedance2MiniRequest(req);
|
|
108
124
|
validateGeminiOmniVideoRequest(req);
|
|
109
|
-
|
|
110
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
111
|
-
try {
|
|
112
|
-
const res = await doFetch(`${baseURL}/api/v1/jobs/createTask`, {
|
|
113
|
-
method: "POST",
|
|
114
|
-
headers: {
|
|
115
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
116
|
-
"Content-Type": "application/json",
|
|
117
|
-
},
|
|
118
|
-
body: JSON.stringify(req),
|
|
119
|
-
signal: controller.signal,
|
|
120
|
-
});
|
|
121
|
-
clearTimeout(timeoutId);
|
|
122
|
-
if (!res.ok) {
|
|
123
|
-
let message = `Kie API error: ${res.status}`;
|
|
124
|
-
let body = null;
|
|
125
|
-
try {
|
|
126
|
-
body = await res.json();
|
|
127
|
-
if (typeof body === "object" &&
|
|
128
|
-
body !== null &&
|
|
129
|
-
"msg" in body &&
|
|
130
|
-
typeof body.msg === "string") {
|
|
131
|
-
message = `Kie API error ${res.status}: ${body.msg}`;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
// ignore parse errors
|
|
136
|
-
}
|
|
137
|
-
throw new KieError(message, res.status, body);
|
|
138
|
-
}
|
|
139
|
-
return (await res.json());
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
clearTimeout(timeoutId);
|
|
143
|
-
if (error instanceof KieError)
|
|
144
|
-
throw error;
|
|
145
|
-
throw new KieError(`Failed to create task: ${error}`, 500);
|
|
146
|
-
}
|
|
125
|
+
return await transport.postJson("/api/v1/jobs/createTask", req);
|
|
147
126
|
}
|
|
148
127
|
// GET https://api.kie.ai/api/v1/jobs/recordInfo?taskId={taskId}
|
|
149
128
|
// Docs: https://docs.kie.ai/market/common/get-task-detail
|
|
150
129
|
async function recordInfo(taskId) {
|
|
151
|
-
|
|
152
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
153
|
-
try {
|
|
154
|
-
const res = await doFetch(`${baseURL}/api/v1/jobs/recordInfo?taskId=${encodeURIComponent(taskId)}`, {
|
|
155
|
-
method: "GET",
|
|
156
|
-
headers: {
|
|
157
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
158
|
-
"Content-Type": "application/json",
|
|
159
|
-
},
|
|
160
|
-
signal: controller.signal,
|
|
161
|
-
});
|
|
162
|
-
clearTimeout(timeoutId);
|
|
163
|
-
if (!res.ok) {
|
|
164
|
-
let message = `Kie API error: ${res.status}`;
|
|
165
|
-
let body = null;
|
|
166
|
-
try {
|
|
167
|
-
body = await res.json();
|
|
168
|
-
if (typeof body === "object" &&
|
|
169
|
-
body !== null &&
|
|
170
|
-
"msg" in body &&
|
|
171
|
-
typeof body.msg === "string") {
|
|
172
|
-
message = `Kie API error ${res.status}: ${body.msg}`;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
// ignore parse errors
|
|
177
|
-
}
|
|
178
|
-
throw new KieError(message, res.status, body);
|
|
179
|
-
}
|
|
180
|
-
return (await res.json());
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
clearTimeout(timeoutId);
|
|
184
|
-
if (error instanceof KieError)
|
|
185
|
-
throw error;
|
|
186
|
-
throw new KieError(`Failed to get task: ${error}`, 500);
|
|
187
|
-
}
|
|
130
|
+
return await transport.getJson(`/api/v1/jobs/recordInfo?taskId=${encodeURIComponent(taskId)}`);
|
|
188
131
|
}
|
|
189
132
|
// GET https://api.kie.ai/api/v1/gpt4o-image/record-info?taskId={taskId}
|
|
190
133
|
// Docs: https://docs.kie.ai/4o-image-api/get-4-o-image-details
|
|
191
134
|
async function gpt4oImageRecordInfo(taskId) {
|
|
192
|
-
|
|
193
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
194
|
-
try {
|
|
195
|
-
const res = await doFetch(`${baseURL}/api/v1/gpt4o-image/record-info?taskId=${encodeURIComponent(taskId)}`, {
|
|
196
|
-
method: "GET",
|
|
197
|
-
headers: {
|
|
198
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
199
|
-
"Content-Type": "application/json",
|
|
200
|
-
},
|
|
201
|
-
signal: controller.signal,
|
|
202
|
-
});
|
|
203
|
-
clearTimeout(timeoutId);
|
|
204
|
-
if (!res.ok) {
|
|
205
|
-
let message = `Kie API error: ${res.status}`;
|
|
206
|
-
let body = null;
|
|
207
|
-
try {
|
|
208
|
-
body = await res.json();
|
|
209
|
-
if (typeof body === "object" &&
|
|
210
|
-
body !== null &&
|
|
211
|
-
"msg" in body &&
|
|
212
|
-
typeof body.msg === "string") {
|
|
213
|
-
message = `Kie API error ${res.status}: ${body.msg}`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
// ignore parse errors
|
|
218
|
-
}
|
|
219
|
-
throw new KieError(message, res.status, body);
|
|
220
|
-
}
|
|
221
|
-
return (await res.json());
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
clearTimeout(timeoutId);
|
|
225
|
-
if (error instanceof KieError)
|
|
226
|
-
throw error;
|
|
227
|
-
throw new KieError(`Failed to get 4o image task: ${error}`, 500);
|
|
228
|
-
}
|
|
135
|
+
return await transport.getJson(`/api/v1/gpt4o-image/record-info?taskId=${encodeURIComponent(taskId)}`);
|
|
229
136
|
}
|
|
230
137
|
// POST https://kieai.redpandaai.co/api/file-stream-upload
|
|
231
138
|
// Docs: https://docs.kie.ai/file-upload-api/upload-file-stream
|
|
232
139
|
async function fileStreamUpload(req) {
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const mimeType = req.mimeType ?? inferMimeType(req.filename);
|
|
237
|
-
if (!mimeType) {
|
|
238
|
-
throw new KieError(`Cannot determine MIME type for: ${req.filename}`, 400);
|
|
239
|
-
}
|
|
240
|
-
const formData = new FormData();
|
|
241
|
-
const file = new File([req.file], req.filename, { type: mimeType });
|
|
242
|
-
formData.append("file", file);
|
|
243
|
-
formData.append("uploadPath", req.uploadPath);
|
|
244
|
-
if (req.fileName) {
|
|
245
|
-
formData.append("fileName", req.fileName);
|
|
246
|
-
}
|
|
247
|
-
const res = await doFetch(`${uploadBaseURL}/api/file-stream-upload`, {
|
|
248
|
-
method: "POST",
|
|
249
|
-
headers: {
|
|
250
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
251
|
-
},
|
|
252
|
-
body: formData,
|
|
253
|
-
signal: controller.signal,
|
|
254
|
-
});
|
|
255
|
-
clearTimeout(timeoutId);
|
|
256
|
-
if (!res.ok) {
|
|
257
|
-
let message = `Kie upload error: ${res.status}`;
|
|
258
|
-
let body = null;
|
|
259
|
-
try {
|
|
260
|
-
body = await res.json();
|
|
261
|
-
if (typeof body === "object" &&
|
|
262
|
-
body !== null &&
|
|
263
|
-
"msg" in body &&
|
|
264
|
-
typeof body.msg === "string") {
|
|
265
|
-
message = `Kie upload error ${res.status}: ${body.msg}`;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
catch {
|
|
269
|
-
// ignore parse errors
|
|
270
|
-
}
|
|
271
|
-
throw new KieError(message, res.status, body);
|
|
272
|
-
}
|
|
273
|
-
return (await res.json());
|
|
140
|
+
const mimeType = req.mimeType ?? inferMimeType(req.filename);
|
|
141
|
+
if (!mimeType) {
|
|
142
|
+
throw new KieError(`Cannot determine MIME type for: ${req.filename}`, 400);
|
|
274
143
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
144
|
+
const formData = new FormData();
|
|
145
|
+
const file = new File([req.file], req.filename, { type: mimeType });
|
|
146
|
+
formData.append("file", file);
|
|
147
|
+
formData.append("uploadPath", req.uploadPath);
|
|
148
|
+
if (req.fileName) {
|
|
149
|
+
formData.append("fileName", req.fileName);
|
|
280
150
|
}
|
|
151
|
+
return await uploadTransport.postForm("/api/file-stream-upload", formData);
|
|
281
152
|
}
|
|
282
153
|
// POST https://kieai.redpandaai.co/api/file-url-upload
|
|
283
154
|
// Docs: https://docs.kie.ai/file-upload-api/upload-file-url
|
|
284
155
|
async function fileUrlUpload(req) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
headers: {
|
|
291
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
292
|
-
"Content-Type": "application/json",
|
|
293
|
-
},
|
|
294
|
-
body: JSON.stringify({
|
|
295
|
-
fileUrl: req.fileUrl,
|
|
296
|
-
uploadPath: req.uploadPath,
|
|
297
|
-
...(req.fileName ? { fileName: req.fileName } : {}),
|
|
298
|
-
}),
|
|
299
|
-
signal: controller.signal,
|
|
300
|
-
});
|
|
301
|
-
clearTimeout(timeoutId);
|
|
302
|
-
if (!res.ok) {
|
|
303
|
-
let message = `Kie upload error: ${res.status}`;
|
|
304
|
-
let body = null;
|
|
305
|
-
try {
|
|
306
|
-
body = await res.json();
|
|
307
|
-
if (typeof body === "object" &&
|
|
308
|
-
body !== null &&
|
|
309
|
-
"msg" in body &&
|
|
310
|
-
typeof body.msg === "string") {
|
|
311
|
-
message = `Kie upload error ${res.status}: ${body.msg}`;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
catch {
|
|
315
|
-
// ignore parse errors
|
|
316
|
-
}
|
|
317
|
-
throw new KieError(message, res.status, body);
|
|
318
|
-
}
|
|
319
|
-
return (await res.json());
|
|
320
|
-
}
|
|
321
|
-
catch (error) {
|
|
322
|
-
clearTimeout(timeoutId);
|
|
323
|
-
if (error instanceof KieError)
|
|
324
|
-
throw error;
|
|
325
|
-
throw new KieError(`Failed to upload from URL: ${error}`, 500);
|
|
326
|
-
}
|
|
156
|
+
return await uploadTransport.postJson("/api/file-url-upload", {
|
|
157
|
+
fileUrl: req.fileUrl,
|
|
158
|
+
uploadPath: req.uploadPath,
|
|
159
|
+
...(req.fileName ? { fileName: req.fileName } : {}),
|
|
160
|
+
});
|
|
327
161
|
}
|
|
328
162
|
// POST https://kieai.redpandaai.co/api/file-base64-upload
|
|
329
163
|
// Docs: https://docs.kie.ai/file-upload-api/upload-file-base-64
|
|
330
164
|
async function fileBase64Upload(req) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
338
|
-
"Content-Type": "application/json",
|
|
339
|
-
},
|
|
340
|
-
body: JSON.stringify({
|
|
341
|
-
base64Data: req.base64Data,
|
|
342
|
-
uploadPath: req.uploadPath,
|
|
343
|
-
...(req.fileName ? { fileName: req.fileName } : {}),
|
|
344
|
-
...(req.mimeType ? { mimeType: req.mimeType } : {}),
|
|
345
|
-
}),
|
|
346
|
-
signal: controller.signal,
|
|
347
|
-
});
|
|
348
|
-
clearTimeout(timeoutId);
|
|
349
|
-
if (!res.ok) {
|
|
350
|
-
let message = `Kie upload error: ${res.status}`;
|
|
351
|
-
let body = null;
|
|
352
|
-
try {
|
|
353
|
-
body = await res.json();
|
|
354
|
-
if (typeof body === "object" &&
|
|
355
|
-
body !== null &&
|
|
356
|
-
"msg" in body &&
|
|
357
|
-
typeof body.msg === "string") {
|
|
358
|
-
message = `Kie upload error ${res.status}: ${body.msg}`;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
catch {
|
|
362
|
-
// ignore parse errors
|
|
363
|
-
}
|
|
364
|
-
throw new KieError(message, res.status, body);
|
|
365
|
-
}
|
|
366
|
-
return (await res.json());
|
|
367
|
-
}
|
|
368
|
-
catch (error) {
|
|
369
|
-
clearTimeout(timeoutId);
|
|
370
|
-
if (error instanceof KieError)
|
|
371
|
-
throw error;
|
|
372
|
-
throw new KieError(`Failed to upload base64 file: ${error}`, 500);
|
|
373
|
-
}
|
|
165
|
+
return await uploadTransport.postJson("/api/file-base64-upload", {
|
|
166
|
+
base64Data: req.base64Data,
|
|
167
|
+
uploadPath: req.uploadPath,
|
|
168
|
+
...(req.fileName ? { fileName: req.fileName } : {}),
|
|
169
|
+
...(req.mimeType ? { mimeType: req.mimeType } : {}),
|
|
170
|
+
});
|
|
374
171
|
}
|
|
375
172
|
// POST https://api.kie.ai/api/v1/common/download-url
|
|
376
173
|
// Docs: https://docs.kie.ai/common-api/download-url
|
|
377
174
|
async function downloadUrl(req) {
|
|
378
|
-
|
|
379
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
380
|
-
try {
|
|
381
|
-
const res = await doFetch(`${baseURL}/api/v1/common/download-url`, {
|
|
382
|
-
method: "POST",
|
|
383
|
-
headers: {
|
|
384
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
385
|
-
"Content-Type": "application/json",
|
|
386
|
-
},
|
|
387
|
-
body: JSON.stringify(req),
|
|
388
|
-
signal: controller.signal,
|
|
389
|
-
});
|
|
390
|
-
clearTimeout(timeoutId);
|
|
391
|
-
if (!res.ok) {
|
|
392
|
-
let message = `Kie API error: ${res.status}`;
|
|
393
|
-
let body = null;
|
|
394
|
-
try {
|
|
395
|
-
body = await res.json();
|
|
396
|
-
if (typeof body === "object" &&
|
|
397
|
-
body !== null &&
|
|
398
|
-
"msg" in body &&
|
|
399
|
-
typeof body.msg === "string") {
|
|
400
|
-
message = `Kie API error ${res.status}: ${body.msg}`;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
catch {
|
|
404
|
-
// ignore parse errors
|
|
405
|
-
}
|
|
406
|
-
throw new KieError(message, res.status, body);
|
|
407
|
-
}
|
|
408
|
-
return (await res.json());
|
|
409
|
-
}
|
|
410
|
-
catch (error) {
|
|
411
|
-
clearTimeout(timeoutId);
|
|
412
|
-
if (error instanceof KieError)
|
|
413
|
-
throw error;
|
|
414
|
-
throw new KieError(`Failed to get download URL: ${error}`, 500);
|
|
415
|
-
}
|
|
175
|
+
return await transport.postJson("/api/v1/common/download-url", req);
|
|
416
176
|
}
|
|
417
177
|
// POST https://api.kie.ai/api/v1/omni/audio/create
|
|
418
178
|
// Docs: https://docs.kie.ai/market/gemini-omni-audio
|
|
419
179
|
async function omniAudioCreate(req) {
|
|
420
|
-
const response = await kieRequest(
|
|
180
|
+
const response = await kieRequest(transport, {
|
|
421
181
|
method: "POST",
|
|
182
|
+
path: "/api/v1/omni/audio/create",
|
|
422
183
|
body: req,
|
|
423
|
-
apiKey: opts.apiKey,
|
|
424
|
-
doFetch,
|
|
425
|
-
timeout,
|
|
426
184
|
});
|
|
427
185
|
if (!response.data) {
|
|
428
186
|
return response;
|
|
@@ -443,42 +201,44 @@ export function createKie(opts) {
|
|
|
443
201
|
// POST https://api.kie.ai/api/v1/omni/character/create
|
|
444
202
|
// Docs: https://docs.kie.ai/market/gemini-omni-character
|
|
445
203
|
async function omniCharacterCreate(req) {
|
|
446
|
-
return kieRequest(
|
|
204
|
+
return kieRequest(transport, {
|
|
447
205
|
method: "POST",
|
|
206
|
+
path: "/api/v1/omni/character/create",
|
|
448
207
|
body: req,
|
|
449
|
-
apiKey: opts.apiKey,
|
|
450
|
-
doFetch,
|
|
451
|
-
timeout,
|
|
452
208
|
});
|
|
453
209
|
}
|
|
454
210
|
// POST https://api.kie.ai/api/v1/flux/kontext/generate
|
|
455
211
|
// Docs: https://docs.kie.ai/flux-kontext-api/generate-or-edit-image
|
|
456
212
|
async function fluxKontextGenerate(req) {
|
|
457
|
-
return kieRequest(
|
|
213
|
+
return kieRequest(transport, {
|
|
458
214
|
method: "POST",
|
|
215
|
+
path: "/api/v1/flux/kontext/generate",
|
|
459
216
|
body: req,
|
|
460
|
-
apiKey: opts.apiKey,
|
|
461
|
-
doFetch,
|
|
462
|
-
timeout,
|
|
463
217
|
});
|
|
464
218
|
}
|
|
465
219
|
// POST https://api.kie.ai/api/v1/gpt4o-image/generate
|
|
466
220
|
// Docs: https://docs.kie.ai/4o-image-api/generate-4-o-image
|
|
467
221
|
async function gpt4oImageGenerate(req) {
|
|
468
|
-
return kieRequest(
|
|
222
|
+
return kieRequest(transport, {
|
|
469
223
|
method: "POST",
|
|
224
|
+
path: "/api/v1/gpt4o-image/generate",
|
|
470
225
|
body: req,
|
|
471
|
-
apiKey: opts.apiKey,
|
|
472
|
-
doFetch,
|
|
473
|
-
timeout,
|
|
474
226
|
});
|
|
475
227
|
}
|
|
476
228
|
// POST https://api.kie.ai/api/v1/mj/generate
|
|
477
229
|
// Docs: https://docs.kie.ai/mj-api/generate-mj-image
|
|
478
230
|
async function mjGenerate(req) {
|
|
479
|
-
return kieRequest(
|
|
231
|
+
return kieRequest(transport, {
|
|
480
232
|
method: "POST",
|
|
233
|
+
path: "/api/v1/mj/generate",
|
|
481
234
|
body: req,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// GET https://api.kie.ai/api/v1/mj/record-info?taskId={taskId}
|
|
238
|
+
// Docs: https://docs.kie.ai/mj-api/get-mj-task-details
|
|
239
|
+
async function mjRecordInfo(taskId) {
|
|
240
|
+
return kieRequest(`${baseURL}/api/v1/mj/record-info?taskId=${encodeURIComponent(taskId)}`, {
|
|
241
|
+
method: "GET",
|
|
482
242
|
apiKey: opts.apiKey,
|
|
483
243
|
doFetch,
|
|
484
244
|
timeout,
|
|
@@ -487,128 +247,43 @@ export function createKie(opts) {
|
|
|
487
247
|
// POST https://api.kie.ai/api/v1/runway/generate
|
|
488
248
|
// Docs: https://docs.kie.ai/runway-api/generate-ai-video
|
|
489
249
|
async function runwayGenerate(req) {
|
|
490
|
-
return kieRequest(
|
|
250
|
+
return kieRequest(transport, {
|
|
491
251
|
method: "POST",
|
|
252
|
+
path: "/api/v1/runway/generate",
|
|
492
253
|
body: req,
|
|
493
|
-
apiKey: opts.apiKey,
|
|
494
|
-
doFetch,
|
|
495
|
-
timeout,
|
|
496
254
|
});
|
|
497
255
|
}
|
|
498
256
|
// POST https://api.kie.ai/api/v1/runway/extend
|
|
499
257
|
// Docs: https://docs.kie.ai/runway-api/extend-ai-video
|
|
500
258
|
async function runwayExtend(req) {
|
|
501
|
-
return kieRequest(
|
|
259
|
+
return kieRequest(transport, {
|
|
502
260
|
method: "POST",
|
|
261
|
+
path: "/api/v1/runway/extend",
|
|
503
262
|
body: req,
|
|
504
|
-
apiKey: opts.apiKey,
|
|
505
|
-
doFetch,
|
|
506
|
-
timeout,
|
|
507
263
|
});
|
|
508
264
|
}
|
|
509
265
|
// GET https://api.kie.ai/api/v1/runway/record-detail?taskId={taskId}
|
|
510
266
|
// Docs: https://docs.kie.ai/runway-api/get-ai-video-details
|
|
511
267
|
async function runwayRecordDetail(taskId) {
|
|
512
|
-
|
|
513
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
514
|
-
try {
|
|
515
|
-
const res = await doFetch(`${baseURL}/api/v1/runway/record-detail?taskId=${encodeURIComponent(taskId)}`, {
|
|
516
|
-
method: "GET",
|
|
517
|
-
headers: {
|
|
518
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
519
|
-
"Content-Type": "application/json",
|
|
520
|
-
},
|
|
521
|
-
signal: controller.signal,
|
|
522
|
-
});
|
|
523
|
-
clearTimeout(timeoutId);
|
|
524
|
-
if (!res.ok) {
|
|
525
|
-
let message = `Kie API error: ${res.status}`;
|
|
526
|
-
let body = null;
|
|
527
|
-
try {
|
|
528
|
-
body = await res.json();
|
|
529
|
-
if (typeof body === "object" &&
|
|
530
|
-
body !== null &&
|
|
531
|
-
"msg" in body &&
|
|
532
|
-
typeof body.msg === "string") {
|
|
533
|
-
message = `Kie API error ${res.status}: ${body.msg}`;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
catch {
|
|
537
|
-
// ignore parse errors
|
|
538
|
-
}
|
|
539
|
-
throw new KieError(message, res.status, body);
|
|
540
|
-
}
|
|
541
|
-
return (await res.json());
|
|
542
|
-
}
|
|
543
|
-
catch (error) {
|
|
544
|
-
clearTimeout(timeoutId);
|
|
545
|
-
if (error instanceof KieError)
|
|
546
|
-
throw error;
|
|
547
|
-
throw new KieError(`Failed to get Runway task: ${error}`, 500);
|
|
548
|
-
}
|
|
268
|
+
return await transport.getJson(`/api/v1/runway/record-detail?taskId=${encodeURIComponent(taskId)}`);
|
|
549
269
|
}
|
|
550
270
|
// GET https://api.kie.ai/api/v1/flux/kontext/record-info?taskId={taskId}
|
|
551
271
|
// Docs: https://docs.kie.ai/flux-kontext-api/get-image-details
|
|
552
272
|
async function fluxKontextRecordInfo(taskId) {
|
|
553
|
-
|
|
554
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
555
|
-
try {
|
|
556
|
-
const res = await doFetch(`${baseURL}/api/v1/flux/kontext/record-info?taskId=${encodeURIComponent(taskId)}`, {
|
|
557
|
-
method: "GET",
|
|
558
|
-
headers: {
|
|
559
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
560
|
-
"Content-Type": "application/json",
|
|
561
|
-
},
|
|
562
|
-
signal: controller.signal,
|
|
563
|
-
});
|
|
564
|
-
clearTimeout(timeoutId);
|
|
565
|
-
if (!res.ok) {
|
|
566
|
-
let message = `Kie API error: ${res.status}`;
|
|
567
|
-
let body = null;
|
|
568
|
-
try {
|
|
569
|
-
body = await res.json();
|
|
570
|
-
if (typeof body === "object" &&
|
|
571
|
-
body !== null &&
|
|
572
|
-
"msg" in body &&
|
|
573
|
-
typeof body.msg === "string") {
|
|
574
|
-
message = `Kie API error ${res.status}: ${body.msg}`;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
catch {
|
|
578
|
-
// ignore parse errors
|
|
579
|
-
}
|
|
580
|
-
throw new KieError(message, res.status, body);
|
|
581
|
-
}
|
|
582
|
-
return (await res.json());
|
|
583
|
-
}
|
|
584
|
-
catch (error) {
|
|
585
|
-
clearTimeout(timeoutId);
|
|
586
|
-
if (error instanceof KieError)
|
|
587
|
-
throw error;
|
|
588
|
-
throw new KieError(`Failed to get Flux Kontext task: ${error}`, 500);
|
|
589
|
-
}
|
|
273
|
+
return await transport.getJson(`/api/v1/flux/kontext/record-info?taskId=${encodeURIComponent(taskId)}`);
|
|
590
274
|
}
|
|
591
275
|
// GET https://api.kie.ai/api/v1/chat/credit
|
|
592
276
|
// Docs: https://docs.kie.ai/common-api/get-account-credits
|
|
593
277
|
async function credit() {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
});
|
|
601
|
-
if (!res.ok) {
|
|
602
|
-
let body = null;
|
|
603
|
-
try {
|
|
604
|
-
body = await res.json();
|
|
605
|
-
}
|
|
606
|
-
catch {
|
|
607
|
-
// ignore parse errors
|
|
278
|
+
try {
|
|
279
|
+
return await transport.getJson("/api/v1/chat/credit");
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (error instanceof KieError) {
|
|
283
|
+
throw new KieError(`Failed to get credits: ${error.status}`, error.status, error.body, error.code);
|
|
608
284
|
}
|
|
609
|
-
throw
|
|
285
|
+
throw error;
|
|
610
286
|
}
|
|
611
|
-
return (await res.json());
|
|
612
287
|
}
|
|
613
288
|
return attachExamples(withPaidGate("kie", {
|
|
614
289
|
veo: withPaidGate("kie", createVeoProvider(baseURL, opts.apiKey, doFetch, timeout), { config: paygate }),
|
|
@@ -697,6 +372,12 @@ export function createKie(opts) {
|
|
|
697
372
|
responseSchema: Gpt4oImageRecordInfoResponseSchema,
|
|
698
373
|
}),
|
|
699
374
|
},
|
|
375
|
+
mj: {
|
|
376
|
+
recordInfo: Object.assign(mjRecordInfo, {
|
|
377
|
+
schema: MjRecordInfoRequestSchema,
|
|
378
|
+
responseSchema: MjRecordInfoResponseSchema,
|
|
379
|
+
}),
|
|
380
|
+
},
|
|
700
381
|
runway: {
|
|
701
382
|
recordDetail: Object.assign(runwayRecordDetail, {
|
|
702
383
|
schema: RecordInfoRequestSchema,
|