For the complete documentation index, see llms.txt. This page is also available as Markdown.

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]" (or pip install "crewai[litellm]"). The [litellm] extra is required; plain crewai fails to initialize model="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-here

A @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

Error asking for crewai[litellm]. Reinstall with the extra: uv add "crewai[litellm]".

Mixing The Grid with other providers in one run. Build separate LLM instances per provider in Python and inject them per agent. The bare-string YAML pattern (llm: openai/agent-prime) reads OPENAI_API_KEY and OPENAI_BASE_URL globally, which forces every openai/* model in the process to route to The Grid.

Last updated

Was this helpful?