wiki / concepts / model-provider-abstraction

Model Provider Abstraction

medium confidence updated 2026-08-30 llm-fundamentals · architecture · patterns

Model Provider Abstraction

A classic production problem: you build directly against one provider’s SDK (say OpenAI’s), and one day you need to switch models — every call site is now vendor-shaped. The cost is not the model, it’s the integration surface: message formats, streaming, tool-call shapes, and error handling all differ per vendor.

The Pattern

Define a narrow interface — e.g. a LanguageModel type (the AI SDK, by vercel, is the reference implementation) that any ask(prompt, model) function accepts — and route all generation through it:

  • Swapping models becomes a one-line change; the same prompt path runs against Anthropic, OpenAI, or a local model.
  • createOpenAICompatible-style adapters extend this to any OpenAI-compatible endpoint, including locally-hosted models.
  • Generation, streaming, embeddings, and image/file input all sit behind the same abstraction.

This is dependency inversion principle applied to LLM infrastructure: the application depends on an abstraction it owns, not on a vendor SDK. It also de-risks context rot economics — provider-agnostic apps can chase the cheapest adequate model without a rewrite.

Caveat

Abstractions leak: provider-specific features (caching behavior, reasoning-token billing, tool-call quirks) do not always map cleanly. The interface should expose the common denominator and allow escape hatches.

llm message protocol, structured outputs, dependency inversion principle, clean architecture, agent native infrastructure.

Evidence — verified primary sources
raw/aihero-video/8SB4g02p1OORs01RhtXt4YCadPPjcfgNr8KsbejDkVxFI.md internal workspace doc
raw/aihero-video/pEqcLrdb41402x028ndrEq2h24A51RkYC01yzqpfG4QJKo.md internal workspace doc
raw/aihero-video/cA6c02ZOSu7MxDK8I9z02J008OS3fwc01LkxNEiZW61DMhg.md internal workspace doc
raw/aihero-video/M02v00KLiYejPc55vWKBI6GETh6NM7Frcewj2i00q1oTyo.md internal workspace doc