{"record":{"id":"8bdc1147f4b5e088","repo":"yikart/AiToEarn","slug":"dashscope-task-id-is-missing","errorCode":null,"errorMessage":"DashScope task id is missing","messagePattern":"DashScope task id is missing","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/dashscope/dashscope.service.ts","lineNumber":269,"sourceCode":"    }\n\n    throw new AppException(ResponseCode.InvalidModel)\n  }\n\n  async createFromRequest(request: UserVideoGenerationRequestDto): Promise<{ id: string }> {\n    const modelConfig = this.getModelConfig(request.model)\n    const { providerModel, mode, payload, duration, resolution } = await this.buildPayload(request, modelConfig)\n\n    const startedAt = new Date()\n    const result = await this.aiAvailability.executeAsync(\n      { provider: 'dashscope', operation: 'videoGeneration', model: providerModel },\n      () => this.dashscopeLibService.createVideoTask(payload),\n      response => response.output?.task_id ?? '',\n    )\n\n    const taskId = result.output?.task_id\n    if (!taskId) {\n      throw new BadRequestException(result.message || result.code || 'DashScope task id is missing')\n    }\n\n    this.logger.log({ request, payload, result }, 'Video generation submitted to provider model')\n\n    const aiLog = await this.aiLogRepo.create({\n      userId: request.userId,\n      userType: request.userType,\n      taskId,\n      model: request.model,\n      channel: AiLogChannel.Dashscope,\n      startedAt,\n      type: AiLogType.Video,\n      request: {\n        model: request.model,\n        providerModel,\n        mode,\n        prompt: request.prompt,\n        images: this.collectImageUrls(request),","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/dashscope/dashscope.service.ts#L251-L287","documentation":"In createFromRequest, after submitting the video task via dashscopeLibService.createVideoTask, the response must contain output.task_id. When it is empty/missing, the service throws BadRequestException carrying the provider's message/code or the fallback 'DashScope task id is missing'. This indicates DashScope accepted or rejected the call without returning a usable async task handle, so the task cannot be tracked.","triggerScenarios":"DashScope createVideoTask returns a response whose output.task_id is undefined/empty — typically a provider-side rejection (invalid API key, invalid model name, quota exhaustion, malformed payload) surfaced as an error body instead of a successful task creation.","commonSituations":"Expired or wrong-region DASHSCOPE_API_KEY; provider model name typo or deprecated model; account out of quota; payload parameter rejected by the provider version; transient DashScope 5xx rendered as an error response without task_id.","solutions":["Read the thrown message/code (from result.message || result.code) to get the actual provider rejection reason.","Verify the DashScope API key is valid, active, and matches the intended region/endpooint.","Confirm the providerModel in the payload is a currently supported DashScope video model.","Retry the submission if the provider reported a transient error; fix payload parameters if it reported invalid input."],"exampleFix":"// before (silent fallback hides provider reason)\nif (!taskId) throw new BadRequestException('DashScope task id is missing')\n// after (log full provider response for diagnosis)\nif (!taskId) {\n  this.logger.error({ result }, 'DashScope did not return task_id')\n  throw new BadRequestException(result.message || result.code || 'DashScope task id is missing')\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasTaskId(r: unknown): r is { output: { task_id: string } } {\n  return typeof r === 'object' && r !== null\n    && 'output' in r\n    && typeof (r as any).output?.task_id === 'string'\n    && (r as any).output.task_id.length > 0\n}","tryCatchPattern":"try {\n  const { id } = await createFromRequest(request)\n  return id\n} catch (e) {\n  if (e instanceof BadRequestException) {\n    // provider rejected task creation: surface e.message (provider code/message),\n    // check API key/quota/model name before retrying\n  }\n  throw e\n}","preventionTips":["Log the full provider response when task_id is absent.","Monitor DashScope quota and API key validity.","Pin and periodically re-verify supported provider model names."],"tags":["dashscope","api-response","missing-task-id","provider-error"],"backgroundTag":"missing-task-id","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}