getaiapi 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 getaiapi contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # getaiapi
2
+
3
+ **One function to call any AI model.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/getaiapi)](https://www.npmjs.com/package/getaiapi)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)
8
+
9
+ A unified TypeScript library that wraps 1,929 AI models across 3 providers into a single `generate()` function. One input shape. One output shape. Any model.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install getaiapi
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import { generate } from 'getaiapi'
21
+
22
+ const result = await generate({
23
+ model: 'flux-schnell',
24
+ prompt: 'a cat wearing sunglasses'
25
+ })
26
+
27
+ console.log(result.outputs[0].url)
28
+ ```
29
+
30
+ ## More Examples
31
+
32
+ **Text-to-video**
33
+
34
+ ```typescript
35
+ const video = await generate({
36
+ model: 'veo3.1',
37
+ prompt: 'a timelapse of a flower blooming in a garden'
38
+ })
39
+ ```
40
+
41
+ **Image editing**
42
+
43
+ ```typescript
44
+ const edited = await generate({
45
+ model: 'gpt-image-1.5-edit',
46
+ image: 'https://example.com/photo.jpg',
47
+ prompt: 'add a rainbow in the sky'
48
+ })
49
+ ```
50
+
51
+ **Text-to-speech**
52
+
53
+ ```typescript
54
+ const speech = await generate({
55
+ model: 'elevenlabs-v3',
56
+ prompt: 'Hello, welcome to getaiapi.',
57
+ options: { voice_id: 'rachel' }
58
+ })
59
+ ```
60
+
61
+ **Upscale an image**
62
+
63
+ ```typescript
64
+ const upscaled = await generate({
65
+ model: 'topaz-upscale-image',
66
+ image: 'https://example.com/low-res.jpg'
67
+ })
68
+ ```
69
+
70
+ **Remove background**
71
+
72
+ ```typescript
73
+ const cutout = await generate({
74
+ model: 'birefnet-v2',
75
+ image: 'https://example.com/portrait.jpg'
76
+ })
77
+ ```
78
+
79
+ ## Configuration
80
+
81
+ Set API keys as environment variables for the providers you want to use. You only need keys for the providers you plan to call.
82
+
83
+ ```bash
84
+ # fal-ai (1,199 models)
85
+ export FAL_KEY="your-fal-key"
86
+
87
+ # Replicate (687 models)
88
+ export REPLICATE_API_TOKEN="your-replicate-token"
89
+
90
+ # WaveSpeed (43 models)
91
+ export WAVESPEED_API_KEY="your-wavespeed-key"
92
+ ```
93
+
94
+ Models are automatically filtered to only show providers where you have a valid key configured.
95
+
96
+ ## Model Discovery
97
+
98
+ ```typescript
99
+ import { listModels, getModel } from 'getaiapi'
100
+
101
+ // List all available models (filtered by your API keys)
102
+ const all = listModels()
103
+
104
+ // Filter by category
105
+ const imageModels = listModels({ category: 'text-to-image' })
106
+
107
+ // Filter by provider
108
+ const falModels = listModels({ provider: 'fal-ai' })
109
+
110
+ // Search by name
111
+ const fluxModels = listModels({ query: 'flux' })
112
+
113
+ // Get details for a specific model
114
+ const model = getModel('flux-schnell')
115
+ // => { canonical_name, aliases, category, modality, providers }
116
+ ```
117
+
118
+ ## Supported Categories
119
+
120
+ | Category | Input | Output | Models |
121
+ |---|---|---|---|
122
+ | `text-to-image` | text | image | 828 |
123
+ | `text-to-video` | text | video | 308 |
124
+ | `image-edit` | image + text | image | 213 |
125
+ | `image-to-video` | image + text | video | 178 |
126
+ | `text-to-audio` | text | audio | 76 |
127
+ | `upscale-image` | image | image | 59 |
128
+ | `training` | images | model | 50 |
129
+ | `image-to-image` | image + text | image | 43 |
130
+ | `segmentation` | image/video | segmentation | 34 |
131
+ | `image-to-3d` | image | 3d | 31 |
132
+ | `audio-to-text` | audio | text | 25 |
133
+ | `remove-background` | image/video | image/video | 24 |
134
+ | `text-to-3d` | text | 3d | 19 |
135
+ | `video-to-audio` | video | audio | 18 |
136
+ | `upscale-video` | video | video | 15 |
137
+ | `moderation` | text/image/video | text | 8 |
138
+
139
+ ## Providers
140
+
141
+ | Provider | Models | Auth Env Var | Protocol |
142
+ |---|---|---|---|
143
+ | fal-ai | 1,199 | `FAL_KEY` | Native fetch |
144
+ | Replicate | 687 | `REPLICATE_API_TOKEN` | Native fetch |
145
+ | WaveSpeed | 43 | `WAVESPEED_API_KEY` | Native fetch |
146
+
147
+ Zero external dependencies -- all provider communication uses native `fetch`.
148
+
149
+ ## API Reference
150
+
151
+ ### `generate(request: GenerateRequest): Promise<GenerateResponse>`
152
+
153
+ The core function. Resolves the model, maps parameters, calls the provider, and returns a unified response.
154
+
155
+ **GenerateRequest**
156
+
157
+ ```typescript
158
+ interface GenerateRequest {
159
+ model: string // required - model name
160
+ prompt?: string // text prompt
161
+ image?: string | File // input image (URL or File)
162
+ audio?: string | File // input audio
163
+ video?: string | File // input video
164
+ negative_prompt?: string // what to avoid
165
+ count?: number // number of outputs
166
+ size?: string | { width: number; height: number } // output dimensions
167
+ seed?: number // reproducibility seed
168
+ guidance?: number // guidance scale
169
+ steps?: number // inference steps
170
+ strength?: number // denoising strength
171
+ format?: 'png' | 'jpeg' | 'webp' | 'mp4' | 'mp3' | 'wav' | 'obj' | 'glb'
172
+ quality?: number // output quality
173
+ safety?: boolean // enable safety checker
174
+ options?: Record<string, unknown> // provider-specific overrides
175
+ }
176
+ ```
177
+
178
+ **GenerateResponse**
179
+
180
+ ```typescript
181
+ interface GenerateResponse {
182
+ id: string
183
+ model: string
184
+ provider: string
185
+ status: 'completed' | 'failed'
186
+ outputs: OutputItem[]
187
+ metadata: {
188
+ seed?: number
189
+ inference_time_ms?: number
190
+ cost?: number
191
+ safety_flagged?: boolean
192
+ }
193
+ }
194
+
195
+ interface OutputItem {
196
+ type: 'image' | 'video' | 'audio' | 'text' | '3d' | 'segmentation'
197
+ url: string
198
+ content_type: string
199
+ size_bytes?: number
200
+ }
201
+ ```
202
+
203
+ ### `listModels(filters?: ListModelsFilters): ModelEntry[]`
204
+
205
+ Returns all models the caller has API keys for. Accepts optional filters:
206
+
207
+ - `category` -- filter by model category (e.g. `'text-to-image'`)
208
+ - `provider` -- filter by provider (e.g. `'fal-ai'`)
209
+ - `query` -- search canonical names and aliases
210
+
211
+ ### `getModel(name: string): ModelEntry`
212
+
213
+ Resolves a model by name. Accepts canonical names, aliases, and normalized variants. Throws `ModelNotFoundError` if no match is found.
214
+
215
+ ## Error Handling
216
+
217
+ All errors extend `GetAIApiError` and can be caught uniformly or by type:
218
+
219
+ | Error | When |
220
+ |---|---|
221
+ | `AuthError` | Missing or invalid API key for a provider |
222
+ | `ModelNotFoundError` | Model name could not be resolved |
223
+ | `ValidationError` | Invalid input parameters |
224
+ | `ProviderError` | Provider returned an error response |
225
+ | `TimeoutError` | Generation exceeded the timeout |
226
+ | `RateLimitError` | Provider returned HTTP 429 |
227
+
228
+ ```typescript
229
+ import { generate, AuthError, ModelNotFoundError } from 'getaiapi'
230
+
231
+ try {
232
+ const result = await generate({ model: 'flux-schnell', prompt: 'a cat' })
233
+ } catch (err) {
234
+ if (err instanceof AuthError) {
235
+ console.error(`Set ${err.envVar} to use ${err.provider}`)
236
+ }
237
+ if (err instanceof ModelNotFoundError) {
238
+ console.error(err.message) // includes "did you mean" suggestions
239
+ }
240
+ }
241
+ ```
242
+
243
+ ## Documentation
244
+
245
+ Full documentation available at [interactive10.com/getaiapi.html](https://www.interactive10.com/getaiapi.html)
246
+
247
+ ## License
248
+
249
+ MIT