vercel/ai · error · AISDKError
KLINGAI_VIDEO_GENERATION_ERROR
KLINGAI_VIDEO_GENERATION_ERROR
Error message
No task_id returned from KlingAI API. Response: ${JSON.stringify(createResponse)} What it means
KlingAI's video creation endpoint accepted the request but returned a payload without a data.task_id. The KlingAI video model needs that task_id to poll for generation status, so doStart throws this AISDKError immediately instead of returning a handle that could never resolve. It indicates an unexpected or malformed API response rather than a user input problem.
Source
Thrown at packages/klingai/src/klingai-video-model.ts:284
const { value: createResponse, responseHeaders } = await postJsonToApi({
url: `${this.config.baseURL}${endpointPath}`,
headers: combineHeaders(
await resolve(this.config.headers),
options.headers,
),
body,
successfulResponseHandler: createJsonResponseHandler(
klingaiCreateTaskSchema,
),
failedResponseHandler: klingaiFailedResponseHandler,
abortSignal: options.abortSignal,
fetch: this.config.fetch,
});
const taskId = createResponse.data?.task_id;
if (!taskId) {
throw new AISDKError({
name: 'KLINGAI_VIDEO_GENERATION_ERROR',
message: `No task_id returned from KlingAI API. Response: ${JSON.stringify(createResponse)}`,
});
}
return {
operation: { taskId, endpointPath },
warnings,
response: {
timestamp: currentDate,
modelId: this.modelId,
headers: responseHeaders,
},
};
}
async doStatus(
options: Parameters<NonNullable<VideoModelV4['doStatus']>>[0],View on GitHub (pinned to 69428b1f8b)
Solutions
- Log the JSON.stringify(createResponse) content included in the message to see the actual API payload
- Verify the KlingAI API key and account are active and have video-generation quota
- Check that the KlingAI package version matches the current KlingAI API version; upgrade the package
- If behind a proxy or mock (custom fetch), ensure it passes the response body through unmodified
- Retry the request in case of a transient API-side anomaly
Example fix
// before
const model = klingai.video('kling-v2');
await model.doGenerate({ prompt: 'cat', /* possibly wrong providerOptions or stale package */ });
// after
pnpm update @ai-sdk/klingai; // and confirm valid API key + quota
await model.doGenerate({ prompt: 'cat', providerOptions: { klingai: { /* valid options */ } } }); Defensive patterns
Strategy: validation
Validate before calling
// pre-flight: ensure provider + key configured
if (!process.env.KLINGAI_API_KEY) throw new Error('Set KLINGAI_API_KEY');
const response = await fetch('https://api.klingai.com/v1/videos/text2video', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.KLINGAI_API_KEY}` },
body: JSON.stringify(payload),
});
const body = await response.json();
if (!body?.data?.task_id) throw new Error(`Unexpected KlingAI response: ${JSON.stringify(body)}`); Type guard
function hasTaskId(r: unknown): r is { data: { task_id: string } } {
return !!r && typeof r === 'object' && 'data' in r &&
!!(r as any).data && typeof (r as any).data.task_id === 'string';
} Try / catch
try {
await model.doGenerate({ ... });
} catch (e) {
if (AISDKError.isInstance(e) && e.name === 'KLINGAI_VIDEO_GENERATION_ERROR') {
console.error('KlingAI create failed:', e.message); // inspect raw response, retry or alert
} else throw e;
} Prevention
- Keep @ai-sdk/klingai updated to match the current KlingAI API version
- Validate API key and quota before long video jobs
- Log full provider responses in development
- Avoid proxy/middleware that mutates response bodies
When it happens
Trigger: Calling doGenerate/doStart on the KlingAI video model when the create-video HTTP call returns 2xx but the body lacks data.task_id — e.g. API response schema changed, an error payload disguised with 200 status, or an intermediary proxy altering the response.
Common situations: KlingAI API version drift, expired/limited account returning an error-shaped 200 response, corporate proxy or mock server stripping fields, or network middleware rewriting JSON.
Related errors
- ALIBABA_VIDEO_GENERATION_ERROR
- Video model ${model.modelId} does not implement doGenerate o
- No video generated.
- Video generation timed out after ${timeoutMs}ms.
- statusResult.error
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/a77f7d2d74aec8c8.
Report an issue: GitHub.