Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm API Route To Call Types

From Leeroopedia
Attribute Value
Sources litellm/litellm_core_utils/api_route_to_call_types.py
Domains Routing, Call Type Resolution
Last Updated 2026-02-15 16:00 GMT

Overview

Maps API route paths to their corresponding CallTypes enum values, supporting both exact and pattern-based URL matching.

Description

This module provides two utility functions that bridge API routes (such as /chat/completions) and the internal CallTypes enum used throughout LiteLLM. The mapping is sourced from the API_ROUTE_TO_CALL_TYPES dictionary defined in litellm.types.utils. The route matcher supports dynamic URL patterns with placeholder segments (e.g., {agent_id}) that match any single path segment, enabling flexible resolution for parameterized endpoints like A2A agent routes.

Usage

Import this module when you need to determine which CallTypes are valid for a given API endpoint, or when you need to discover all routes associated with a particular call type. Commonly used for request routing, logging, and access-control decisions within the LiteLLM proxy.

Code Reference

Source Location

litellm/litellm_core_utils/api_route_to_call_types.py (69 lines)

Signature

def _route_matches_pattern(route: str, pattern: str) -> bool
def get_call_types_for_route(route: str) -> Optional[List[CallTypes]]
def get_routes_for_call_type(call_type: CallTypes) -> list

Import

from litellm.litellm_core_utils.api_route_to_call_types import get_call_types_for_route, get_routes_for_call_type

I/O Contract

get_call_types_for_route

Direction Name Type Description
Input route str API route path (e.g., /chat/completions)
Output return Optional[List[CallTypes]] List of matching call types, or None if no match

get_routes_for_call_type

Direction Name Type Description
Input call_type CallTypes The call type enum to search for
Output return list List of route strings that include the given call type

Usage Examples

from litellm.litellm_core_utils.api_route_to_call_types import (
    get_call_types_for_route,
    get_routes_for_call_type,
)
from litellm.types.utils import CallTypes

# Look up call types for a standard route
call_types = get_call_types_for_route("/chat/completions")
# e.g., [CallTypes.completion, CallTypes.acompletion]

# Look up call types for a parameterized route
call_types = get_call_types_for_route("/a2a/my-agent/message/send")
# Matches pattern /a2a/{agent_id}/message/send

# Reverse lookup: find all routes for a call type
routes = get_routes_for_call_type(CallTypes.completion)
# e.g., ["/chat/completions", ...]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment