Unable to Use Local Ollama LLM with CrewAI 1.3.0

Hi,

I’m trying to run a local LLM (Gemma3 12B) via Ollama with CrewAI version 1.3.0, but I keep running into issues.

Here is my setup:

from utils import basic_auth, api_key, OLLAMA_URL, modelo, OLLAMA_LOCALHOST,modelo_localhost, prioridade_baixa, prioridade_media, prioridade_alta, prioridade_urgente
from requests.auth import HTTPBasicAuth
import os

# Warning control
import warnings

warnings.filterwarnings("ignore")


os.environ["OPENAI_API_KEY"] = "dummy"

# os.environ["CREWAI_LLM_PROVIDER"] = "ollama"

from crewai import Agent, Crew, Task, Process, LLM


# llm = LLM(
#     model="ollama/gemma3:12b",
#     stream=True
# )

llm = LLM(
    model='ollama/gemma3:12b',
    base_url='http://localhost:11434'
)

assunto = "Que horas são?"
descricao = "Por favor, gostaria de saber que horas são em São Paulo."


class CrewClassificar:
    def classificador_prioridade(self) -> Agent:
        return Agent(
    role="Classificador de Prioridade de Tickets",
    goal=(
        "Classificar a prioridade de um ticket do Freshdesk em **Baixa**, **Média**, **Alta** ou **Urgente**, "
        "com base exclusivamente no **assunto** e na **descrição** do ticket. "

    ),
    backstory=(
        "Você é um especialista em priorização de tickets de suporte. "

    ),
    verbose=True,
    LLM=llm
)

    def classificador_tipo(self) -> Agent:
        return Agent(
            role="Classificador de tipo de ticket",
            goal="Classificar os tickets em Solicitação, Dúvida, Incidente, Problema",
            backstory="Pesquisador dedicado com olhar atento aos detalhes",
            verbose=True,
            LLM=llm
        )

    def task_prioridade(self, assunto,descricao) -> Task:
        return Task(
            description=f'Analise o assunto: "{assunto} e a descrição: {descricao} do ticket e classifique levando em consideração as palavras-chaves."',
            expected_output="Apenas uma palavra: Baixa, Média, Alta ou Urgente",
            agent=self.classificador_prioridade()
        )

    def task_tipo(self, assunto, descricao) -> Task:
        return Task(
            description=f"Classifique a o tipo do ticket de acordo com o assunto: {assunto} e a descrição: {descricao}",
            expected_output="Apenas uma palavra: Solicitação, Dúvida, Incidente, Problema, Service Task, Acompanhamento, Pedidos , Notificação NOC , Aviso Manutenção , Análise e estudo, Comercial (Novo Projeto/Proposta) ",
            agent=self.classificador_tipo()
        )

    def crew(self) -> Crew:
        file_name = "log-crew-classificacao[1]"
        return Crew(
            agents=[self.classificador_prioridade(), self.classificador_tipo()],
            tasks=[self.task_prioridade(assunto,descricao), self.task_tipo(assunto,descricao)],
            process=Process.sequential,
            verbose=True,
            output_log_file=f"{file_name}.txt"
        )
    

CrewClassificar().crew().kickoff()

Errors I encounter:

  1. When I try the above, I get:

ImportError: Error importing native provider: OPENAI_API_KEY is required

openai.AuthenticationError: Error code: 401 - {‘error’: {‘message’: ‘Incorrect API key provided: dummy’, …}}

This error doesn’t seem to be raised by CrewAI or LiteLLM at all. I’d recommend you check its origin, as it’s likely coming from one of your many internal imports.

1 Like

(post deleted by author)

Please see this issue: [BUG] LiteLLM issues with local ollama and Anthropic · Issue #3811 · crewAIInc/crewAI · GitHub

You might find your answers. I had some problems upgrading from 0.203.1 to 1.2.x as things changed a little bit. Short answer, I believe you need to provide an api key (doesn’t matter what it is).

1 Like

I ran into a similar sounding situation using Ollama and found I needed to specify an embedder for my agent, otherwise it defaults to openai (and therefore a key is required).
This is probably only the case when your agent needs to embed some analyzed data for later use and I’m not sure if that’s your case or not.

    @agent
    def data_engineer(self) -> Agent:
        return Agent(
            config=self.agents_config["data_engineer"],
            llm=self.llm,
            max_iter=3,
            allow_delegation=False,
            verbose=verbose_setting,
            embedder={
                "provider": "ollama",
                "config": {
                    "model": "nomic-embed-text",
                    "task_type": "retrieval_document",
                    "url": "http://localhost:11434/api/embeddings",
                },
            }
        )
1 Like

to get ollama working try this:

llm=LLM(
base_url = '``http://localhost:11434/v1``',
api_key='ollama', # required, but unused,
model="..." # you might need to try openai/<model_name> but first try without the model )