CrewAI Integration with The Grid | Agent LLM Setup
Connect CrewAI to The Grid with the LLM class. Use the OpenAI-compatible endpoint, assign Grid models to agents, and tier by role.
CrewAI is a Python framework for orchestrating multi-agent systems. The Grid plugs in through CrewAI's LLM class as a standard OpenAI-compatible provider. No custom provider code: build an LLM pointed at The Grid, pass it to each Agent, and every step, tool call, and delegation runs on market-priced inference.
Prerequisites
CrewAI installed with the LiteLLM extra:
uv add "crewai[litellm]"(orpip install "crewai[litellm]"). The[litellm]extra is required; plaincrewaifails to initializemodel="openai/<instrument>".A Grid account at app.thegrid.ai.
Credits in your account. The Grid is prepaid.
A Grid consumption API key from Settings → API Keys → Create Consumption Key.
Setup
1. Add the key to your environment
Put it in a .env at your project root:
THEGRID_API_KEY=your-consumption-key-hereA @CrewBase-decorated project auto-loads .env via python-dotenv. For plain scripts, add from dotenv import load_dotenv; load_dotenv() at the top.
2. Build an LLM instance pointed at The Grid
In your crew module:
import os
from crewai import LLM
grid_llm = LLM(
model="openai/agent-prime",
base_url="https://api.thegrid.ai/v1",
api_key=os.getenv("THEGRID_API_KEY"),
)The openai/ prefix tells CrewAI to use the OpenAI-compatible transport. The model name after the slash is a Grid instrument from the current instruments list.
3. Pass the LLM to your agents
For YAML-driven crews, keep config/agents.yaml exactly as the CrewAI CLI generates it. Inject the LLM from Python in crew.py:
4. (Optional) Tier instruments by agent role
Build one LLM instance per tier and route by cognitive load. Put the manager on Agent Max, daily workers on Agent Prime, prose synthesis on Text Prime, classification and extraction on Text Standard:
You can also split function-calling: Agent(llm=grid_writer, function_calling_llm=grid_utility) keeps reasoning expensive and tool-argument shaping cheap.
5. Run the crew
Verification
Drop this into a file and run it:
If you see OK, auth and routing are good.
Troubleshooting
Last updated
Was this helpful?