Creates families of related objects through a stable interface while hiding concrete classes. In the Vercel AI SDK, generateText and streamText create language-model instances from different providers. section 3.3.2
The pattern’s implementation has three practical pieces:
- A shared language-model specification defines the contract that provider implementations must satisfy. section 3.3.2
- A configuration object selects a provider-specific model while preserving the same generateText interface. section 3.3.2
- Regular stateless functions can provide the factory behavior; classes are not required. section 3.3.2
Switching providers
Call generateText with openai('gpt-3.5-turbo') or anthropic('claude-v1'), changing the model parameter without changing the text-generation call.


