Skip to main content

Core, config and host interfaces

Since v1.110.0

The interfaces between the Python facade, the Rust core and the host it runs under. The core and the host explains why they are shaped this way.

The Router facade uses the RouterCore protocol; RustCore implements it and
holds a handle to the Rust RustRouter, which calls the Host trait that
PythonHost implements

Python side​

NameFileWhat it is
Routerlitellm/router.pythe facade. Router(**arguments) and Router.from_config(config, host=python_host)
RouterCorelitellm/router_core.pythe protocol the facade delegates to
make_core(config, host)litellm/router_core.pybuilds the core once, when the Router is built
RustCorelitellm/router_rust/core.pyholds one RouterCoreHandle and answers its steps
RustBridgeDeclinedlitellm.rust_bridge._nativeraised when the handle cannot read a config
RouterConfiglitellm/router_config.pythe constructor arguments, frozen, with plain containers copied (build_router_config)
RouterDynamicConfiglitellm/router_config.pya versioned snapshot of the process settings the router reads per call (current_dynamic_config())
PythonHostlitellm/router_python_host.pyinvoke(op) returns the litellm endpoint function, plus sleep, dynamic(), the callback lists, the global cache and routing_cache(config)
router_attemptlitellm/router_attempt.pybuilds one attempt's keyword arguments for the deployment the core picked
RouterHostlitellm/router_host.pywhat only the application can answer (vertex pass-through credentials, member auto-router authorization)
DeprecatedRouterMemberslitellm/router_deprecated.pythe old Router member names, served with a DeprecationWarning

RouterDynamicConfig fields are num_retries, max_fallbacks, router_max_fallbacks, allowed_fails, request_timeout, fallbacks, default_fallbacks, context_window_fallbacks, content_policy_fallbacks, drop_params, provider_list, expose_router_debug_in_errors, redact_user_api_key_info, model_alias_map, model_cost, known_custom_logger_compatible_callbacks, exception_types, callbacks, success_callback, failure_callback, input_callback, callback_manager and cache, plus its version.

The step protocol​

RouterCoreHandle(config, dynamic) in litellm.rust_bridge._native wraps one Rust Router. start(op, request), select(model, request) and healthy(model, request) return a RouterCall, and so do the report and model info queries. The driver calls RouterCall.next(answer) until it gets done or failed. Every step carries the routing events since the last step.

StepThe core needsThe driver answers with
attemptone attempt run on the named deploymentthe response and its total tokens, or the typed failure
sleepa backoff of secondsnothing, after sleeping through the host
allow_fallbackwhether a cross-group fallback target is alloweda bool from the fallback access and budget checks
pre_routethe sub-routers, session binding or a custom strategy before a pick resolves modela model group, a deployment the custom strategy picked, or None
selectone host stage run on the candidates, named by stagesee the stage table below
cachea routing cache read or write (get, set, batch_get, increment and the rest)the values read, or an acknowledgement
secrets, validate, provider, addedone deployment's build, while a config or change set is appliedthe resolved secrets, the validated entry, the provider, the added entry
model_infoa cost map or capability lookup during a model info querythe lookup's documents
donenothing morethe result goes back to the caller, with routing headers
failednothing morethe error goes back to the caller, by its error_kind
select stageThe host returns
routing_pluginsthe candidate models the routing plugins left, after running them when run is set
callback_filtersthe deployment ids the CustomLogger filters left, or a failure
pluginsthe deployments Router(plugins=[...]) objects left
pre_callthe facts the pre-call checks decide by, such as token counts
tagsthe deployments tag routing left
text_onlythe candidates that declare no vision support
route_incapablethe candidates whose provider cannot serve the call the handler names
media_refusingthe candidates that refuse the audio or videos a Decisions call carries
embedding_batchthe candidates that admit the embedding input
override_checkthe candidates after a per-request strategy's pre-call check, or its refusal
provider_requestthe provider/model form of a bare name, for wildcard matching
strategythe candidates with the pick first, for a strategy the core does not implement

