vercel/ai · error · NoSuchModelError

Hugging Face Responses API does not support image generation

Error message

Hugging Face Responses API does not support image generation. Use the Hugging Face Inference API directly for image models.

What it means

The Hugging Face Responses API provider does not implement image generation; provider.imageModel always throws NoSuchModelError. Requesting an image model from this provider is intentionally unsupported because the Responses API cannot generate images. The message points to Hugging Face's Inference API for image models.

Source

Thrown at packages/huggingface/src/huggingface-provider.ts:105

  const provider = (modelId: HuggingFaceResponsesModelId) =>
    createResponsesModel(modelId);

  provider.specificationVersion = 'v4' as const;
  provider.languageModel = createResponsesModel;
  provider.responses = createResponsesModel;

  provider.embeddingModel = (modelId: string) => {
    throw new NoSuchModelError({
      modelId,
      modelType: 'embeddingModel',
      message:
        'Hugging Face Responses API does not support text embeddings. Use the Hugging Face Inference API directly for embeddings.',
    });
  };
  provider.textEmbeddingModel = provider.embeddingModel;

  provider.imageModel = (modelId: string) => {
    throw new NoSuchModelError({
      modelId,
      modelType: 'imageModel',
      message:
        'Hugging Face Responses API does not support image generation. Use the Hugging Face Inference API directly for image models.',
    });
  };

  return provider;
}

/**
 * Default Hugging Face provider instance.
 */
export const huggingFace = createHuggingFace();

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Use Hugging Face's Inference API directly for text-to-image models (e.g. via fetch or a dedicated provider package).
  2. Use an AI SDK provider with image generation support, e.g. openai.image('gpt-image-1') or another @ai-sdk image-capable provider.
  3. If you only need language models, keep using huggingface(modelId) and avoid the imageModel factory.

Example fix

// before
const { image } = await generateImage({ model: huggingface.imageModel('black-forest-labs/FLUX.1-schnell'), prompt });
// after
const { image } = await generateImage({ model: openai.image('gpt-image-1'), prompt });
Defensive patterns

Strategy: fallback

Validate before calling

const IMAGE_CAPABLE = new Set(['openai', 'google', 'amazon-bedrock']);
if (!IMAGE_CAPABLE.has(providerName)) {
  throw new Error(`Provider ${providerName} does not support imageModel; configure an image-capable provider.`);
}

Type guard

import { NoSuchModelError } from '@ai-sdk/provider';
function isNoSuchModel(e: unknown): e is NoSuchModelError {
  return NoSuchModelError.isInstance(e);
}

Try / catch

let imageModel;
try {
  imageModel = huggingface.imageModel(id);
} catch (e) {
  if (NoSuchModelError.isInstance(e)) {
    imageModel = openai.image('gpt-image-1');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling huggingface.imageModel('some-model-id') or passing the Hugging Face provider where a ImageModelV4 is required, e.g. generateImage({ model: huggingface.imageModel(...) }).

Common situations: Migrating generateImage code from a provider with image support to Hugging Face; assuming provider parity across the AI SDK's model factory methods; using provider.textEmbeddingModel/imageModel generically in abstraction layers.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/86a3f2badaf0c483. Report an issue: GitHub.