getaiapi 1.3.0 → 1.3.1

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
@@ -6,7 +6,7 @@
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)
8
8
 
9
- A unified TypeScript library that wraps 1,890+ AI models across 4 providers into a single `generate()` function. One input shape. One output shape. Any model.
9
+ A unified TypeScript library that wraps 1,890+ AI models across 5 providers into a single `generate()` function. One input shape. One output shape. Any model.
10
10
 
11
11
  ## Install
12
12
 
@@ -106,6 +106,18 @@ const upscaled = await generate({
106
106
  })
107
107
  ```
108
108
 
109
+ **Kling native provider** (bypass fal-ai, call Kling API directly)
110
+
111
+ ```typescript
112
+ const video = await generate({
113
+ model: 'kling-video-v3-pro-text-to-video',
114
+ provider: 'kling', // uses KLING_ACCESS_KEY directly
115
+ prompt: 'a golden retriever running on a beach at sunset',
116
+ duration: '5',
117
+ options: { aspect_ratio: '16:9', sound: 'on' },
118
+ })
119
+ ```
120
+
109
121
  **Remove background**
110
122
 
111
123
  ```typescript
@@ -175,6 +187,10 @@ export WAVESPEED_API_KEY="your-wavespeed-key"
175
187
 
176
188
  # OpenRouter (24 LLM models — Claude, GPT, Gemini, Llama, etc.)
177
189
  export OPENROUTER_API_KEY="your-openrouter-key"
190
+
191
+ # Kling AI (69 models — native API, bypasses fal-ai middleman)
192
+ export KLING_ACCESS_KEY="your-access-key"
193
+ export KLING_SECRET_KEY="your-secret-key"
178
194
  ```
179
195
 
180
196
  ### Option 2: Programmatic Configuration
@@ -190,6 +206,7 @@ configure({
190
206
  'replicate': process.env.MY_REPLICATE_TOKEN,
191
207
  'wavespeed': process.env.MY_WAVESPEED_TOKEN,
192
208
  'openrouter': process.env.MY_OPENROUTER_TOKEN,
209
+ 'kling': `${process.env.MY_KLING_AK}:${process.env.MY_KLING_SK}`,
193
210
  },
194
211
  })
195
212
  ```
@@ -259,7 +276,7 @@ Models declare their input and output types via `modality`. There are no fixed c
259
276
 
260
277
  **Output types:** `image`, `video`, `audio`, `text`, `3d`, `segmentation`
261
278
 
262
- Common combinations across 1,890+ models:
279
+ Common combinations across 1,890+ models (69 with native Kling provider):
263
280
 
264
281
  | Inputs | Outputs | Example |
265
282
  |---|---|---|
@@ -279,9 +296,14 @@ Common combinations across 1,890+ models:
279
296
  |---|---|---|---|
280
297
  | fal-ai | 1,201 | `FAL_KEY` | Native fetch |
281
298
  | Replicate | 687 | `REPLICATE_API_TOKEN` | Native fetch |
299
+ | Kling AI | 69 | `KLING_ACCESS_KEY` | Native fetch + JWT |
282
300
  | WaveSpeed | 66 | `WAVESPEED_API_KEY` | Native fetch |
283
301
  | OpenRouter | 24 | `OPENROUTER_API_KEY` | Native fetch |
284
302
 
303
+ Many Kling models are available through both fal-ai and the native Kling provider. Using `provider: 'kling'` calls the Kling API directly with JWT authentication, bypassing intermediary markup. Set both `KLING_ACCESS_KEY` and `KLING_SECRET_KEY` env vars (or pass them combined as `accessKey:secretKey` via `configure()`).
304
+
305
+ **Provider portability** -- the same code works across providers. Parameter names are aligned: `generate_audio`, `end_image_url`, `voice_ids`, and `elements` work identically whether you use `provider: 'fal-ai'` or `provider: 'kling'`. The library automatically translates to each provider's native field names (e.g., `generate_audio: true` becomes `sound: "on"` for Kling, stays `generate_audio: true` for fal-ai).
306
+
285
307
  Zero external dependencies -- all provider communication uses native `fetch`. Works in Node.js, Vercel Edge, Cloudflare Workers, Deno, Bun, and any ESM runtime -- no `fs` or special bundler config needed.
286
308
 
287
309
  ## API Reference
@@ -293,9 +315,9 @@ The core function. Resolves the model, maps parameters, calls the provider, and
293
315
  **GenerateRequest**
294
316
 
295
317
  ```typescript
296
- interface GenerateRequest {
318
+ interface GenerateRequest<P extends ProviderName = ProviderName> {
297
319
  model: string // required - model name
298
- provider?: ProviderName // preferred provider (optional)
320
+ provider?: P // preferred provider (optional)
299
321
  prompt?: string // text prompt
300
322
  image?: string | File // input image (URL or File)
301
323
  images?: (string | File)[] // multiple reference images
@@ -311,10 +333,29 @@ interface GenerateRequest {
311
333
  format?: 'png' | 'jpeg' | 'webp' | 'mp4' | 'mp3' | 'wav' | 'obj' | 'glb'
312
334
  quality?: number // output quality
313
335
  safety?: boolean // enable safety checker
314
- options?: Record<string, unknown> // provider-specific overrides
336
+ duration?: string // output duration (video/audio)
337
+ options?: ProviderOptionsFor<P> // provider-specific overrides
315
338
  }
316
339
  ```
317
340
 
341
+ The generic `P` narrows `options` by provider. Use `GenerateRequest<'kling'>` for type-safe Kling options:
342
+
343
+ ```typescript
344
+ const req: GenerateRequest<'kling'> = {
345
+ model: 'kling-video-v3-pro-image-to-video',
346
+ provider: 'kling',
347
+ image: 'https://example.com/img.png',
348
+ prompt: 'Animate this photo',
349
+ options: {
350
+ sound: 'on', // typed: 'on' | 'off'
351
+ aspect_ratio: '16:9', // typed: string
352
+ cfg_scale: 0.5, // typed: number
353
+ },
354
+ }
355
+ ```
356
+
357
+ Without a generic, `options` accepts any `Record<string, unknown>` (backward compatible).
358
+
318
359
  **GenerateResponse**
319
360
 
320
361
  ```typescript