Skip to main content

Overview

The check_models module tells you which model names you can pass to Agent(model_name=...). It merges two sources:
  • LiteLLM’s model list: litellm.model_list from the installed litellm package. 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 prefixed openrouter/. 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

These three are exported from swarms and swarms.structs. The async and cache helpers live only in the module:

How the list is built

  1. Start with LiteLLM’s model list, de-duplicated, in LiteLLM’s order.
  2. If include_openrouter is True, append each OpenRouter model, prefixed openrouter/. A model is skipped when LiteLLM already lists it, either with the openrouter/ prefix or without it.
  3. If exclude_keywords is set, drop every model whose name contains one of them. The match is a case-insensitive substring match, and it applies to both sources.
The LiteLLM list depends on your installed litellm version, so counts differ between environments.

Functions

get_available_models

List every model name LiteLLM knows, plus OpenRouter’s live catalogue.
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.
Returns a dict:
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.
This function never raises on a network failure. See OpenRouter caching.

is_model_available

Whether 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.
Returns True if the name is listed.
The check is an exact, case-sensitive string match. LiteLLM can route some names it does not list, such as provider-prefixed spellings like "openai/gpt-5.4", so False does not always mean an agent cannot call the model. Check the bare name too, or look the name up in get_available_models()["models"].

model_count

How many model names get_available_models() would return with the same arguments. Returns its count.

aget_available_models

The async form of 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

Fetch OpenRouter’s model list on its own. Each 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

The async form of fetch_openrouter_models(), sharing its cache.

clear_openrouter_cache

Forget the cached OpenRouter list, so the next call fetches it again.

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

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