apply(changes) returns the new registry version, registry_version() reads it, and retire() retires the router.

Rust side​

All of these live in litellm-rust/crates/router-core/src/.

TypeModuleWhat it is
Router, RouterBuilderlib.rsRouter::new(config, dynamic, host), or the builder with randomness and clock for tests
RouterConfig, RouterDynamicConfig, Op, RoutingStrategy, RetryPolicy, AllowedFailsPolicyconfig.rsstatic and dynamic config, the operation name, the strategies (is_native is true for simple-shuffle)
Registry, Deployment, ChangeSet, RegistryVersion, deployment_idregistry.rsthe immutable, indexed deployments
Settingssettings.rsthe frozen settings view
Health, Outcome, Clock, cooldown_key, usage_keyhealth.rscooldowns, allowed fails, usage and the outcome counters
RouterCache, InMemoryRouterCachecache.rsthe routing state store the host provides
Randomness, SeededRandomness, simple_shuffleselect.rsthe filter chain and simple-shuffle
resolve_request, all_deploymentsresolve.rsname resolution
routing_context, request_overridestrategy.rswhich strategy a pick uses
RouterWeights, validateweights.rsper-request weights
RouterResponsecall.rsthe call loop's result with the deployment, group, retries and fallbacks used
StreamPolicy, StreamOrigincall/stream.rswhat may take over a stream that broke
Fallbacks, FallbackTargetfallback.rsthe parsed fallback lists
Host, Attempt, RouterRequest, Output, RouterEvent, RoutingContext, SelectStagehost.rsthe host seam
Error, ConfigError, Unsupported, AttemptError, FailureKinderror.rserrors at build time, at call time, and per attempt

The other modules hold one stage or query each: access.rs (access groups and windows), ptu.rs (PTU shares), health_routing.rs, precall.rs, prerouting.rs, routing_groups.rs, routing_plugins.rs, retry.rs, mock.rs (mock_testing_* failures), build.rs (the deployment build), lookup.rs and host_index.rs (the indexes the Python surface reads), model_info.rs and group_info.rs (model info merges).

Op is the operation's name as a string, such as acompletion, aembedding, aresponses or aanthropic_messages. The core passes it to the host and never interprets it.

Host​

MethodCalled for
invoke(attempt)every attempt. There is no native attempt path
select(stage, ctx, candidates)the Plugins, Strategy, Tags, TextOnly, RouteIncapable, MediaRefusing, EmbeddingBatch and OverrideCheck stages
pre_route(ask)pre-routing, and the whole pick for a custom strategy
routing_plugin_models, callback_filters, pre_call_facts, provider_requestthe stages that need live Python objects
allow_fallback(request, target)the access and budget checks before a cross-group fallback
refuses_fallbacks(level, targets)whether a chain is refused for one of its dict targets, such as a server-owned federation field or an oidc/ api key. Defaults to false
sleep(duration), observe(event), cache()backoff, routing events, the routing state store
secrets, validate, provider, addedthe deployment build
model_info(lookup)cost map and capability lookups
supports(op, provider), can_select()what the host can serve. Both default to true, and PythonHost serves everything

RouterRequest​

