{"record":{"id":"0d91611515b471a7","repo":"vercel/ai","slug":"the-anthropic-aws-model-function-cannot-be-called","errorCode":null,"errorMessage":"The Anthropic AWS model function cannot be called with the new keyword.","messagePattern":"The Anthropic AWS model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/anthropic-aws/src/anthropic-aws-provider.ts","lineNumber":245,"sourceCode":"    ...options.headers,\n  });\n\n  const createChatModel = (modelId: AnthropicModelId) =>\n    new AnthropicLanguageModel(modelId, {\n      provider: 'anthropic-aws.messages',\n      baseURL: getBaseURL(),\n      headers: getHeaders,\n      fetch: fetchFunction,\n      generateId: options.generateId,\n      supportedUrls: () => ({\n        'image/*': [/^https?:\\/\\/.*$/],\n        'application/pdf': [/^https?:\\/\\/.*$/],\n      }),\n    });\n\n  const provider = function (modelId: AnthropicModelId) {\n    if (new.target) {\n      throw new Error(\n        'The Anthropic AWS model function cannot be called with the new keyword.',\n      );\n    }\n    return createChatModel(modelId);\n  };\n\n  provider.specificationVersion = 'v4' as const;\n  provider.languageModel = createChatModel;\n  provider.chat = createChatModel;\n  provider.messages = createChatModel;\n\n  provider.embeddingModel = (modelId: string) => {\n    throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n  };\n  provider.textEmbeddingModel = provider.embeddingModel;\n  provider.imageModel = (modelId: string) => {\n    throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n  };","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/anthropic-aws/src/anthropic-aws-provider.ts#L227-L263","documentation":"The Anthropic AWS provider returned by `createAnthropicAws()` is a factory function, not a constructor. Calling it with `new` is detected via `new.target` and rejected with this error so users get a clear message instead of a silently broken model object.","triggerScenarios":"Writing `new anthropicAws('claude-...')` or `new anthropic('model-id', {...})` with the AWS provider, typically copying old constructor-style provider code.","commonSituations":"Migrating from older SDKs where providers were classes; IDE auto-completing with `new`; LLM-generated boilerplate using `new` on provider factories.","solutions":["Call the provider as a plain function: `anthropicAws('claude-sonnet-4-...')`.","Remove `new` wherever the provider is invoked, including inside helpers that construct models.","Consult current @ai-sdk/anthropic-aws docs for the factory-call pattern."],"exampleFix":"// before\nconst model = new anthropicAws('claude-sonnet-4-20250514');\n// after\nconst model = anthropicAws('claude-sonnet-4-20250514');","handlingStrategy":"validation","validationCode":"if (typeof anthropicAws !== 'function') throw new Error('anthropicAws must be called as a function, not constructed');\nconst model = anthropicAws('claude-sonnet-4-20250514');","typeGuard":"function isProviderFactory(v: unknown): v is (modelId: string, settings?: unknown) => unknown {\n  return typeof v === 'function' && !/^class\\s/.test(String(v));\n}","tryCatchPattern":"try {\n  const model = anthropicAws('claude-sonnet-4-20250514');\n} catch (e) {\n  if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {\n    // drop the `new` keyword at the call site\n  }\n  throw e;\n}","preventionTips":["Never instantiate AI SDK providers with `new`.","Add a lint/grep rule against `new anthropicAws`.","Follow current provider docs instead of class-based examples."],"tags":["api-misuse","typescript","provider","aws"],"backgroundTag":"illegal-new-invocation","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}