Skip to main content

Overview

Function calling (also called tool use) allows LLMs to call external functions and APIs. LiteLLM provides a unified interface that automatically translates between different provider formats.

Quick Start

Defining Functions

Standard format used by LiteLLM.

Function Calling Flow

Tool Choice Control

Let the model decide whether to call functions.

Provider Support

Native support with full features.

Streaming with Function Calls

Parallel Function Calls

Some providers support calling multiple functions simultaneously.

Complex Parameter Types

Error Handling

Best Practices

  • Write clear, detailed descriptions
  • Explain when the function should be used
  • Include example values in parameter descriptions
  • Be specific about parameter formats
  • Use descriptive parameter names
  • Mark only truly required parameters as required
  • Provide enums for fixed choices
  • Use appropriate JSON schema types
  • Always validate function arguments
  • Handle JSON parsing errors gracefully
  • Return structured error messages to the model
  • Include relevant context in function results
  • Keep full conversation history in messages
  • Include both assistant and tool messages
  • Allow multiple tool call rounds if needed
  • Provide clear context in tool results

Advanced Patterns

Debugging