yikart/AiToEarn · error · BadRequestException

DashScope task id is missing

Error message

DashScope task id is missing

What it means

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.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/dashscope/dashscope.service.ts:269

    }

    throw new AppException(ResponseCode.InvalidModel)
  }

  async createFromRequest(request: UserVideoGenerationRequestDto): Promise<{ id: string }> {
    const modelConfig = this.getModelConfig(request.model)
    const { providerModel, mode, payload, duration, resolution } = await this.buildPayload(request, modelConfig)

    const startedAt = new Date()
    const result = await this.aiAvailability.executeAsync(
      { provider: 'dashscope', operation: 'videoGeneration', model: providerModel },
      () => this.dashscopeLibService.createVideoTask(payload),
      response => response.output?.task_id ?? '',
    )

    const taskId = result.output?.task_id
    if (!taskId) {
      throw new BadRequestException(result.message || result.code || 'DashScope task id is missing')
    }

    this.logger.log({ request, payload, result }, 'Video generation submitted to provider model')

    const aiLog = await this.aiLogRepo.create({
      userId: request.userId,
      userType: request.userType,
      taskId,
      model: request.model,
      channel: AiLogChannel.Dashscope,
      startedAt,
      type: AiLogType.Video,
      request: {
        model: request.model,
        providerModel,
        mode,
        prompt: request.prompt,
        images: this.collectImageUrls(request),

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Read the thrown message/code (from result.message || result.code) to get the actual provider rejection reason.
  2. Verify the DashScope API key is valid, active, and matches the intended region/endpooint.
  3. Confirm the providerModel in the payload is a currently supported DashScope video model.
  4. Retry the submission if the provider reported a transient error; fix payload parameters if it reported invalid input.

Example fix

// before (silent fallback hides provider reason)
if (!taskId) throw new BadRequestException('DashScope task id is missing')
// after (log full provider response for diagnosis)
if (!taskId) {
  this.logger.error({ result }, 'DashScope did not return task_id')
  throw new BadRequestException(result.message || result.code || 'DashScope task id is missing')
}
Defensive patterns

Strategy: try-catch

Type guard

function hasTaskId(r: unknown): r is { output: { task_id: string } } {
  return typeof r === 'object' && r !== null
    && 'output' in r
    && typeof (r as any).output?.task_id === 'string'
    && (r as any).output.task_id.length > 0
}

Try / catch

try {
  const { id } = await createFromRequest(request)
  return id
} catch (e) {
  if (e instanceof BadRequestException) {
    // provider rejected task creation: surface e.message (provider code/message),
    // check API key/quota/model name before retrying
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/8bdc1147f4b5e088. Report an issue: GitHub.