CherryHQ/cherry-studio · error · NoSuchModelError

imageModel

Error message

imageModel

What it means

NoSuchModelError is the AI SDK's standard error for 'this provider does not serve this model type'. createMoonshotProvider explicitly throws it from provider.imageModel() because Moonshot only exposes chat and embedding models — there is no image generation backend. The error carries modelId and modelType='imageModel' for the SDK's error-handling pipeline.

Source

Thrown at src/main/ai/provider/custom/moonshotProvider.ts:156

      includeUsage: settings.includeUsage
    })

  const createEmbeddingModel = (modelId: string) =>
    new OpenAICompatibleEmbeddingModel(modelId, {
      provider: `${MOONSHOT_PROVIDER_NAME}.embedding`,
      url,
      headers,
      fetch: customFetch
    })

  const provider = (modelId: string) => createChatModel(modelId)
  provider.specificationVersion = 'v3' as const
  provider.languageModel = createChatModel
  provider.chatModel = createChatModel
  provider.embeddingModel = createEmbeddingModel
  provider.textEmbeddingModel = createEmbeddingModel
  provider.imageModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'imageModel' })
  }

  return provider as MoonshotProvider
}

View on GitHub (pinned to 726446b54c)

Solutions

  1. Do not route image-generation requests to the Moonshot provider — it has no image backend. Use a provider that exposes createImageGenerationModel/createImageModel.
  2. Audit the model registry: ensure models under the moonshot provider are typed as chat/embedding, not image.
  3. If writing generic dispatcher code, guard with a capability check (hasImageTransport / provider capability flags) before calling provider.imageModel().
  4. Catch NoSuchModelError at the call site and surface a user-facing 'model type not supported by this provider' message.

Example fix

// before
const img = provider.imageModel(modelId) // throws on moonshot
// after — capability gate before resolution
if (!providerCapabilities(providerId).image) {
  throw new Error(`Provider '${providerId}' does not support image generation`)
}
const img = provider.imageModel(modelId)
Defensive patterns

Strategy: type-guard

Validate before calling

// Capability check before resolving an image model
if (!providerCapabilities(providerId).image) {
  throw new Error(`Provider '${providerId}' does not support image generation`)
}

Type guard

import { NoSuchModelError } from '@ai-sdk/provider'
export function isNoSuchImageModelError(e: unknown): boolean {
  return e instanceof NoSuchModelError && (e as any).modelType === 'imageModel'
}

Try / catch

try {
  provider.imageModel(modelId)
} catch (e) {
  if (e instanceof NoSuchModelError) {
    // route to a different provider or surface to user
  }
  throw e
}

Prevention

When it happens

Trigger: Anything calls provider.imageModel(someId) on a Moonshot provider instance — typically the unified provider facade when the dispatcher routes an image-generation request to the moonshot provider by mistake, or a model record is mis-typed as an image model in configuration.

Common situations: A model registered under the moonshot provider with the wrong capability/type (marked image-capable), or generic code that probes provider.imageModel for every provider without a capability check.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/3f3c76a48714a357. Report an issue: GitHub.