Does the AI SDK openai() helper have a fallback argument?
The OpenAI guide shows openai('model-id') and does not document a fallback list. Use LiteLLM fallbacks or OpenRouter's models array when you want a documented backup.
Point the model argument at the replacement id from the provider's deprecation page. LiteLLM and OpenRouter document a fallback list. The Vercel AI SDK OpenAI guide and LangChain's ChatOpenAI page document the model string, not a fallback list.
Last reviewed . Publisher: SunsetDiff.
LiteLLM's completion helper tries the model argument first, then each entry in fallbacks, in order. A fallback entry is a model name or a dict of completion arguments. The first success is returned. If every entry fails, completion raises, and the message ends with All fallback attempts failed.
The strings in the sample are the ones in LiteLLM's docs. Replace them with the retired id and the replacement id. The proxy uses a different shape: model_name is the name clients send, litellm_params.model is the provider string, and router_settings.fallbacks maps one model_name to another.
from litellm import completion
response = completion(
model="bad-model",
messages=[{"role": "user", "content": "Hello"}],
fallbacks=["gpt-6-luna", "command-nightly"],
)
router_settings:
fallbacks:
- gpt-6-luna:
- gpt-6.1-sol
Sources: LiteLLM reliable completions , LiteLLM proxy fallbacks , LiteLLM proxy config , checked October 20, 2026.
OpenRouter's model fallbacks guide says the models array is tried in order when the first model returns an error. Errors that trigger a fallback include context length, moderation, rate limits, and downtime. The response model field is the id that actually ran, and the price is that model's price.
With the OpenAI SDK, the guide puts the first id in model and the backups in extra_body.models. The ids below are the guide's examples, including the ~ prefix that guide uses. This page does not include an API key.
model = "~openai/gpt-sol-latest"
extra_body = {
"models": ["~anthropic/claude-sonnet-latest", "gryphe/mythomax-l2-13b"]
}
messages = [{"role": "user", "content": "What is the meaning of life?"}]
Source: OpenRouter model fallbacks , checked October 20, 2026.
The AI SDK OpenAI guide creates the model with openai('model-id'). The string in the docs example is gpt-6-astra. Change that string to the replacement id. generateText and streamText take that model object.
That guide does not document a fallback list. For a second model, use the LiteLLM or OpenRouter fallback above, or catch the error in your own code and call a second model id.
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
const { text } = await generateText({
model: openai("gpt-6-astra"),
prompt: "Hello",
});
Source: AI SDK OpenAI guide , checked October 20, 2026.
LangChain's models page sets the id on init_chat_model or on the provider class. The documented examples include init_chat_model("gpt-5.5"), ChatOpenAI(model="gpt-5.5"), ChatAnthropic(model="claude-sonnet-4-6"), ChatGoogleGenerativeAI(model="gemini-3.7-flash"), and init_chat_model("us.anthropic.claude-sonnet-4-6", model_provider="bedrock_converse").
Azure is the deployment name, not only the OpenAI model id. The documented call passes azure_deployment. Microsoft's working-with-models page is where that deployment's version and upgrade policy are set.
The chat integrations page says routers such as OpenRouter and LiteLLM offer automatic fallbacks. It does not document a fallback list on ChatOpenAI. The samples below omit credentials. The library reads the credential you already configured.
from langchain.chat_models import init_chat_model
model = init_chat_model("gpt-5.5")
model = init_chat_model(
"us.anthropic.claude-sonnet-4-6",
model_provider="bedrock_converse",
)
Sources: LangChain models , LangChain chat integrations , Working with Azure OpenAI models , checked October 20, 2026.
The OpenAI guide shows openai('model-id') and does not document a fallback list. Use LiteLLM fallbacks or OpenRouter's models array when you want a documented backup.
No. Keep the credential where the SDK already reads it. These samples only change the model id.