{"record":{"id":"a77f7d2d74aec8c8","repo":"vercel/ai","slug":"klingai-video-generation-error","errorCode":"KLINGAI_VIDEO_GENERATION_ERROR","errorMessage":"No task_id returned from KlingAI API. Response: ${JSON.stringify(createResponse)}","messagePattern":"No task_id returned from KlingAI API\\. Response: (.+?)","errorType":"error_code","errorClass":"AISDKError","httpStatus":null,"severity":"error","filePath":"packages/klingai/src/klingai-video-model.ts","lineNumber":284,"sourceCode":"\n    const { value: createResponse, responseHeaders } = await postJsonToApi({\n      url: `${this.config.baseURL}${endpointPath}`,\n      headers: combineHeaders(\n        await resolve(this.config.headers),\n        options.headers,\n      ),\n      body,\n      successfulResponseHandler: createJsonResponseHandler(\n        klingaiCreateTaskSchema,\n      ),\n      failedResponseHandler: klingaiFailedResponseHandler,\n      abortSignal: options.abortSignal,\n      fetch: this.config.fetch,\n    });\n\n    const taskId = createResponse.data?.task_id;\n    if (!taskId) {\n      throw new AISDKError({\n        name: 'KLINGAI_VIDEO_GENERATION_ERROR',\n        message: `No task_id returned from KlingAI API. Response: ${JSON.stringify(createResponse)}`,\n      });\n    }\n\n    return {\n      operation: { taskId, endpointPath },\n      warnings,\n      response: {\n        timestamp: currentDate,\n        modelId: this.modelId,\n        headers: responseHeaders,\n      },\n    };\n  }\n\n  async doStatus(\n    options: Parameters<NonNullable<VideoModelV4['doStatus']>>[0],","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/klingai/src/klingai-video-model.ts#L266-L302","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst model = klingai.video('kling-v2');\nawait model.doGenerate({ prompt: 'cat', /* possibly wrong providerOptions or stale package */ });\n// after\npnpm update @ai-sdk/klingai; // and confirm valid API key + quota\nawait model.doGenerate({ prompt: 'cat', providerOptions: { klingai: { /* valid options */ } } });","handlingStrategy":"validation","validationCode":"// pre-flight: ensure provider + key configured\nif (!process.env.KLINGAI_API_KEY) throw new Error('Set KLINGAI_API_KEY');\nconst response = await fetch('https://api.klingai.com/v1/videos/text2video', {\n  method: 'POST',\n  headers: { Authorization: `Bearer ${process.env.KLINGAI_API_KEY}` },\n  body: JSON.stringify(payload),\n});\nconst body = await response.json();\nif (!body?.data?.task_id) throw new Error(`Unexpected KlingAI response: ${JSON.stringify(body)}`);","typeGuard":"function hasTaskId(r: unknown): r is { data: { task_id: string } } {\n  return !!r && typeof r === 'object' && 'data' in r &&\n    !!(r as any).data && typeof (r as any).data.task_id === 'string';\n}","tryCatchPattern":"try {\n  await model.doGenerate({ ... });\n} catch (e) {\n  if (AISDKError.isInstance(e) && e.name === 'KLINGAI_VIDEO_GENERATION_ERROR') {\n    console.error('KlingAI create failed:', e.message); // inspect raw response, retry or alert\n  } else throw e;\n}","preventionTips":["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"],"tags":["video","api-response","missing-field"],"backgroundTag":"missing-field-in-api-response","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}