vercel/ai · error · NoSuchModelError

Hugging Face Responses API does not support text embeddings.

Error message

Hugging Face Responses API does not support text embeddings. Use the Hugging Face Inference API directly for embeddings.

What it means

The Hugging Face provider's Responses API integration does not implement embedding models; provider.embeddingModel always throws NoSuchModelError. The AI SDK surfaces this when you request an embedding model from this provider. The library directs you to Hugging Face's Inference API (feature-extraction pipeline) for embeddings instead.

Source

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

  const createResponsesModel = (modelId: HuggingFaceResponsesModelId) => {
    return new HuggingFaceResponsesLanguageModel(modelId, {
      provider: 'huggingface.responses',
      url: ({ path }) => `${baseURL}${path}`,
      headers: getHeaders,
      fetch: options.fetch,
      generateId: options.generateId ?? generateId,
    });
  };

  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;

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Use Hugging Face's Inference API directly (e.g. its feature-extraction endpoint or a custom provider wrapper) for embeddings instead of this provider's embeddingModel.
  2. Switch embeddings to a provider with embedding support, e.g. openai.embeddingModel('text-embedding-3-small') or another @ai-sdk provider.
  3. If you only need text generation, use huggingface(modelId) / huggingface.responses(modelId) and keep embeddings on a different provider instance.

Example fix

// before
const model = huggingface.embeddingModel('sentence-transformers/all-MiniLM-L6-v2');
// after
const model = openai.embeddingModel('text-embedding-3-small'); // or use HF Inference API directly
Defensive patterns

Strategy: fallback

Validate before calling

if (typeof (huggingface as any).embeddingModel === 'function') {
  try { huggingface.embeddingModel('probe'); } catch { /* falls through to NoSuchModelError */ }
}

Type guard

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

Try / catch

let embeddingModel;
try {
  embeddingModel = huggingface.embeddingModel(id);
} catch (e) {
  if (NoSuchModelError.isInstance(e)) {
    embeddingModel = openai.embeddingModel('text-embedding-3-small'); // fallback provider
  } else throw e;
}

Prevention

When it happens

Trigger: Calling huggingface.embeddingModel('some-model-id') or passing the Hugging Face provider where an EmbeddingModel is required, e.g. embed({ model: huggingface.embeddingModel(...) }) or embedMany.

Common situations: Assuming the Hugging Face provider covers all model types like other providers (OpenAI, etc.); copying embed() examples and swapping in the Hugging Face provider; using a Responses-API-only provider instance configured via createHuggingface responses mode.

Related errors


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