Skip to main content

Connect CrewAI to LLMs

CrewAI connects to LLMs through native SDK integrations for the most popular providers (OpenAI, Anthropic, Google Gemini, Azure, and AWS Bedrock), and uses LiteLLM as a flexible fallback for all other providers.
By default, CrewAI uses the gpt-4o-mini model. This is determined by the OPENAI_MODEL_NAME environment variable, which defaults to “gpt-4o-mini” if not set. You can easily configure your agents to use a different model or provider as described in this guide.

Supported Providers

LiteLLM supports a wide range of providers, including but not limited to:
  • OpenAI
  • Anthropic
  • Google (Vertex AI, Gemini)
  • Azure OpenAI
  • AWS (Bedrock, SageMaker)
  • Cohere
  • VoyageAI
  • Hugging Face
  • Ollama
  • Mistral AI
  • Replicate
  • Together AI
  • AI21
  • Cloudflare Workers AI
  • DeepInfra
  • Groq
  • SambaNova
  • Nebius AI Studio
  • NVIDIA NIMs
  • And many more!
For a complete and up-to-date list of supported providers, please refer to the LiteLLM Providers documentation.
To use any provider not covered by a native integration, add LiteLLM as a dependency to your project:
Native providers (OpenAI, Anthropic, Google Gemini, Azure, AWS Bedrock) use their own SDK extras — see the Provider Configuration Examples.

Changing the LLM

To use a different LLM with your CrewAI agents, you have several options:
Pass the model name as a string when initializing the agent:

Configuration Options

When configuring an LLM for your agent, you have access to a wide range of parameters: For a complete list of parameters and their descriptions, refer to the LLM class documentation.

Connecting to OpenAI-Compatible LLMs

You can connect to OpenAI-compatible LLMs using either environment variables or by setting specific attributes on the LLM class:

Using Local Models with Ollama

For local models like those provided by Ollama:
1
2

Pull the desired model

For example, run ollama pull llama3.2 to download the model.
3

Configure your agent

Changing the Base API URL

You can change the base API URL for any LLM provider by setting the base_url parameter:
Code
This is particularly useful when working with OpenAI-compatible APIs or when you need to specify a different endpoint for your chosen provider.

Conclusion

By leveraging LiteLLM, CrewAI offers seamless integration with a vast array of LLMs. This flexibility allows you to choose the most suitable model for your specific needs, whether you prioritize performance, cost-efficiency, or local deployment. Remember to consult the LiteLLM documentation for the most up-to-date information on supported models and configuration options.