#12381·ai

Make async APIs a first-class API in AI SDK

Author: gr2mCreated Feb 9, 2026Updated Sep 30, 2026
Labelsai/coretype:epictask-identify-issue-type-done

In some cases, provider APIs do not respond with the result to a user's prompt, but with a task ID or a callback URL which has to be polled until the result is ready and the method like generateVideo() can be resolved with the result. As an alternative to polling, most if not all provider APIs support a webhook URL to be passed. We have to support both ways and default to the long polling behavior we currently implement across some of our provider models. Support for Webhook URLs can depend on models within the same provider. Instead of passing a webhookUrl at call time, a user should also be able to pass an async callback function which resolves with a webhook URL, letting the provider decide whether to generate it or not depending on model configuration.

Users will be interested into the long poll mechanism, like using their own fetch method, tracking the number of poll requests, configure the poll interval (e.g. make it exponential/dynamic).

Let's discuss what API we want to implement. We are open to input!

Current architecture for context

Current Architecture (for context)

User calls:     generateVideo({ model, prompt })
                        ↓
Core function:  model.doGenerate(options)     ← returns Promise<Result>
                        ↓
Provider impl:  postJsonToApi(...)            ← submit job
                while (!done) {               ← internal polling loop
                  await delay(interval)
                  status = await getFromApi()
                }
                return result                 ← resolves only when complete

The provider owns the entire lifecycle. The SDK core has zero visibility or control.

Summary of current polling implementations across providers

11 files use the submit-then-poll pattern, where postJsonToApi() (or similar) does not directly return the response, but instead returns a URL or task ID that needs to be polled until the actual response is ready. They fall into three categories.

Image Generation (2)

@ai-sdk/black-forest-labs
  • File: packages/black-forest-labs/src/black-forest-labs-image-model.ts
  • Submit: postJsonToApi → polling_url + id
  • Poll: pollForImageUrl() — for loop with max attempts, getFromApi to polling URL
  • Lines: 261–333
@ai-sdk/luma
  • File: packages/luma/src/luma-image-model.ts
  • Submit: postJsonToApi → generation id
  • Poll: pollForImageUrl() — for loop with max attempts, getFromApi to /generations/{id}
  • Lines: 153–198

Video Generation (5)

@ai-sdk/replicate
  • File: packages/replicate/src/replicate-video-model.ts
  • Submit: postJsonToApi → prediction id + urls.get
  • Poll: while loop in doGenerate, getFromApi to urls.get
  • Lines: 193–254
@ai-sdk/fal (video)
  • File: packages/fal/src/fal-video-model.ts
  • Submit: postJsonToApi → response_url
  • Poll: while (true) in doGenerate, getFromApi to response URL
  • Lines: 156–249
@ai-sdk/klingai
  • File: packages/klingai/src/klingai-video-model.ts
  • Submit: postJsonToApi → task_id
  • Poll: while (true) in doGenerate, getFromApi to task status endpoint
  • Lines: 276–348
@ai-sdk/google (video)
  • File: packages/google/src/google-generative-ai-video-model.ts
  • Submit: postJsonToApi → operation name
  • Poll: while (!done) in doGenerate, getFromApi to operation URL
  • Lines: 185–251
@ai-sdk/google-vertex (video)
  • File: packages/google-vertex/src/google-vertex-video-model.ts
  • Submit: postJsonToApi → operation name
  • Poll: while (!done) in doGenerate, postJsonToApi to fetchPredictOperation
  • Lines: 181–251

Transcription (4)

@ai-sdk/assemblyai
  • File: packages/assemblyai/src/assemblyai-transcription-model.ts
  • Submit: postJsonToApi → transcript id
  • Poll: waitForCompletion() — while (true), direct fetch to /v2/transcript/{id}
  • Lines: 268–329
@ai-sdk/revai
  • File: packages/revai/src/revai-transcription-model.ts
  • Submit: postFormDataToApi → job id
  • Poll: while (status !== 'transcribed') in doGenerate, getFromApi to /jobs/{id}
  • Lines: 322–390
@ai-sdk/gladia
  • File: packages/gladia/src/gladia-transcription-model.ts
  • Submit: postJsonToApi → result_url
  • Poll: while (true) in doGenerate, getFromApi to result URL
  • Lines: 525–589
@ai-sdk/fal (transcription)
  • File: packages/fal/src/fal-transcription-model.ts
  • Submit: postJsonToApi → request_id
  • Poll: while (true) in doGenerate, getFromApi to request status URL
  • Lines: 136–232

Common Shape

All follow roughly the same pattern:

  1. Submit via postJsonToApi (or postFormDataToApi) → get back a task ID or polling URL
  2. Poll in a loop (while/for) calling getFromApi (or fetch) with a delay() between iterations
  3. Check status — looking for terminal states like Ready, completed, succeed, done
  4. Return the final result (image URL, video URL, transcript)
  5. Timeout protection via max attempts or elapsed time

Default Poll Intervals and Timeouts

Package Poll Interval Timeout
black-forest-labs 500ms 60s
luma 500ms 120 attempts (~60s)
replicate 2000ms 5 min
fal (video) 2000ms 5 min
klingai 5000ms 10 min
google / google-vertex 10000ms 10 min
assemblyai 3000ms none (polls indefinitely)
revai 1000ms 60s
gladia 1000ms 60s
fal (transcription) 1000ms 60s

Related