yikart/AiToEarn · error · AppException

InvalidModel

InvalidModel

Error message

ResponseCode.InvalidModel

What it means

getVideoDraftModelConfig in DraftGenerationService looks up the requested video generation model name in config.ai.models.video.generation and throws InvalidModel when no entry matches. This validates the video-draft generation model before resolving reference mode or dispatching the generation task.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-ai/src/core/draft-generation/draft-generation.service.ts:233

      return task
    }

    const queue = await this.queueService.getDraftGenerationQueueInfo(task.id)
    if (!queue) {
      return task
    }

    return { ...task, queue }
  }

  private async attachQueueInfoToTasks<T extends { id: string, status: AiLogStatus }>(tasks: T[]): Promise<Array<DraftGenerationTaskWithQueue<T>>> {
    return await Promise.all(tasks.map(task => this.attachQueueInfo(task)))
  }

  private getVideoDraftModelConfig(model: string) {
    const modelConfig = config.ai.models.video.generation.find(m => m.name === model)
    if (!modelConfig) {
      throw new AppException(ResponseCode.InvalidModel)
    }

    return modelConfig
  }

  private resolveVideoReferenceMode(
    modelConfig: ReturnType<DraftGenerationService['getVideoDraftModelConfig']>,
    videoUrls?: string[],
    audioUrls?: string[],
  ): 'multi-ref' | 'video2video' | undefined {
    const hasVideoReference = (videoUrls?.length ?? 0) > 0
    const hasAudioReference = (audioUrls?.length ?? 0) > 0
    if (!hasVideoReference && !hasAudioReference) {
      return undefined
    }

    if (modelConfig.modes.includes('multi-ref')) {
      return 'multi-ref'

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Use a model name exactly matching an entry in config.ai.models.video.generation
  2. Update config to include the requested model, or remove it from the client's offered list
  3. Serve the valid model list to clients from config so they cannot submit unknown names
  4. Check environment: the model may exist in another env's config but not this one

Example fix

// before
generateVideoDraft({ model: 'kling-v1-5', ... })
// after (config has 'kling-v2')
generateVideoDraft({ model: 'kling-v2', ... })
Defensive patterns

Strategy: validation

Validate before calling

const validVideoModels = config.ai.models.video.generation.map(m => m.name)
if (!validVideoModels.includes(request.model)) {
  throw new Error(`Unknown video model ${request.model}; valid: ${validVideoModels.join(',')}`)
}

Type guard

function isKnownVideoModel(name: string): boolean {
  return config.ai.models.video.generation.some(m => m.name === name)
}

Try / catch

try {
  const task = await draftGenerationService.createVideoDraft(dto)
} catch (e) {
  if (e instanceof AppException && e.code === ResponseCode.InvalidModel) {
    return { error: 'invalid-model', validModels: config.ai.models.video.generation.map(m => m.name) }
  }
  throw e
}

Prevention

When it happens

Trigger: A video draft generation request supplies a model name that is not present in config.ai.models.video.generation (typo, deprecated model, or client sending a model from another environment's config).

Common situations: Video provider retired a model name and config was updated, but cached clients still send the old name; staging/production configs have different model lists; frontend model picker hardcoded instead of driven by server config.

Related errors


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