Skip to main content

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.
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
Never commit API keys to version control. Use environment files (.env) or your system’s secret management.
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.
CrewAI provides native integration with OpenAI through the OpenAI Python SDK.
Code
Basic Usage:
Code
Custom OpenAI-Compatible Endpoint:
Code
Advanced Configuration:
Code
Structured Outputs:
Code
Supported Environment Variables:
  • OPENAI_API_KEY: Your OpenAI API key (required)
  • OPENAI_BASE_URL: Custom base URL for OpenAI API (optional)
Features:
  • 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
Supported 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
Responses API Parameters:
  • 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 conversations
  • previous_response_id: ID of previous response for multi-turn
  • include: 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 structured ResponsesAPIResult with parsed built-in tool outputs
  • auto_chain: Automatically track and use response IDs for multi-turn conversations
  • auto_chain_reasoning: Track encrypted reasoning items for ZDR (Zero Data Retention) compliance
Use the Responses API for new projects, especially when working with reasoning models (o1, o3, o4) or when you need native multimodal support for files.
Note: To use OpenAI, install the required dependencies:
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 .env file:
Code
Example usage in your CrewAI project:
Code
All models listed here https://llama.developer.meta.com/docs/models/ are supported.Note: This provider uses LiteLLM. Add it as a dependency to your project:
CrewAI provides native integration with the Snowflake Cortex REST API through its OpenAI-compatible Chat Completions endpoint. This avoids LiteLLM fallback for snowflake/... models. Snowflake Cortex currently supports Chat Completions only in CrewAI, so use the default api mode and do not set api="responses".
Code
Basic Usage:
Code
Claude Models on Cortex:
Code
Supported Environment Variables:
  • SNOWFLAKE_PAT, SNOWFLAKE_TOKEN, or SNOWFLAKE_JWT: token used as the Bearer credential
  • SNOWFLAKE_ACCOUNT_URL: full Snowflake account URL
  • SNOWFLAKE_ACCOUNT, SNOWFLAKE_ACCOUNT_ID, or SNOWFLAKE_ACCOUNT_IDENTIFIER: account identifier used to build the account URL
Snowflake REST requests use the user’s default Snowflake role. Make sure that role has 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
CrewAI provides native integration with Anthropic through the Anthropic Python SDK.
Code
Basic Usage:
Code
Advanced Configuration:
Code
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.
Code
Thinking Configuration Options:
  • type: Set to "enabled" to activate extended thinking mode
  • budget_tokens (optional): Maximum tokens to use for thinking (helps control costs)
Models Supporting Extended Thinking:
  • claude-sonnet-4 and newer models
  • claude-3-7-sonnet (with extended thinking capabilities)
When to Use Extended Thinking:
  • Complex reasoning and multi-step problem solving
  • Mathematical calculations and proofs
  • Code analysis and debugging
  • Strategic planning and decision making
  • Research and analytical tasks
Note: Extended thinking consumes additional tokens but can significantly improve response quality for complex tasks.Supported Environment Variables:
  • ANTHROPIC_API_KEY: Your Anthropic API key (required)
Features:
  • 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
Important Notes:
  • max_tokens is a required parameter for all Anthropic models
  • Claude uses stop_sequences instead of stop
  • System messages are handled separately from conversation messages
  • First message must be from the user (automatically handled)
  • Messages must alternate between user and assistant
Supported Models:Note: To use Anthropic, install the required dependencies:
CrewAI provides native integration with Google Gemini through the Google Gen AI Python SDK.Set your API key in your .env file. If you need a key, check AI Studio.
.env
Basic Usage:
Code
Advanced Configuration:
Code
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 .env file:
.env
Then use the LLM as usual:
Code
To get an Express mode API key:For more details, see the Vertex AI Express mode documentation.
Vertex AI Configuration (Service Account):
Code
Supported Environment Variables:
  • GOOGLE_API_KEY or GEMINI_API_KEY: Your Google API key (required for Gemini API and Vertex AI Express mode)
  • GOOGLE_GENAI_USE_VERTEXAI: Set to true to 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 to us-central1)
Features:
  • 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
