Skip to main content

Overview

Perform chat completions using any of LiteLLM’s 100+ supported LLM providers. Returns responses in OpenAI format.

Function Signature

Parameters

Required Parameters

string
required
The model to use for completion. See supported models for the full list.Examples: gpt-4, claude-3-5-sonnet-20241022, gemini-pro, bedrock/anthropic.claude-v2
List[dict]
required
List of message objects representing the conversation context.Each message should have:
  • role: “system”, “user”, “assistant”, or “tool”
  • content: The message content (string or array for multimodal)

Generation Parameters

float
default:"1.0"
Controls randomness in the output. Higher values (e.g., 1.0) make output more random, lower values (e.g., 0.2) make it more deterministic.Range: 0.0 to 2.0
float
default:"1.0"
Nucleus sampling parameter. The model considers tokens with top_p probability mass.Range: 0.0 to 1.0
int
Maximum number of tokens to generate in the completion.
int
Upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
int
default:"1"
Number of chat completion choices to generate for each input message.
Union[str, List[str]]
Up to 4 sequences where the API will stop generating further tokens.
float
default:"0.0"
Penalizes new tokens based on their existence in the text so far.Range: -2.0 to 2.0
float
default:"0.0"
Penalizes new tokens based on their frequency in the text so far.Range: -2.0 to 2.0
dict
Modify the probability of specific tokens appearing in the completion.Maps token IDs to bias values from -100 to 100.

Streaming

bool
default:"false"
If true, returns a streaming response.
dict
Options for streaming response. Only use when stream=True.

Function Calling & Tools

List[dict]
List of tools the model can call. Use OpenAI tool format.
Union[str, dict]
Controls which tool is called. Options:
  • "none": Don’t call any tool
  • "auto": Let the model decide
  • {"type": "function", "function": {"name": "tool_name"}}: Force specific tool
bool
default:"true"
Whether to enable parallel function calling.

Response Format

Union[dict, Type[BaseModel]]
Specify the format of the response.For JSON mode:
For structured outputs with Pydantic:

Advanced Parameters

Literal
Control reasoning effort for reasoning models (e.g., o1, o3).Options: "none", "minimal", "low", "medium", "high", "xhigh", "default"
List[str]
Output types you want the model to generate.Example: ["text", "audio"]
dict
Parameters for audio output. Required when audio is requested with modalities.
dict
Configuration for Predicted Output, which can improve response times when large parts of the response are known ahead of time.
bool
default:"false"
Whether to return log probabilities of output tokens.
int
Number of most likely tokens to return at each position (0-5). Requires logprobs=True.
int
Seed for deterministic sampling. Supported by some providers.
string
Unique identifier for your end-user, for abuse monitoring.

API Configuration

string
API key for the provider. If not provided, uses environment variables.
string
Base URL for the API endpoint.
string
API version to use (provider-specific).
Union[float, httpx.Timeout]
default:"600"
Request timeout in seconds.
dict
Additional headers to include in the request.

LiteLLM Specific

string
Override the provider detection. Use for non-standard providers.Example: custom_llm_provider="bedrock"
string
Return a mock response for testing/debugging.
int
default:"0"
Number of retry attempts on failure.
List[str]
List of fallback models to try if the primary fails.
dict
Additional metadata to tag the completion call.
dict
Anthropic thinking parameter for extended thinking mode.

Response

ModelResponse

string
Unique identifier for the completion.
List[Choice]
List of completion choices.
int
Unix timestamp of when the completion was created.
string
Model used for completion.
Usage
Token usage information.
float
Response time in milliseconds (LiteLLM specific).

Usage Examples

Basic Completion

Streaming

Async Completion

Function Calling

Multiple Providers

Error Handling