Neural network API
OpenAI-compatible API: how to switch to another model in an hour
An OpenAI-compatible API accepts requests in the same format as OpenAI: the same methods, the same fields, the same library. To move to another model, you change three values in code: the base address (base_url), the key and the model name. As of 16 October 2026, DeepSeek, Qwen in Alibaba Cloud and open models on a vLLM server work this way.
In short: what compatibility means
The openai library sends a request to the address in the base_url parameter. It does not care who answers: OpenAI, another provider’s cloud or your own server, as long as the answer comes in the same format.
The format includes the method address, messages with the system, user and assistant roles, generation parameters and the shape of the answer. As long as a provider repeats this structure, the openai library, frameworks and ready integrations work with it with no changes.
DeepSeek says it plainly in its documentation: the API is compatible with the OpenAI and Anthropic formats, and you only change the address and the key in the usual library (as of 16 October 2026). Alibaba Cloud describes the same for Qwen: the key, the address and the model name change.
For a company in Russia, this is a way not to depend on one provider. Russia is not on the list of OpenAI API countries, and access from outside the list may end with the account being blocked. Code written for OpenAI moves to an open model with no rewrite.
Who is compatible: clouds and your own server
As of 16 October 2026, the providers’ documentation gives this picture:
DeepSeek also accepts the Anthropic format at a separate address, so code written for Claude also moves by changing the address and the key.
For Qwen, the address contains the workspace ID (WorkspaceId), and the key works only in the region where it was created. You choose the region once, by where the company may process its data.
A cloud is simpler to launch, while your own server gives control over the data: requests do not go to the provider, and a model with open weights works inside your network. How Ollama, LM Studio and vLLM differ and what to choose for your load is covered separately.
- DeepSeek: the address https://api.deepseek.com for the OpenAI format and https://api.deepseek.com/anthropic for the Anthropic format; the models deepseek-flash and deepseek-v4-pro.
- Qwen in Alibaba Cloud Model Studio: compatible mode at an address like https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1 for Singapore; there are addresses for Beijing, Virginia and Tokyo.
- vLLM on your own server: it brings up OpenAI-compatible interfaces, including Chat, Completions, Responses and speech recognition.
What to change in code
Take code built on the openai library for Python. Three lines change: the address, the key variable and the model. The key sits in an environment variable, not in the code.
For Qwen, base_url gets the address of your region, and the key comes from the DASHSCOPE_API_KEY variable. For your own vLLM server, base_url gets that server’s address, and the model is named the way it was launched.
Streaming output works the same way: in DeepSeek’s examples, the stream flag goes to the same chat.completions.create method as with OpenAI.
Before the switch, move the address, the key and the model into the app settings. Then switching between providers needs no new build, and for a test a second copy of the settings is enough.
The rest of the code does not change: the same messages, the same parsing of the answer. Step-by-step connection to a CRM, 1C and bots is described in the guide to connecting an API.
import os
from openai import OpenAI
# Before: OpenAI(api_key=os.environ[“OPENAI_API_KEY”])
client = OpenAI(
base_url=”https://api.deepseek.com”,
api_key=os.environ[“DEEPSEEK_API_KEY”],
)
reply = client.chat.completions.create(
model=”deepseek-flash”,
messages=[{“role”: “user”, “content”: “Briefly summarize the supply contract”}],
)
print(reply.choices[0].message.content)What does not match
Compatibility covers the format, not the behavior. Differences show up right after you change the address; examples from the documentation as of 16 October 2026:
Rate limits and error texts also differ by provider, although the response codes are similar: a wrong key at Alibaba Cloud returns the standard 401 invalid_api_key. It is worth testing the error handler on the new model separately.
So the switch starts with a test on a copy, not with changing the address in the production system.
- Model names: each provider has its own, and OpenAI model names do not work in DeepSeek or Qwen.
- Parameters: in Alibaba Cloud the n parameter works only with qwen-plus, and tools cannot be combined with streaming output (stream).
- Own features: Qwen accepts extra parameters through extra_body, for example enable_search for search.
- Regions: an Alibaba Cloud key is bound to the region where it was created; with another region’s address, the request returns error 401 invalid_api_key.
- Methods: the set of methods differs by provider; DeepSeek uses /chat/completions in its examples.
- Answers: the format is the same, the content is different. Prompts tuned for one model give another result on a different one.
How to test quality on your own data
The test takes a few steps and is done before the production system is switched:
Decide by the numbers. If the new model matches the reference on most requests and fits the budget, switch one system, not all at once, and compare the error logs after a week. Token prices differ by provider; you can check them in the API price comparison.
Anonymize personal data in the test set before sending it to the cloud. On your own server, data does not leave your network.
If the test is easier to run on dedicated infrastructure, we pick an open model for the task: DeepSeek, Qwen or another with open weights, in the OpenAI format. You change the address and the key, and the code stays.
- Collect 50–100 real requests from the log: typical ones, hard ones and those where the current model made mistakes.
- Save reference answers: the current model’s answers or an employee’s correct answers.
- Run the same set through the new model, changing only base_url, the key and the model.
- Compare on four measures: accuracy, answer format (JSON, the required fields), response time and cost per 1,000 requests.
- Separately check tool calls (tools) and structured output, if the code uses them.
Questions and answers
Can you move from OpenAI to another model without rewriting code?
What is base_url?
Sources and dates
- DeepSeek API Docs, checked 16 October 2026api-docs.deepseek.com
- Alibaba Cloud Model Studio, OpenAI compatibility, checked 16 October 2026help.aliyun.com
- vLLM Docs, OpenAI-compatible server, checked 16 October 2026docs.vllm.ai
- OpenAI, Supported countries and territories, checked 16 October 2026developers.openai.com