CrewAICrewAI 1.15 · Python 3.10 to 3.13
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
32 small wins to finish your pathNext lesson

Using a real model

Swapping the model you wrote for a hosted one is one argument: llm=LLM(model=...). Every agent, tool, crew and flow stays as it is.

Every lesson so far ran on ShopLLM. A hosted model takes its place through CrewAI's LLM class, which picks the provider from the prefix of the model string.

Examplereal_model.py
from crewai import LLM

llm = LLM(model="openrouter/google/gemma-4-31b-it:free")
print(llm.call("Say hello to a customer in five words."))

A hosted model writes something different every run, so read the answers it gives as one run of many rather than as the result.

The key it looks for

Example
import os

import shop_llm
from crewai import LLM

os.environ.pop("OPENROUTER_API_KEY", None)
try:
    LLM(model="openrouter/google/gemma-4-31b-it:free")
except Exception as error:
    print(type(error).__name__)
    print(error)

With no key set, the model is refused when it is created, and the message names the variable. Set OPENROUTER_API_KEY and the block above runs.

In the crew

Examplecrew.py, with a hosted model
from crewai import LLM

model = LLM(model="gemini/gemini-3.6-flash", temperature=0)
clerk.llm = model
writer.llm = model

openrouter and openai work with what crewai installs. Anthropic needs pip install "crewai[anthropic]" and Gemini needs pip install "crewai[google-genai]". Providers CrewAI has no client for, such as Groq, go through LiteLLM and need pip install "crewai[litellm]"; without it, creating the model fails with a message saying so.

A hosted model returns real token counts, so result.token_usage stops showing zeros. It also writes different text on each run: the guardrail and the tool hook hold regardless, which is why they are code and not prompt text.

Try it yourself
  • Run the first block with a key and compare two answers.
  • Give the writer a hosted model and keep ShopLLM for the clerk.
  • Print result.token_usage after a run with a hosted model.

You understood something today that you didn't yesterday.