Overview
Thecheck_models module tells you which model names you can pass to Agent(model_name=...). It merges two sources:
- LiteLLM’s model list:
litellm.model_listfrom the installedlitellmpackage. It is read once, when the module is imported, and needs no network. - OpenRouter’s live catalogue: fetched from
https://openrouter.ai/api/v1/models, with each id prefixedopenrouter/. No API key is needed. The list is cached for five minutes.
These functions are standalone utilities.
Agent does not call them, so an agent never checks its model_name against this list. Do not confuse get_available_models() here with Agent.get_available_models(), which returns the agent’s own fallback chain.Import
swarms and swarms.structs. The async and cache helpers live only in the module:
How the list is built
- Start with LiteLLM’s model list, de-duplicated, in LiteLLM’s order.
- If
include_openrouterisTrue, append each OpenRouter model, prefixedopenrouter/. A model is skipped when LiteLLM already lists it, either with theopenrouter/prefix or without it. - If
exclude_keywordsis set, drop every model whose name contains one of them. The match is a case-insensitive substring match, and it applies to both sources.
litellm version, so counts differ between environments.
Functions
get_available_models
bool
default:"True"
Fetch OpenRouter’s model list, or use the cached one, and include it. Set
False to stay offline and use only LiteLLM’s list.Optional[Iterable[str]]
default:"None"
Drop any model whose name contains one of these, case-insensitively.
str
Always
"success". A failed OpenRouter fetch does not change it; the OpenRouter names are just missing.int
The number of names in
models.List[str]
The model names: LiteLLM’s first, then OpenRouter’s.
is_model_available
model appears in the list.
str
required
A model name as you would pass to
Agent(model_name=...).bool
default:"True"
Also check OpenRouter’s catalogue.
True if the name is listed.
model_count
get_available_models() would return with the same arguments. Returns its count.
aget_available_models
get_available_models(). It takes the same arguments, returns the same dict, and shares the same OpenRouter cache. Import it from swarms.structs.check_models.
fetch_openrouter_models
id in the response’s data array becomes openrouter/<id>, for example openrouter/moonshotai/kimi-k3, and entries without an id are skipped. Returns the names, or an empty list if the request fails. The result is not merged with LiteLLM’s list and ignores exclude_keywords.
afetch_openrouter_models
fetch_openrouter_models(), sharing its cache.
clear_openrouter_cache
OpenRouter caching
OpenRouter’s list is kept in one module-level cache that the sync and async functions share.- Within the lifetime, every call returns the cached list without a request.
- On a failed fetch, a warning is logged and an empty list is returned. The empty list is cached for the full lifetime too, so a dead endpoint is retried once every five minutes rather than on every call.
- To force a refresh, call
clear_openrouter_cache().
Examples
Validate a model name before building an agent
Filter out non-chat models
Search a provider’s models
Use it from async code
Refresh the OpenRouter list
Related
Model providers
How to name models from each provider
OpenRouter
Run agents on OpenRouter models
LLMManager
An agent’s own model and fallback chain
Decision models
get_decision_models() lists TypeSafe and Cloudflare decision models