๐—ช๐—ต๐˜† ๐—œ ๐—ฆ๐˜๐—ผ๐—ฝ๐—ฝ๐—ฒ๐—ฑ ๐—›๐—ฎ๐—ฟ๐—ฑ๐—ฐ๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—”๐—œ ๐—”๐—ฃ๐—œ ๐—–๐—ฎ๐—น๐—น๐˜€

It was 11 PM. I built a tool for developers. OpenAI worked. Then a client asked for Claude.

My code had one function. It called OpenAI directly. To add Claude, I had to copy and paste. This created bad code.

I used if-else blocks first. It worked for two providers. The third provider broke everything. The code became a mess.

I built a simple interface. Now the app asks for a prompt. It does not care which AI answers.

Here is the logic:

This approach has limits:

Start simple. Write one provider. Refactor when you need a second one.

How do you handle multiple AI providers? Do you use tools or build your own?

Source: https://dev.to/__c1b9e06dc90a7e0a676b/why-i-stopped-hardcoding-ai-api-calls-and-built-a-simple-abstraction-layer-27me