FieldMeaning
modelthe requested name, a model group, alias, routing group, deployment id or wildcard match
bodythe request params the core's own checks read
team_id, listing_team_id, proxy_admin, allowed_models, admin_modelthe caller facts the team and access filters read. listing_team_id is the team a failed level lists the group's deployments for
specific_deploymentthe caller named a deployment's litellm_params.model
pinned_deployment_ida deployment the session or affinity binding pinned
num_retries, uncounted_retries, model_group_retry_policy, retry_policy_raisesper-request retry settings, which win over the router's. uncounted_retries holds a num_retries that is not a count
disable_fallbacks, fallbacks, context_window_fallbacks, content_policy_fallbacks, max_fallbacksper-request fallback settings
same_group_fallbacks_onlythe request names a resource only one provider holds, such as an uploaded file, so it falls back inside its own group
cooldown_timea per-request cooldown
router_weightsper-team weights, model group to deployment id to weight
routing_strategya per-request strategy override
filter_tags, has_imageinputs to the tag and text-only stages
endpoint, web_search, route_handler, decisions_media, batch_create, embedding_batchwhat the call needs, which removes deployments that declare they cannot serve it
wildcard_requestthe provider/model form of the name, for a lookup that cannot ask the host
pass_througha pass-through route, which serves only pass-through deployments
target_order, excluded_ids, retry_skipped_idsthe order an order fallback targets, and ids the pick must skip
pre_routes, unrouted, skip_weighted_failoverwhether and how pre-routing and weighted failover run
passthrough_on_no_deploymenta failed pick hands the attempt to the host under the requested name
outcome_callbackswhich of the router's outcome callbacks run for this request
mock_failure, health_check_probetest failures and health check probes
payloadwhat the host needs to run the call itself, such as the Python kwargs

Attempt and Output​

Attempt carries op, request, deployment, name (the requested name or the fallback target), model_group (the group served, after fallbacks), routed (the group a pre-routing hook selected, when it differs), target_order, candidate_ids, retry (0 for the first attempt in this group), fallback_depth, fallback_level (0 for the requested name), timeout, params, scope, max_retries and model_group_size.

Output carries the value the host hands back unchanged, total_tokens, blocked (ContentFilter or Refusal, which the fallback rules read) and deferred, which is set for a stream or realtime session whose outcome the host reports when it ends, and tracks_usage, which says whether the attempt counts against the deployment's per-minute usage when the host knows better than the deployment's own limits.

RouterEvent​

EventFields
PickStartedmodel
Selectedmodel_group, deployment_id, pick
Succeededdeployment_id
AttemptFaileddeployment_id, kind, status
CooldownSetdeployment_id, cooldown
Retrymodel_group, retry, delay
Fallbackfrom, to, order, depth, level, scope, parent, max_fallbacks, unroutable
FallbackDonefrom, to, level, scope, parent, succeeded
Blockedlevel, model, blocked
RetryLoggedscope, level, model, attempted_retries, cause
RetriesOpenedscope, max_retries, model_group_size
RetryBudgetscope, max_retries
PickFailedlevel, model, error
LevelFailedlevel, model, error, handling
MockFailedmock, level, model, num_retries
RetryPolicyRaisedlevel, model, cause
RetryCountRaisedlevel, model, cause
FallingBacklevel, model
OrderChainFailedlevel, last_hop
FallbacksFailedlevel, chain, last_hop
RetriesExhaustedmodel_group, attempted, max, level, picked

The driver uses the later events to raise the exception a caller expects at that point, with the retry and fallback attributes set.

FailureKind​

The kinds are RateLimit, ContextWindowExceeded, ContentPolicyViolation, Authentication, PermissionDenied, NotFound, BadRequest, Timeout, ApiConnection, InternalServer, ServiceUnavailable, BadGateway, GuardrailIntervention (never retried or fallen back from), Declined (litellm rejected the request before calling, and it never cools a deployment down), CallerCredentialAuthentication and CallerCredentialRateLimit (the caller's own credential failed) and Other. AttemptError adds status, retry_after, num_retries, the provider's error text for the cooldown record, and agentic_followup, which marks an agentic follow-up call that failed after the first call was served and is never retried.

Build-time errors​

Router::new returns ConfigError when the registry cannot be built, for example from a malformed deployment or a duplicate id, or when the host cannot serve the config. Unsupported names what is missing: a strategy or plugin on a host that cannot select, or an operation and provider pair the host does not support. Under PythonHost neither happens, since it serves every operation and strategy.

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →