今日已更新 311 条资讯 | 累计 29453 条内容
关于我们

One OpenAI-Compatible Endpoint for Multiple LLM Providers: A Practical Setup Guide

jack lee 2026年07月28日 05:11 7 次阅读 来源:Dev.to

When an application starts using more than one language model provider, the hard part is rarely the first API call. The hard part is everything that follows: separate credentials, different request shapes, provider-specific errors, billing dashboards, and model migrations scattered across the codebase. A useful way to reduce that surface area is to keep one OpenAI-compatible client contract and move provider choice into configuration. This guide shows the smallest working setup with Routara , plus the production checks I recommend before sending real traffic. 1. Keep the SDK, change the endpoint If your project already uses the OpenAI Python SDK, the client initialization is the only part that needs to change: import os from openai import OpenAI client = OpenAI ( api_key = os . environ [ " ROUTARA_API_KEY " ], base_url = " https://api.routara.ai/v1 " , ) response = client . chat . completions . create ( model = " deepseek-chat " , messages = [ { " role " : " user " , " content " : " Explain idempotency in two sentences. " } ], ) print ( response . choices [ 0 ]. message . content ) Store the key in an environment variable. Do not put it in browser code, a public repository, screenshots, or support messages. The same pattern works in Node.js: import OpenAI from " openai " ; const client = new OpenAI ({ apiKey : process . env . ROUTARA_API_KEY , baseURL : " https://api.routara.ai/v1 " , }); const result = await client . chat . completions . create ({ model : " deepseek-chat " , messages : [{ role : " user " , content : " Return one short test sentence. " }], }); console . log ( result . choices [ 0 ]. message . content ); 2. Treat model IDs as configuration Do not spread model names throughout the application. Put them in environment variables or a typed configuration object: model_id = os . environ . get ( " ROUTARA_MODEL " , " deepseek-chat " ) That makes model evaluation and rollback much safer. Routara's live model catalog is the source of truth for current availa

本文内容来源于互联网,版权归原作者所有
查看原文