Menu

Swap OpenAI for DeepSeek without rewriting a single line of code
πŸ“°
0

Swap OpenAI for DeepSeek without rewriting a single line of code

DEV CommunityΒ·TokenHubΒ·about 1 month ago
#X7sIUPno
#ai#api#python#openai#gateway#model
Reading 0:00
15s threshold

Last month I added Claude to a project that was already using GPT-4o. Two SDKs, two error formats, two retry strategies. By the time I finished I had wrapped both in my own abstraction β€” a tiny LLM gateway, badly written, that I now had to maintain. Then I noticed something I should have noticed earlier: most of the new providers expose an OpenAI-compatible endpoint. DeepSeek, Mistral, Together, Fireworks β€” they all speak the same wire format. You don't need a new SDK. You need a new base_url . This post is the 5-minute version of that realization, with the tradeoffs I learned the hard way. The "before" code Standard OpenAI Python: from openai import OpenAI client = OpenAI ( api_key = " sk-... " ) resp = client . chat . completions . create ( model = " gpt-4o " , messages = [{ " role " : " user " , " content " : " Summarize this PR diff... " }], ) print ( resp . choices [ 0 ]. message .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More