Overview
CrewAI integrates with multiple LLM providers through providers native sdks, giving you the flexibility to choose the right model for your specific use case. This guide will help you understand how to configure and use different LLM providers in your CrewAI projects.What are LLMs?
Large Language Models (LLMs) are the core intelligence behind CrewAI agents. They enable agents to understand context, make decisions, and generate human-like responses. Here’s what you need to know:LLM Basics
Large Language Models are AI systems trained on vast amounts of text data. They power the intelligence of your CrewAI agents, enabling them to understand and generate human-like text.
Context Window
The context window determines how much text an LLM can process at once. Larger windows (e.g., 128K tokens) allow for more context but may be more expensive and slower.
Temperature
Temperature (0.0 to 1.0) controls response randomness. Lower values (e.g., 0.2) produce more focused, deterministic outputs, while higher values (e.g., 0.8) increase creativity and variability.
Provider Selection
Each LLM provider (e.g., OpenAI, Anthropic, Google) offers different models with varying capabilities, pricing, and features. Choose based on your needs for accuracy, speed, and cost.
Setting up your LLM
There are different places in CrewAI code where you can specify the model to use. Once you specify the model you are using, you will need to provide the configuration (like an API key) for each of the model providers you use. See the provider configuration examples section for your provider.- 1. Environment Variables
- 2. YAML Configuration
- 3. Direct Code
The simplest way to get started. Set the model in your environment directly, through an
.env file or in your app code. If you used crewai create to bootstrap your project, it will be set already..env
CrewAI provides native SDK integrations for OpenAI, Anthropic, Google (Gemini API), Azure, AWS Bedrock, and Snowflake Cortex — no extra install needed beyond the provider-specific extras (e.g.
uv add "crewai[openai]").All other providers are powered by LiteLLM. If you plan to use any of them, add it as a dependency to your project:Provider Configuration Examples
CrewAI supports a multitude of LLM providers, each offering unique features, authentication methods, and model capabilities. In this section, you’ll find detailed examples that help you select, configure, and optimize the LLM that best fits your project’s needs.OpenAI
OpenAI
CrewAI provides native integration with OpenAI through the OpenAI Python SDK.Basic Usage:Custom OpenAI-Compatible Endpoint:Advanced Configuration:Structured Outputs:Supported Environment Variables:Responses API Parameters:
Code
Code
Code
Code
Code
OPENAI_API_KEY: Your OpenAI API key (required)OPENAI_BASE_URL: Custom base URL for OpenAI API (optional)
- Native function calling support (except o1 models)
- Structured outputs with JSON schema
- Streaming support for real-time responses
- Token usage tracking
- Stop sequences support (except o1 models)
- Log probabilities for token-level insights
- Reasoning effort control for o1 models
Responses API:OpenAI offers two APIs: Chat Completions (default) and the newer Responses API. The Responses API was designed from the ground up with native multimodal support—text, images, audio, and function calls are all first-class citizens. It provides better performance with reasoning models and supports additional features like auto-chaining and built-in tools.
Code
api: Set to"responses"to use the Responses API (default:"completions")instructions: System-level instructions (Responses API only)store: Whether to store responses for multi-turn conversationsprevious_response_id: ID of previous response for multi-turninclude: Additional data to include in response (e.g.,["reasoning.encrypted_content"])builtin_tools: List of OpenAI built-in tools:"web_search","file_search","code_interpreter","computer_use"parse_tool_outputs: Return structuredResponsesAPIResultwith parsed built-in tool outputsauto_chain: Automatically track and use response IDs for multi-turn conversationsauto_chain_reasoning: Track encrypted reasoning items for ZDR (Zero Data Retention) compliance
Meta-Llama
Meta-Llama
Meta’s Llama API provides access to Meta’s family of large language models.
The API is available through the Meta Llama API.
Set the following environment variables in your Example usage in your CrewAI project:All models listed here https://llama.developer.meta.com/docs/models/ are supported.
.env file:Code
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Snowflake Cortex
Snowflake Cortex
CrewAI provides native integration with the Snowflake Cortex REST API through its OpenAI-compatible Chat Completions endpoint. This avoids LiteLLM fallback for Basic Usage:Claude Models on Cortex:Supported Environment Variables:
snowflake/... models. Snowflake Cortex currently supports Chat Completions only in CrewAI, so use the default api mode and do not set api="responses".Code
Code
Code
SNOWFLAKE_PAT,SNOWFLAKE_TOKEN, orSNOWFLAKE_JWT: token used as the Bearer credentialSNOWFLAKE_ACCOUNT_URL: full Snowflake account URLSNOWFLAKE_ACCOUNT,SNOWFLAKE_ACCOUNT_ID, orSNOWFLAKE_ACCOUNT_IDENTIFIER: account identifier used to build the account URL
SNOWFLAKE.CORTEX_USER or SNOWFLAKE.CORTEX_REST_API_USER. Database, schema, warehouse, and explicit role parameters are not required by the Cortex REST Chat Completions endpoint.Features:- Native provider selection with
model="snowflake/<model-name>" - Streaming and non-streaming Chat Completions only;
api="responses"is not supported - Token usage tracking
- Function calling for Snowflake-hosted OpenAI and Claude models
- Automatic removal of invalid trailing assistant prefill for Snowflake Claude models
Anthropic
Anthropic
CrewAI provides native integration with Anthropic through the Anthropic Python SDK.Basic Usage:Advanced Configuration:Extended Thinking (Claude Sonnet 4 and Beyond):CrewAI supports Anthropic’s Extended Thinking feature, which allows Claude to think through problems in a more human-like way before responding. This is particularly useful for complex reasoning, analysis, and problem-solving tasks.Thinking Configuration Options:
Code
Code
Code
Code
type: Set to"enabled"to activate extended thinking modebudget_tokens(optional): Maximum tokens to use for thinking (helps control costs)
claude-sonnet-4and newer modelsclaude-3-7-sonnet(with extended thinking capabilities)
- Complex reasoning and multi-step problem solving
- Mathematical calculations and proofs
- Code analysis and debugging
- Strategic planning and decision making
- Research and analytical tasks
ANTHROPIC_API_KEY: Your Anthropic API key (required)
- Native tool use support for Claude 3+ models
- Extended Thinking support for Claude Sonnet 4+
- Streaming support for real-time responses
- Automatic system message handling
- Stop sequences for controlled output
- Token usage tracking
- Multi-turn tool use conversations
max_tokensis a required parameter for all Anthropic models- Claude uses
stop_sequencesinstead ofstop - System messages are handled separately from conversation messages
- First message must be from the user (automatically handled)
- Messages must alternate between user and assistant
Note: To use Anthropic, install the required dependencies:
Google (Gemini API)
Google (Gemini API)
CrewAI provides native integration with Google Gemini through the Google Gen AI Python SDK.Set your API key in your Basic Usage:Advanced Configuration:Vertex AI Express Mode (API Key Authentication):Vertex AI Express mode allows you to use Vertex AI with simple API key authentication instead of service account credentials. This is the quickest way to get started with Vertex AI.To enable Express mode, set both environment variables in your Then use the LLM as usual:Vertex AI Configuration (Service Account):Supported Environment Variables:The full list of models is available in the Gemini model docs.
.env file. If you need a key, check AI Studio..env
Code
Code
.env file:.env
Code
To get an Express mode API key:
- New Google Cloud users: Get an express mode API key
- Existing Google Cloud users: Get a Google Cloud API key bound to a service account
Code
GOOGLE_API_KEYorGEMINI_API_KEY: Your Google API key (required for Gemini API and Vertex AI Express mode)GOOGLE_GENAI_USE_VERTEXAI: Set totrueto use Vertex AI (required for Express mode)GOOGLE_CLOUD_PROJECT: Google Cloud project ID (for Vertex AI with service account)GOOGLE_CLOUD_LOCATION: GCP location (defaults tous-central1)
- Native function calling support for Gemini 1.5+ and 2.x models
- Streaming support for real-time responses
- Multimodal capabilities (text, images, video)
- Safety settings configuration
- Support for both Gemini API and Vertex AI
- Automatic system instruction handling
- Token usage tracking
Gemma Models:The Gemini API also supports Gemma models hosted on Google infrastructure.
Note: To use Google Gemini, install the required dependencies:
Google (Vertex AI)
Google (Vertex AI)
Get credentials from your Google Cloud Console and save it to a JSON file, then load it with the following code:Example usage in your CrewAI project:Google offers a range of powerful models optimized for different use cases:
Code
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Azure
Azure
CrewAI provides native integration with Azure AI Inference and Azure OpenAI through the Azure AI Inference Python SDK.Endpoint URL Formats:For Azure OpenAI deployments:For Azure AI Inference endpoints:Basic Usage:Advanced Configuration:Supported Environment Variables:
Code
Code
Code
AZURE_API_KEY: Your Azure API key (required)AZURE_ENDPOINT: Your Azure endpoint URL (required, also checksAZURE_OPENAI_ENDPOINTandAZURE_API_BASE)AZURE_API_VERSION: API version (optional, defaults to2024-06-01)
- Native function calling support for Azure OpenAI models (gpt-4, gpt-4o, gpt-3.5-turbo, etc.)
- Streaming support for real-time responses
- Automatic endpoint URL validation and correction
- Comprehensive error handling with retry logic
- Token usage tracking
AWS Bedrock
AWS Bedrock
CrewAI provides native integration with AWS Bedrock through the boto3 SDK using the Converse API.Basic Usage:Advanced Configuration:Supported Environment Variables:
Code
Code
Code
AWS_ACCESS_KEY_ID: AWS access key (required)AWS_SECRET_ACCESS_KEY: AWS secret key (required)AWS_SESSION_TOKEN: AWS session token for temporary credentials (optional)AWS_DEFAULT_REGION: AWS region (defaults tous-east-1)AWS_REGION_NAME: AWS region (defaults tous-east-1). Alternative configuration for backwards compatibility with LiteLLM
- Native tool calling support via Converse API
- Streaming and non-streaming responses
- Comprehensive error handling with retry logic
- Guardrail configuration for content filtering
- Model-specific parameters via
additional_model_request_fields - Token usage tracking and stop reason logging
- Support for all Bedrock foundation models
- Automatic conversation format handling
- Uses the modern Converse API for unified model access
- Automatic handling of model-specific conversation requirements
- System messages are handled separately from conversation
- First message must be from user (automatically handled)
- Some models (like Cohere) require conversation to end with user message
Note: To use AWS Bedrock, install the required dependencies:
Amazon SageMaker
Amazon SageMaker
Code
Code
Mistral
Mistral
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Nvidia NIM
Nvidia NIM
Set the following environment variables in your Example usage in your CrewAI project:Nvidia NIM provides a comprehensive suite of models for various use cases, from general-purpose tasks to specialized applications.
.env file:Code
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
NVIDIA Nemotron
NVIDIA Nemotron
NVIDIA Nemotron models are designed for demanding agentic workloads, including complex reasoning, long-context analysis, tool use, multilingual tasks, and high-stakes RAG.The Hosted NVIDIA NIM usage:Self-hosted OpenAI-compatible endpoint:Model details:
NVIDIA-Nemotron-3-Ultra-550B-A55B-NVFP4 model is a frontier-scale open-weight model from NVIDIA with 550B total parameters and 55B active parameters. It uses a LatentMoE architecture that combines Mamba-2, MoE, Attention, and Multi-Token Prediction (MTP), and supports context lengths up to 1M tokens.NVIDIA-Nemotron-3-Ultra-550B-A55B-NVFP4 is a very large model. NVIDIA lists minimum serving requirements of 4x GB200, 4x B200, 4x GB300, 4x B300, or 8x H100 GPUs. For most CrewAI users, the recommended path is to use NVIDIA NIM or another OpenAI-compatible hosted endpoint rather than running it locally.Code
Code
Code
Supported languages: English, French, Spanish, Italian, German, Japanese, Korean, Hindi, Brazilian Portuguese, and Chinese.Reasoning mode: Nemotron 3 Ultra supports configurable reasoning via its chat template using
enable_thinking=True or enable_thinking=False. If you are using a hosted endpoint, check your provider’s documentation for how that flag is exposed.For model details, license, and deployment guidance, see the NVIDIA Nemotron 3 Ultra model card.Note: Hosted NVIDIA NIM usage uses LiteLLM. Add it as a dependency to your project:Local NVIDIA NIM Deployed using WSL2
Local NVIDIA NIM Deployed using WSL2
NVIDIA NIM enables you to run powerful LLMs locally on your Windows machine using WSL2 (Windows Subsystem for Linux).
This approach allows you to leverage your NVIDIA GPU for private, secure, and cost-effective AI inference without relying on cloud services.
Perfect for development, testing, or production scenarios where data privacy or offline capabilities are required.Here is a step-by-step guide to setting up a local NVIDIA NIM model:Note: This provider uses LiteLLM. Add it as a dependency to your project:
- Follow installation instructions from NVIDIA Website
- Install the local model. For Llama 3.1-8b follow instructions
- Configure your crewai local models:
Code
Groq
Groq
Set the following environment variables in your Example usage in your CrewAI project:
.env file:Code
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
IBM watsonx.ai
IBM watsonx.ai
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Ollama (Local LLMs)
Ollama (Local LLMs)
- Install Ollama: ollama.ai
- Run a model:
ollama run llama3 - Configure:
Code
Fireworks AI
Fireworks AI
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Perplexity AI
Perplexity AI
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Hugging Face
Hugging Face
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
SambaNova
SambaNova
Set the following environment variables in your Example usage in your CrewAI project:
.env file:Code
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Cerebras
Cerebras
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Cerebras features:
- Fast inference speeds
- Competitive pricing
- Good balance of speed and quality
- Support for long context windows
Open Router
Open Router
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Open Router models:
- openrouter/deepseek/deepseek-r1
- openrouter/deepseek/deepseek-chat
Nebius AI Studio
Nebius AI Studio
Set the following environment variables in your Example usage in your CrewAI project:Note: This provider uses LiteLLM. Add it as a dependency to your project:
.env file:Code
Code
Nebius AI Studio features:
- Large collection of open source models
- Higher rate limits
- Competitive pricing
- Good balance of speed and quality
Streaming Responses
CrewAI supports streaming responses from LLMs, allowing your application to receive and process outputs in real-time as they’re generated.- Basic Setup
- Event Handling
- Agent & Task Tracking
Enable streaming by setting the When streaming is enabled, responses are delivered in chunks as they’re generated, creating a more responsive user experience.
stream parameter to True when initializing your LLM:Async LLM Calls
CrewAI supports asynchronous LLM calls for improved performance and concurrency in your AI workflows. Async calls allow you to run multiple LLM requests concurrently without blocking, making them ideal for high-throughput applications and parallel agent operations.- Basic Usage
- With Streaming
Use the The
acall method for asynchronous LLM requests:acall method supports all the same parameters as the synchronous call method, including messages, tools, and callbacks.Structured LLM Calls
CrewAI supports structured responses from LLM calls by allowing you to define aresponse_format using a Pydantic model. This enables the framework to automatically parse and validate the output, making it easier to integrate the response into your application without manual post-processing.
For example, you can define a Pydantic model to represent the expected response structure and pass it as the response_format when instantiating the LLM. The model will then be used to convert the LLM output into a structured Python object.
Code
Advanced Features and Optimization
Learn how to get the most out of your LLM configuration:Context Window Management
Context Window Management
CrewAI includes smart context management features:
Best practices for context management:
- Choose models with appropriate context windows
- Pre-process long inputs when possible
- Use chunking for large documents
- Monitor token usage to optimize costs
Performance Optimization
Performance Optimization
1
Token Usage Optimization
Choose the right context window for your task:
- Small tasks (up to 4K tokens): Standard models
- Medium tasks (between 4K-32K): Enhanced models
- Large tasks (over 32K): Large context models
2
Best Practices
- Monitor token usage
- Implement rate limiting
- Use caching when possible
- Set appropriate max_tokens limits
Remember to regularly monitor your token usage and adjust your configuration as needed to optimize costs and performance.
Drop Additional Parameters
Drop Additional Parameters
CrewAI internally uses native sdks for LLM calls, which allows you to drop additional parameters that are not needed for your specific use case. This can help simplify your code and reduce the complexity of your LLM configuration.
For example, if you don’t need to send the
stop parameter, you can simply omit it from your LLM call:Transport Interceptors
Transport Interceptors
CrewAI provides message interceptors for several providers, allowing you to hook into request/response cycles at the transport layer.Supported Providers:Important Notes:
- ✅ OpenAI
- ✅ Anthropic
- Both methods must return the received object or type of object.
- Modifying received objects may result in unexpected behavior or application crashes.
- Not all providers support interceptors - check the supported providers list above
Interceptors operate at the transport layer. This is particularly useful for:
- Message transformation and filtering
- Debugging API interactions
Common Issues and Solutions
- Authentication
- Model Names
- Context Length
