
In an AI gateway, the model is just one field of the request. If you keep the model id in a setting, not in the code, you change models without touching a line of the program: you change the setting and restart.
The model in an environment variable
import os
from openai import OpenAI
client = OpenAI(base_url="api.mozout.co.mz/v1", api_key=os.environ["MOZOUT_API_KEY"])
model = os.environ.get("AI_MODEL", "deepseek-ai/deepseek-v4-flash")
r = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Summarise this text in two sentences: ..."}],
max_tokens=300,
)
print(r.choices[0].message.content)
To move to deepseek-ai/deepseek-v4-pro, for example, you only change AI_MODEL. The request, the response format and the key stay the same.
Before you switch, check three things
| What | Where to see it |
| The price | On the Models tab or in GET /v1/models, in the pricing field. A stronger model can cost several times more. |
| The context and maximum output | context_length and max_output_tokens, in the same place. A long text may not fit in a model with a smaller context. See what each one means. |
| Tools | If your program sends tools, check that the new model accepts them, with a small request before you switch in production. |
A backup model, if the main one fails
With the model in a setting, you can also keep a second one for when the first answers 502 upstream_error. If the first fails with 502, the program moves on to the second:
import openai
models = [os.environ.get("AI_MODEL", "deepseek-ai/deepseek-v4-flash"),
os.environ.get("AI_MODEL_BACKUP", "zai-org/glm-5.2")]
for m in models:
try:
r = client.chat.completions.create(model=m, messages=messages, max_tokens=300)
break
except openai.APIStatusError as e:
if e.status_code != 502:
raise
See when to try again and when to choose another model.
| Before you pick the main model, compare: the same request on several models. |
|
Want to pick your next model? Open the Models tab. See All in One AI |
|
SEE ALSO Why every model id has a slash |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 396,00 MT/mo (3-year plan, with coupon) See plans |











