Provider Abstraction, Routing & Fallbacks
A provider abstraction isolates product logic from vendor SDK details while still allowing capability-specific behavior.
type Capability = 'text' | 'vision' | 'tools' | 'structured' | 'realtime';
interface ModelAdapter {
supports(capability: Capability): boolean;
generate(input: unknown): Promise<{ output: unknown; usage?: unknown }>;
}
Do not abstract away semantics
Providers differ in tool behavior, schema support, reasoning controls, retention, modality limits and streaming events. The abstraction should normalize your domain contract, not pretend all capabilities are identical.
Fallbacks must pass the same eval suite and security policy. A fallback that returns an answer but breaks citations or tool schemas is not resilience.
Practice
- What belongs in a provider adapter?
- What differences should remain explicit?
- Why must fallback models be pre-evaluated?
- Design a route for cheap extraction vs expensive reasoning tasks.