Allowed models
Fix the list of models your program may use, and let the user choose from it.
A program that ships to other people, such as a harness or a binary, often needs one fixed list of models. Put the list in your code and give it to setModels. The SDK never reads the list from disk, so a user cannot change it by editing a file in their home folder.
import { setModels, listModels } from "agent-accelerator";
setModels({
default: {
model: "google/gemini-4-argon",
sub_agent_model: "google/gemini-4-argon",
},
providers: {
google: { models: ["gemini-4-argon", "gemini-4-carbon"] },
anthropic: { models: ["claude-opus-5-5"] },
openrouter: { models: ["meta/muse-ember"] },
},
});
// A list for a model picker:
for (const m of listModels()?.models ?? []) console.log(m.model);The shape of the list
- Models sit under their provider without the
provider/prefix. The SDK joins them intoprovider/model. OpenRouter ids keep their own slash:"meta/muse-ember"becomesopenrouter/meta/muse-ember. Use real catalog ids. Anthropic ids use dashes:claude-opus-5-5. default.modelanddefault.sub_agent_modelare fullprovider/modelstrings and must be on the list.- The list means "any of these". It is not a fallback order, and the model never picks from it.
- The shape is exact. A wrong shape, an unknown key, a provider with no models, an empty, duplicate or wildcard (
*) entry, aprovider/prefix, or a default outside the list throws oneConfigErrorthat lists every problem. Nothing changes. listModels()returns{ default, models: [{ provider, id, model }] }, frozen, orundefineduntil you callsetModels. CallingsetModelsagain replaces the list.- This is a guardrail inside your program, not a security wall. Other code in the same process can call
setModelstoo.
The user's choice
setModel(id) and setSubAgentModel(id) save the user's pick in <home>/configs.json. They are the only way the model is written. See Settings.
- The id must be a full
provider/modelstring that is on your list. OtherwiseModelNotAllowedErroris thrown and nothing is saved. With no list, any non-empty id is accepted. - An
Agentwith nomodeluses the saved choice, then yourdefault.model. A worker with no model uses the savedsub_agent_model, thendefault.sub_agent_model. This also covers asubagents: [...]entry written as data without amodel; a plainAgentwithout one uses the main model. - A model you name in the
Agentconfig always wins. - A saved model that is no longer on the list (you shipped a new list) is ignored, with a
config.saved_model_ignoredwarning, and the default is used.
Where the list is enforced
Once you call setModels, a model outside the list throws ModelNotAllowedError. It is a ConfigError, so it is never retried. The message names the model and lists the available ones, like Model "openai/gpt-6" is not available. Available: google/gemini-4-argon, ....
The list is checked wherever a model is picked:
- Every run start (
run,stream, queued runs, resumed runs), before anything is sent. - The
Agentconstructor, for the main model and the worker model. This also coversAgent.fromConfigandfork(). - Chat workers and scheduled runs. A scheduled run whose model is off the list is recorded as failed.
importSession, for the session's model and worker model, before anything changes.
The model catalog is filtered when it is read. getModelsForProvider and the catalog lookups show only listed models, and clearing the list brings everything back. The cache files are never changed, because several processes can share one home.
A listed model the catalog does not know is still allowed. Its price is unknown, never $0. Without setModels, nothing is restricted.