Skip to main content

LLM Module

The LLM module provides the core language model client and utilities for agent interactions, supporting multiple providers through LiteLLM.

Param Cluster Map

Note: base_url and api_key remain separate parameters (connection/auth constraint).

Precedence Ladder

Instance > Config > Array > Dict > String > Bool > Default

Ways to Use llm=

Legacy (Deprecated)

Installation

Quick Start

Classes

LLM

Main LLM client class supporting multiple providers.

Constructor

Methods

LLMContextLengthExceededException

Exception raised when context length is exceeded.

OpenAIClient

OpenAI-compatible client for direct API access.

ModelRouter

Intelligent model routing based on task complexity.

TaskComplexity

ModelProfile

Profile for a model’s capabilities.

Response Types

ChatCompletion

ChatCompletionMessage

ToolCall

CompletionUsage

Utility Functions

supports_structured_outputs

Check if a model supports structured outputs.

supports_streaming_with_tools

Check if a model supports streaming with tool calls.

process_stream_chunks

Process streaming response chunks.

create_routing_agent

Create an agent with model routing.

Usage Examples

Basic Chat

Streaming Response

With Tools

Model Routing

Different Providers

Environment Variables