yikart/AiToEarn · error · AppException
InvalidModel
InvalidModel
Error message
ResponseCode.InvalidModel
What it means
InvalidModel is thrown by RelayVideoService.createFromRequest when request.model does not match any configured video generation model, or when the supplied mode is not in the model's allowed modes list. The Relay channel only accepts models/modes explicitly declared in modelsConfigService.config.video.generation.
Source
Thrown at project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/relay/relay-video.service.ts:34
constructor(
private readonly relayLibService: RelayLibService,
private readonly aiLogRepo: AiLogRepository,
private readonly modelsConfigService: ModelsConfigService,
private readonly aiAvailability: AiAvailabilityService,
@Optional() private readonly relayMediaResolver?: RelayMediaResolverService,
) {}
private async resolveRelayJson<T>(value: T): Promise<T> {
if (!this.relayMediaResolver) {
return value
}
return await this.relayMediaResolver.resolveJson(value)
}
async createFromRequest(request: UserVideoGenerationRequestDto): Promise<{ id: string }> {
const modelConfig = this.modelsConfigService.config.video.generation.find(m => m.name === request.model)
if (!modelConfig) {
throw new AppException(ResponseCode.InvalidModel)
}
if (request.mode && !(modelConfig.modes as readonly string[]).includes(request.mode)) {
throw new AppException(ResponseCode.InvalidModel)
}
const startedAt = new Date()
const payload = { ...request } as RelayVideoGenerationRequest & { userId?: string, userType?: UserType, groupId?: string }
delete payload.userId
delete payload.userType
delete payload.groupId
const relayPayload = await this.resolveRelayJson(payload)
const result = await this.aiAvailability.executeAsync<RelayVideoSubmitResponse>(
{ provider: 'relay', operation: 'videoGeneration', model: request.model },
() => this.relayLibService.createVideo(relayPayload),
response => response.id || '',
)View on GitHub (pinned to d3aa8bea5b)
Solutions
- Use a model name exactly matching an entry in the video.generation models config (check models config file/env for available names)
- If the model should be supported, add it to modelsConfigService.config.video.generation and redeploy
- Fetch the current model list from the API and populate client pickers from it instead of hardcoding
- Confirm you are targeting the right channel: Relay-supported models differ from OpenAI/Dashscope ones
Example fix
// before
await relayVideoService.createFromRequest({ model: 'sora-2-pro', ... }) // not in relay config
// after
const models = modelsConfigService.config.video.generation.map(m => m.name)
await relayVideoService.createFromRequest({ model: models.includes('sora-2-pro') ? 'sora-2-pro' : models[0], ... }) Defensive patterns
Strategy: validation
Validate before calling
const names = modelsConfigService.config.video.generation.map(m => m.name)
if (!names.includes(request.model)) {
throw new Error(`Unknown relay video model: ${request.model}; available: ${names.join(', ')}`)
} Type guard
function isKnownRelayVideoModel(name: string, cfg: ModelsConfig): name is string {
return cfg.video.generation.some(m => m.name === name)
} Try / catch
try {
await relayVideoService.createFromRequest(req)
} catch (e) {
if (e instanceof AppException && e.code === ResponseCode.InvalidModel) {
// refresh model list from config/API and prompt user to pick a valid model
} else throw e
} Prevention
- Populate client model pickers from the server's model list, never hardcode
- Re-sync model names after backend config updates
- Match exact casing/spacing of model names
- Verify the model is offered on the Relay channel, not just OpenAI/Dashscope
When it happens
Trigger: line 34: request.model is not found in modelsConfigService.config.video.generation (no entry whose name equals request.model).
Common situations: Typo in model name; model removed or renamed in the models config after a deployment; client using a model that only exists on OpenAI/Dashscope, not the Relay channel; stale cached model list on the client; config file/env not updated to add a newly available Relay model.
Related errors
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/797740b3fa24a738.
Report an issue: GitHub.