getaiapi 1.0.0-alpha.2 → 1.0.0-alpha.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 +76 -0
- package/dist/{chunk-34X3VRM3.js → chunk-DZVZ5HSO.js} +133 -72
- package/dist/{chunk-34X3VRM3.js.map → chunk-DZVZ5HSO.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,6 +115,48 @@ const cutout = await generate({
|
|
|
115
115
|
})
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
## Async Job Control
|
|
119
|
+
|
|
120
|
+
For long-running jobs (video generation, training), you can submit a job and poll for status separately instead of blocking until completion.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { submit, poll } from 'getaiapi'
|
|
124
|
+
|
|
125
|
+
// Submit — returns immediately with the provider's task ID
|
|
126
|
+
const job = await submit({
|
|
127
|
+
model: 'veo3.1',
|
|
128
|
+
prompt: 'a timelapse of a flower blooming',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
console.log(job.id) // provider task ID
|
|
132
|
+
console.log(job.status) // 'pending' | 'processing' | 'completed'
|
|
133
|
+
|
|
134
|
+
// Poll — check status manually (call in a loop, on a timer, etc.)
|
|
135
|
+
let result = await poll(job)
|
|
136
|
+
|
|
137
|
+
while (result.status === 'pending' || result.status === 'processing') {
|
|
138
|
+
await new Promise(r => setTimeout(r, 2000))
|
|
139
|
+
result = await poll(job)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (result.status === 'completed') {
|
|
143
|
+
console.log(result.outputs[0].url)
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Synchronous providers (like OpenRouter) return `status: 'completed'` from `submit()` immediately -- check status before polling.
|
|
148
|
+
|
|
149
|
+
`submitAndPoll()` is an alias for `generate()` that makes the blocking behavior explicit:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { submitAndPoll } from 'getaiapi'
|
|
153
|
+
|
|
154
|
+
const result = await submitAndPoll({
|
|
155
|
+
model: 'flux-schnell',
|
|
156
|
+
prompt: 'a cat in space',
|
|
157
|
+
})
|
|
158
|
+
```
|
|
159
|
+
|
|
118
160
|
## Configuration
|
|
119
161
|
|
|
120
162
|
### Option 1: Environment Variables
|
|
@@ -302,6 +344,40 @@ interface OutputItem {
|
|
|
302
344
|
}
|
|
303
345
|
```
|
|
304
346
|
|
|
347
|
+
### `submit(request: GenerateRequest): Promise<SubmitResponse>`
|
|
348
|
+
|
|
349
|
+
Submits a job to the provider and returns immediately without waiting for completion. Returns the provider's task ID and enough context to poll later.
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
interface SubmitResponse {
|
|
353
|
+
id: string // provider's task/request ID
|
|
354
|
+
model: string // canonical model name
|
|
355
|
+
provider: ProviderName // which provider handled it
|
|
356
|
+
endpoint: string // needed for polling
|
|
357
|
+
status: 'pending' | 'processing' | 'completed'
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### `poll(job: SubmitResponse): Promise<PollResponse>`
|
|
362
|
+
|
|
363
|
+
Checks the status of a submitted job once. Returns current status, and includes mapped outputs and metadata when completed.
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
interface PollResponse {
|
|
367
|
+
id: string
|
|
368
|
+
model: string
|
|
369
|
+
provider: ProviderName
|
|
370
|
+
status: 'completed' | 'failed' | 'processing' | 'pending'
|
|
371
|
+
outputs?: OutputItem[] // populated when completed
|
|
372
|
+
metadata?: GenerateResponse['metadata'] // populated when completed
|
|
373
|
+
error?: string // populated when failed
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### `submitAndPoll(request: GenerateRequest): Promise<GenerateResponse>`
|
|
378
|
+
|
|
379
|
+
Alias for `generate()`. Submits a job and polls until completion. Use this when you want the blocking behavior but want to be explicit about it.
|
|
380
|
+
|
|
305
381
|
### `listModels(filters?: ListModelsFilters): ModelEntry[]`
|
|
306
382
|
|
|
307
383
|
Returns all models in the registry. Accepts optional filters:
|
|
@@ -32511,11 +32511,9 @@ var registry_default = [
|
|
|
32511
32511
|
video: "video_url",
|
|
32512
32512
|
image: "image_url",
|
|
32513
32513
|
prompt: "prompt",
|
|
32514
|
-
|
|
32515
|
-
|
|
32516
|
-
|
|
32517
|
-
steps: "num_inference_steps",
|
|
32518
|
-
safety: "enable_safety_checker"
|
|
32514
|
+
character_orientation: "character_orientation",
|
|
32515
|
+
keep_audio: "keep_original_sound",
|
|
32516
|
+
elements: "elements"
|
|
32519
32517
|
},
|
|
32520
32518
|
output_map: {
|
|
32521
32519
|
type: "video",
|
|
@@ -32530,13 +32528,11 @@ var registry_default = [
|
|
|
32530
32528
|
auth_env: "REPLICATE_API_TOKEN",
|
|
32531
32529
|
param_map: {
|
|
32532
32530
|
video: "video",
|
|
32533
|
-
image: "
|
|
32531
|
+
image: "image",
|
|
32534
32532
|
prompt: "prompt",
|
|
32535
|
-
|
|
32536
|
-
|
|
32537
|
-
|
|
32538
|
-
steps: "num_inference_steps",
|
|
32539
|
-
safety: "enable_safety_checker"
|
|
32533
|
+
character_orientation: "character_orientation",
|
|
32534
|
+
mode: "mode",
|
|
32535
|
+
keep_audio: "keep_original_sound"
|
|
32540
32536
|
},
|
|
32541
32537
|
output_map: {
|
|
32542
32538
|
type: "video",
|
|
@@ -45366,15 +45362,15 @@ var registry_default = [
|
|
|
45366
45362
|
auth_env: "FAL_KEY",
|
|
45367
45363
|
param_map: {
|
|
45368
45364
|
prompt: "prompt",
|
|
45369
|
-
|
|
45365
|
+
images: "image_urls",
|
|
45370
45366
|
count: "num_images",
|
|
45371
|
-
size: "image_size",
|
|
45372
|
-
guidance: "guidance_scale",
|
|
45373
|
-
steps: "num_inference_steps",
|
|
45374
45367
|
seed: "seed",
|
|
45368
|
+
resolution: "resolution",
|
|
45369
|
+
aspect_ratio: "aspect_ratio",
|
|
45375
45370
|
format: "output_format",
|
|
45376
|
-
|
|
45377
|
-
|
|
45371
|
+
safety_tolerance: "safety_tolerance",
|
|
45372
|
+
web_search: "enable_web_search",
|
|
45373
|
+
thinking_level: "thinking_level"
|
|
45378
45374
|
},
|
|
45379
45375
|
output_map: {
|
|
45380
45376
|
type: "image",
|
|
@@ -45389,18 +45385,12 @@ var registry_default = [
|
|
|
45389
45385
|
auth_env: "REPLICATE_API_TOKEN",
|
|
45390
45386
|
param_map: {
|
|
45391
45387
|
prompt: "prompt",
|
|
45392
|
-
|
|
45393
|
-
|
|
45394
|
-
|
|
45395
|
-
"width",
|
|
45396
|
-
"height"
|
|
45397
|
-
],
|
|
45398
|
-
guidance: "guidance",
|
|
45399
|
-
steps: "num_inference_steps",
|
|
45400
|
-
seed: "seed",
|
|
45388
|
+
images: "image_input",
|
|
45389
|
+
resolution: "resolution",
|
|
45390
|
+
aspect_ratio: "aspect_ratio",
|
|
45401
45391
|
format: "output_format",
|
|
45402
|
-
|
|
45403
|
-
|
|
45392
|
+
web_search: "google_search",
|
|
45393
|
+
image_search: "image_search"
|
|
45404
45394
|
},
|
|
45405
45395
|
output_map: {
|
|
45406
45396
|
type: "image",
|
|
@@ -45432,15 +45422,16 @@ var registry_default = [
|
|
|
45432
45422
|
endpoint: "fal-ai/nano-banana-2/edit",
|
|
45433
45423
|
auth_env: "FAL_KEY",
|
|
45434
45424
|
param_map: {
|
|
45435
|
-
image: "image_url",
|
|
45436
|
-
images: "image_urls",
|
|
45437
45425
|
prompt: "prompt",
|
|
45438
|
-
|
|
45439
|
-
|
|
45426
|
+
images: "image_urls",
|
|
45427
|
+
count: "num_images",
|
|
45440
45428
|
seed: "seed",
|
|
45429
|
+
resolution: "resolution",
|
|
45430
|
+
aspect_ratio: "aspect_ratio",
|
|
45441
45431
|
format: "output_format",
|
|
45442
|
-
|
|
45443
|
-
|
|
45432
|
+
safety_tolerance: "safety_tolerance",
|
|
45433
|
+
web_search: "enable_web_search",
|
|
45434
|
+
thinking_level: "thinking_level"
|
|
45444
45435
|
},
|
|
45445
45436
|
output_map: {
|
|
45446
45437
|
type: "image",
|
|
@@ -45454,15 +45445,11 @@ var registry_default = [
|
|
|
45454
45445
|
endpoint: "google/nano-banana-2/edit",
|
|
45455
45446
|
auth_env: "WAVESPEED_API_KEY",
|
|
45456
45447
|
param_map: {
|
|
45457
|
-
image: "image_url",
|
|
45458
|
-
images: "image_urls",
|
|
45459
45448
|
prompt: "prompt",
|
|
45460
|
-
|
|
45461
|
-
|
|
45449
|
+
image: "image",
|
|
45450
|
+
images: "image_urls",
|
|
45462
45451
|
seed: "seed",
|
|
45463
|
-
format: "output_format"
|
|
45464
|
-
quality: "quality",
|
|
45465
|
-
safety: "enable_safety_checker"
|
|
45452
|
+
format: "output_format"
|
|
45466
45453
|
},
|
|
45467
45454
|
output_map: {
|
|
45468
45455
|
type: "image",
|
|
@@ -48632,6 +48619,7 @@ var registry_default = [
|
|
|
48632
48619
|
modality: {
|
|
48633
48620
|
inputs: [
|
|
48634
48621
|
"audio",
|
|
48622
|
+
"text",
|
|
48635
48623
|
"video"
|
|
48636
48624
|
],
|
|
48637
48625
|
outputs: [
|
|
@@ -48646,13 +48634,9 @@ var registry_default = [
|
|
|
48646
48634
|
auth_env: "FAL_KEY",
|
|
48647
48635
|
param_map: {
|
|
48648
48636
|
video: "video_url",
|
|
48649
|
-
|
|
48650
|
-
|
|
48651
|
-
|
|
48652
|
-
seed: "seed",
|
|
48653
|
-
guidance: "guidance_scale",
|
|
48654
|
-
steps: "num_inference_steps",
|
|
48655
|
-
safety: "enable_safety_checker"
|
|
48637
|
+
audio: "audio_url",
|
|
48638
|
+
text: "text",
|
|
48639
|
+
voice_id: "voice_id"
|
|
48656
48640
|
},
|
|
48657
48641
|
output_map: {
|
|
48658
48642
|
type: "video",
|
|
@@ -48667,13 +48651,7 @@ var registry_default = [
|
|
|
48667
48651
|
auth_env: "REPLICATE_API_TOKEN",
|
|
48668
48652
|
param_map: {
|
|
48669
48653
|
video: "video",
|
|
48670
|
-
|
|
48671
|
-
prompt: "prompt",
|
|
48672
|
-
resolution: "resolution",
|
|
48673
|
-
seed: "seed",
|
|
48674
|
-
guidance: "guidance_scale",
|
|
48675
|
-
steps: "num_inference_steps",
|
|
48676
|
-
safety: "enable_safety_checker"
|
|
48654
|
+
audio: "audio"
|
|
48677
48655
|
},
|
|
48678
48656
|
output_map: {
|
|
48679
48657
|
type: "video",
|
|
@@ -48950,12 +48928,11 @@ var registry_default = [
|
|
|
48950
48928
|
param_map: {
|
|
48951
48929
|
video: "video_url",
|
|
48952
48930
|
image: "image_url",
|
|
48953
|
-
prompt: "prompt",
|
|
48954
48931
|
resolution: "resolution",
|
|
48955
48932
|
seed: "seed",
|
|
48956
|
-
|
|
48957
|
-
|
|
48958
|
-
|
|
48933
|
+
mode: "mode",
|
|
48934
|
+
keep_audio: "original_sound_switch",
|
|
48935
|
+
keyframe: "keyframe_id"
|
|
48959
48936
|
},
|
|
48960
48937
|
output_map: {
|
|
48961
48938
|
type: "video",
|
|
@@ -64763,14 +64740,19 @@ var registry_default = [
|
|
|
64763
64740
|
endpoint: "fal-ai/wan/v2.2-14b/animate/move",
|
|
64764
64741
|
auth_env: "FAL_KEY",
|
|
64765
64742
|
param_map: {
|
|
64743
|
+
video: "video_url",
|
|
64766
64744
|
image: "image_url",
|
|
64767
|
-
|
|
64768
|
-
negative_prompt: "negative_prompt",
|
|
64745
|
+
resolution: "resolution",
|
|
64769
64746
|
seed: "seed",
|
|
64770
64747
|
guidance: "guidance_scale",
|
|
64771
64748
|
steps: "num_inference_steps",
|
|
64772
|
-
|
|
64773
|
-
|
|
64749
|
+
safety: "enable_safety_checker",
|
|
64750
|
+
shift: "shift",
|
|
64751
|
+
video_write_mode: "video_write_mode",
|
|
64752
|
+
video_quality: "video_quality",
|
|
64753
|
+
turbo: "use_turbo",
|
|
64754
|
+
output_safety: "enable_output_safety_checker",
|
|
64755
|
+
return_frames_zip: "return_frames_zip"
|
|
64774
64756
|
},
|
|
64775
64757
|
output_map: {
|
|
64776
64758
|
type: "video",
|
|
@@ -64804,12 +64786,17 @@ var registry_default = [
|
|
|
64804
64786
|
param_map: {
|
|
64805
64787
|
video: "video_url",
|
|
64806
64788
|
image: "image_url",
|
|
64807
|
-
prompt: "prompt",
|
|
64808
64789
|
resolution: "resolution",
|
|
64809
64790
|
seed: "seed",
|
|
64810
64791
|
guidance: "guidance_scale",
|
|
64811
64792
|
steps: "num_inference_steps",
|
|
64812
|
-
safety: "enable_safety_checker"
|
|
64793
|
+
safety: "enable_safety_checker",
|
|
64794
|
+
shift: "shift",
|
|
64795
|
+
video_write_mode: "video_write_mode",
|
|
64796
|
+
video_quality: "video_quality",
|
|
64797
|
+
turbo: "use_turbo",
|
|
64798
|
+
output_safety: "enable_output_safety_checker",
|
|
64799
|
+
return_frames_zip: "return_frames_zip"
|
|
64813
64800
|
},
|
|
64814
64801
|
output_map: {
|
|
64815
64802
|
type: "video",
|
|
@@ -64825,12 +64812,10 @@ var registry_default = [
|
|
|
64825
64812
|
param_map: {
|
|
64826
64813
|
video: "video",
|
|
64827
64814
|
image: "character_image",
|
|
64828
|
-
prompt: "prompt",
|
|
64829
64815
|
resolution: "resolution",
|
|
64830
64816
|
seed: "seed",
|
|
64831
|
-
|
|
64832
|
-
|
|
64833
|
-
safety: "enable_safety_checker"
|
|
64817
|
+
keep_audio: "merge_audio",
|
|
64818
|
+
turbo: "go_fast"
|
|
64834
64819
|
},
|
|
64835
64820
|
output_map: {
|
|
64836
64821
|
type: "video",
|
|
@@ -71950,8 +71935,7 @@ var adapters = {
|
|
|
71950
71935
|
"openrouter": openRouterAdapter
|
|
71951
71936
|
};
|
|
71952
71937
|
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
71953
|
-
async function
|
|
71954
|
-
const startTime = Date.now();
|
|
71938
|
+
async function _prepare(request) {
|
|
71955
71939
|
if (!request.model) throw new ValidationError("model", "model is required");
|
|
71956
71940
|
const auth = new AuthManager();
|
|
71957
71941
|
const model = resolveModel(request.model, auth.availableProviders());
|
|
@@ -71980,6 +71964,80 @@ async function generate(request) {
|
|
|
71980
71964
|
});
|
|
71981
71965
|
const adapter = adapters[binding.provider];
|
|
71982
71966
|
const apiKey = auth.getKey(binding.provider);
|
|
71967
|
+
return { binding, adapter, apiKey, finalParams, model };
|
|
71968
|
+
}
|
|
71969
|
+
async function submit(request) {
|
|
71970
|
+
const { binding, adapter, apiKey, finalParams, model } = await _prepare(request);
|
|
71971
|
+
const timeoutMs = request.options?.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
71972
|
+
const submitted = await withRetry(
|
|
71973
|
+
() => adapter.submit(binding.endpoint, finalParams, apiKey),
|
|
71974
|
+
{ timeoutMs, provider: binding.provider, model: model.canonical_name }
|
|
71975
|
+
);
|
|
71976
|
+
return {
|
|
71977
|
+
id: submitted.id,
|
|
71978
|
+
model: model.canonical_name,
|
|
71979
|
+
provider: binding.provider,
|
|
71980
|
+
endpoint: binding.endpoint,
|
|
71981
|
+
status: submitted.status === "completed" ? "completed" : submitted.status
|
|
71982
|
+
};
|
|
71983
|
+
}
|
|
71984
|
+
async function poll(job) {
|
|
71985
|
+
const adapter = adapters[job.provider];
|
|
71986
|
+
if (!adapter) {
|
|
71987
|
+
throw new ValidationError("provider", `Unknown provider "${job.provider}"`);
|
|
71988
|
+
}
|
|
71989
|
+
const auth = new AuthManager();
|
|
71990
|
+
const apiKey = auth.getKey(job.provider);
|
|
71991
|
+
const result = await adapter.poll(job.id, apiKey, job.endpoint);
|
|
71992
|
+
if (result.status === "completed") {
|
|
71993
|
+
const model = resolveModel(job.model, auth.availableProviders());
|
|
71994
|
+
const binding = model.providers.find((p) => p.provider === job.provider);
|
|
71995
|
+
if (!binding) {
|
|
71996
|
+
throw new ProviderError(job.provider, job.model, 0, "Could not resolve provider binding for output mapping");
|
|
71997
|
+
}
|
|
71998
|
+
const outputs = mapOutput(result.output, binding.output_map);
|
|
71999
|
+
const rawOutput = typeof result.output === "object" && result.output !== null ? result.output : void 0;
|
|
72000
|
+
const metadata = {
|
|
72001
|
+
seed: rawOutput?.seed,
|
|
72002
|
+
safety_flagged: rawOutput ? Array.isArray(rawOutput.has_nsfw_concepts) ? rawOutput.has_nsfw_concepts.some((v) => v) : void 0 : void 0
|
|
72003
|
+
};
|
|
72004
|
+
if (rawOutput?.usage) {
|
|
72005
|
+
const usage = rawOutput.usage;
|
|
72006
|
+
metadata.tokens = usage.total_tokens;
|
|
72007
|
+
metadata.prompt_tokens = usage.prompt_tokens;
|
|
72008
|
+
metadata.completion_tokens = usage.completion_tokens;
|
|
72009
|
+
}
|
|
72010
|
+
return {
|
|
72011
|
+
id: job.id,
|
|
72012
|
+
model: job.model,
|
|
72013
|
+
provider: job.provider,
|
|
72014
|
+
status: "completed",
|
|
72015
|
+
outputs,
|
|
72016
|
+
metadata
|
|
72017
|
+
};
|
|
72018
|
+
}
|
|
72019
|
+
if (result.status === "failed") {
|
|
72020
|
+
return {
|
|
72021
|
+
id: job.id,
|
|
72022
|
+
model: job.model,
|
|
72023
|
+
provider: job.provider,
|
|
72024
|
+
status: "failed",
|
|
72025
|
+
error: result.error || "Generation failed"
|
|
72026
|
+
};
|
|
72027
|
+
}
|
|
72028
|
+
return {
|
|
72029
|
+
id: job.id,
|
|
72030
|
+
model: job.model,
|
|
72031
|
+
provider: job.provider,
|
|
72032
|
+
status: result.status
|
|
72033
|
+
};
|
|
72034
|
+
}
|
|
72035
|
+
async function submitAndPoll(request) {
|
|
72036
|
+
return generate(request);
|
|
72037
|
+
}
|
|
72038
|
+
async function generate(request) {
|
|
72039
|
+
const startTime = Date.now();
|
|
72040
|
+
const { binding, adapter, apiKey, finalParams, model } = await _prepare(request);
|
|
71983
72041
|
const timeoutMs = request.options?.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
71984
72042
|
const submitted = await withRetry(
|
|
71985
72043
|
() => adapter.submit(binding.endpoint, finalParams, apiKey),
|
|
@@ -72076,8 +72134,11 @@ export {
|
|
|
72076
72134
|
uploadAsset,
|
|
72077
72135
|
presignAsset,
|
|
72078
72136
|
deleteAsset,
|
|
72137
|
+
submit,
|
|
72138
|
+
poll,
|
|
72139
|
+
submitAndPoll,
|
|
72079
72140
|
generate,
|
|
72080
72141
|
listModels,
|
|
72081
72142
|
deriveCategory
|
|
72082
72143
|
};
|
|
72083
|
-
//# sourceMappingURL=chunk-
|
|
72144
|
+
//# sourceMappingURL=chunk-DZVZ5HSO.js.map
|