Route a CrewAI Agent Through Your Own OpenAI-Compatible Gateway
Intermediate · 30 minutes · 5 tasks, checked automatically · 100 points
Learn how to decouple your CrewAI agent from a hard-coded model by pointing it at an OpenAI-compatible gateway such as LiteLLM or OpenRouter. You will install CrewAI, build a minimal but real crew, configure it to read the base URL and model name from environment variables, and prove that swapping models requires zero code changes. Because the agent runs against a real frontier model on your own API key, you will also observe genuine multi-step reasoning in the tool-call trace.
What you’ll learn
- Install CrewAI inside the toolbox container and verify the CLI is available
- Write a crew script that reads OPENAI_BASE_URL and CREW_MODEL from the environment so the model can be changed without editing code
- Run the crew against the default gpt-4o endpoint and confirm it produces a saved output file
- Switch to a second model string by changing only an environment variable and re-run the crew, proving the zero-code-change contract
- Validate the gateway routing by inspecting the output file and confirming the correct model name appears in the run log
How this lab works
- Start the lab: One click starts a sandbox with a local model and the agent’s toolbox: no API key and no token bill.
- Work through 5 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work inspects the agent, its config and its output, and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: Locally, against a model on your computer: no API key, no tokens
- Model: gpt-4o
- Open source: github.com/crewAIInc/crewAI
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- An OpenAI-compatible gateway account (OpenAI, OpenRouter, or a self-hosted LiteLLM proxy) with your key already set as OPENAI_API_KEY in the playground
Topics: crewai, deployment, gateway, litellm, openrouter, openai-compatible, environment-variables, model-routing
Create a free account to start this lab.
Keep going
- Serve MCP over Streamable HTTP and Connect a Remote Client
- Persistent OpenClaw: docker-compose with Surviving Volumes
- Run the Hermes Gateway as a Persistent Service with Request Logging and Clean Shutdown
- Dual-Surface Agent Control: CLI and Web Gateway with Hermes
- Schedule a LangGraph Morning Briefing Agent
- Build and Invoke a Custom OpenClaw Shell-Out Skill