Disclosure up front: I work on the gateway described below, so treat the code as practical and the conclusions as my own experience, not neutral benchmarks.
The problem
Most teams start with one model provider. Then a second need appears β cheaper bulk tasks, a model that handles a different language better, or a local option for sensitive data. Suddenly you are managing two SDKs, two key formats, and two billing dashboards.
The idea
An OpenAI-compatible endpoint keeps the request and response shape you already use. You change the base URL and the key. The rest of the client code stays put.
from openai import OpenAI
client = OpenAI ( base_url = "https://your-gateway.example/v1" , api_key = "YOUR_KEY" , )
resp = client . chat . completions . create ( model = "chosen-model" , messages = [ { "role" : "user" , "content" : "Hello" } ] , )
Enter fullscreen mode
Exit fullscreen mode
That is the whole migration.β¦