Gemini Models:Google offers a range of powerful models optimized for different use cases.Gemma Models:The Gemini API also supports Gemma models hosted on Google infrastructure.Note: To use Google Gemini, install the required dependencies:
The full list of models is available in the Gemini model docs.
Get credentials from your Google Cloud Console and save it to a JSON file, then load it with the following code:
Code
Example usage in your CrewAI project:
Code
Google offers a range of powerful models optimized for different use cases:Note: This provider uses LiteLLM. Add it as a dependency to your project:
CrewAI provides native integration with Azure AI Inference and Azure OpenAI through the Azure AI Inference Python SDK.
Code
Endpoint URL Formats:For Azure OpenAI deployments:
For Azure AI Inference endpoints:
Basic Usage:
Code
Advanced Configuration:
Code
Supported Environment Variables:
  • AZURE_API_KEY: Your Azure API key (required)
  • AZURE_ENDPOINT: Your Azure endpoint URL (required, also checks AZURE_OPENAI_ENDPOINT and AZURE_API_BASE)
  • AZURE_API_VERSION: API version (optional, defaults to 2024-06-01)
Features:
  • 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
Note: To use Azure AI Inference, install the required dependencies:
CrewAI provides native integration with AWS Bedrock through the boto3 SDK using the Converse API.
Code
Basic Usage:
Code
Advanced Configuration:
Code
Supported Environment Variables:
  • 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 to us-east-1)
  • AWS_REGION_NAME: AWS region (defaults to us-east-1). Alternative configuration for backwards compatibility with LiteLLM
Features:
  • 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
Important Notes:
  • 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
Amazon Bedrock is a managed service that provides access to multiple foundation models from top AI companies through a unified API.Note: To use AWS Bedrock, install the required dependencies:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Nvidia NIM provides a comprehensive suite of models for various use cases, from general-purpose tasks to specialized applications.Note: This provider uses LiteLLM. Add it as a dependency to your project:
NVIDIA Nemotron models are designed for demanding agentic workloads, including complex reasoning, long-context analysis, tool use, multilingual tasks, and high-stakes RAG.The 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.
Hosted NVIDIA NIM usage:
Code
Code
Self-hosted OpenAI-compatible endpoint:
Code
Model details: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:
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:
  1. Follow installation instructions from NVIDIA Website
  2. Install the local model. For Llama 3.1-8b follow instructions
  3. Configure your crewai local models:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
  1. Install Ollama: ollama.ai
  2. Run a model: ollama run llama3
  3. Configure:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Cerebras features:
  • Fast inference speeds
  • Competitive pricing
  • Good balance of speed and quality
  • Support for long context windows
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Open Router models:
  • openrouter/deepseek/deepseek-r1
  • openrouter/deepseek/deepseek-chat
Note: This provider uses LiteLLM. Add it as a dependency to your project:
Set the following environment variables in your .env file:
Code
Example usage in your CrewAI project:
Code
Nebius AI Studio features:
  • Large collection of open source models
  • Higher rate limits
  • Competitive pricing
  • Good balance of speed and quality
Note: This provider uses LiteLLM. Add it as a dependency to your project:

Streaming Responses

CrewAI supports streaming responses from LLMs, allowing your application to receive and process outputs in real-time as they’re generated.
Enable streaming by setting the stream parameter to True when initializing your LLM:
When streaming is enabled, responses are delivered in chunks as they’re generated, creating a more responsive user experience.

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.
Use the acall method for asynchronous LLM requests:
The 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 a response_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:
CrewAI includes smart context management features:
Best practices for context management:
  1. Choose models with appropriate context windows
  2. Pre-process long inputs when possible
  3. Use chunking for large documents
  4. Monitor token usage to optimize costs
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
  • Lower temperature (0.1 to 0.3) for factual responses
  • Higher temperature (0.7 to 0.9) for creative tasks
2

Best Practices

  1. Monitor token usage
  2. Implement rate limiting
  3. Use caching when possible
  4. Set appropriate max_tokens limits
Remember to regularly monitor your token usage and adjust your configuration as needed to optimize costs and performance.
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:
CrewAI provides message interceptors for several providers, allowing you to hook into request/response cycles at the transport layer.Supported Providers:
  • ✅ OpenAI
  • ✅ Anthropic
Basic Usage:
Important Notes:
  • 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

Most authentication issues can be resolved by checking API key format and environment variable names.