Back to feed
Dev.to
Dev.to
5/23/2026
Stop scattering LLM SDK/API calls across your codebase. Here is the 2-file rule that fixed mine

Stop scattering LLM SDK/API calls across your codebase. Here is the 2-file rule that fixed mine

Short summary

Scattering LLM SDK calls across a codebase causes maintenance pain during version upgrades and duplicates prompt logic. The solution: apply hexagonal architecture by limiting SDK imports to exactly two files—an adapter and provider registry—while business logic calls a provider-agnostic interface. This pattern enables multi-provider routing, cost gating, and isolated migrations; the author proved it by migrating through major SDK breaking changes with only 2 files modified instead of 15+.

  • SDK version upgrades break 15+ files because code scatters imports and provider-specific types throughout the codebase
  • Hexagonal architecture fix: two files only hold SDK imports (adapter + registry), everything else uses typed interfaces with no SDK knowledge
  • Proven result: major breaking changes required 2-file edits instead of 15+; author released open-source llm-ports library implementing this pattern

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Explore more