vercel/ai · error · NoSuchModelError

embeddingModel

Error message

embeddingModel

What it means

The Anthropic provider only implements language (chat) models. Its `embeddingModel` factory is a stub that unconditionally throws NoSuchModelError with modelType 'embeddingModel' for any modelId passed. Anthropic does not offer an embeddings API through this SDK.

Source

Thrown at packages/anthropic/src/anthropic-provider.ts:195

    });

  const provider = function (modelId: AnthropicModelId) {
    if (new.target) {
      throw new Error(
        'The Anthropic model function cannot be called with the new keyword.',
      );
    }

    return createChatModel(modelId);
  };

  provider.specificationVersion = 'v4' as const;
  provider.languageModel = createChatModel;
  provider.chat = createChatModel;
  provider.messages = createChatModel;

  provider.embeddingModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
  };
  provider.textEmbeddingModel = provider.embeddingModel;
  provider.imageModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
  };

  provider.files = () =>
    new AnthropicFiles({
      provider: providerName,
      baseURL,
      headers: getHeaders,
      fetch: options.fetch,
    });

  provider.skills = createSkills;

  provider.tools = anthropicTools;

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Use a provider that implements embeddings, e.g. `createOpenAI(...).embedding('text-embedding-3-small')`, `@ai-sdk/amazon-bedrock`, or Google.
  2. Move embedding generation to a separate provider instance and keep Anthropic only for language models.

Example fix

// before
import { createAnthropic } from '@ai-sdk/anthropic';
const model = createAnthropic().embeddingModel('claude-embed');
// after
import { createOpenAI } from '@ai-sdk/openai';
const model = createOpenAI().embedding('text-embedding-3-small');
Defensive patterns

Strategy: fallback

Validate before calling

const embeddingProvider = supportsEmbeddings('anthropic')
  ? anthropic
  : createOpenAI();
const model = embeddingProvider.textEmbeddingModel('text-embedding-3-small');

Type guard

function hasEmbeddingModel(
  p: any,
): p is { textEmbeddingModel: (id: string) => unknown } {
  return typeof p?.textEmbeddingModel === 'function' &&
    !p.textEmbeddingModel.toString().includes('NoSuchModelError');
}

Try / catch

try {
  return anthropic.textEmbeddingModel(id);
} catch (error) {
  if (NoSuchModelError.isInstance(error) && error.modelType === 'embeddingModel') {
    return openai.embedding('text-embedding-3-small');
  }
  throw error;
}

Prevention

When it happens

Trigger: Calling `anthropic.embeddingModel('some-id')` or `anthropic.textEmbeddingModel('some-id')`, or passing the anthropic provider to APIs that request an embedding model (e.g. `embed({ model: anthropic.embeddingModel(...) })`).

Common situations: Assuming provider parity with OpenAI and using Anthropic for embeddings; building a generic RAG pipeline that resolves embedding models from the wrong provider; swapping providers in shared config.

Related errors


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