CrewAI with an OpenAI-compatible API: setup
Run CrewAI agents on Claude, GPT, Gemini or open models through one key: the LLM class settings, a model per agent to control cost, and the version gotchas.
CrewAI connects to UplinkSwitch through its LLM class: LLM(model="openai/gpt-6.1-sol", base_url="https://api.uplinkswitch.com/v1", api_key=...). The openai/ prefix tells CrewAI to send the request to the OpenAI-compatible path at your base URL.
Set up one LLM
import os
from crewai import Agent, LLM
llm = LLM(
model="openai/gpt-6.1-sol",
base_url="https://api.uplinkswitch.com/v1",
api_key=os.environ["UPLINKSWITCH_API_KEY"],
temperature=0.3,
)
researcher = Agent(role="Researcher", goal="Find the facts", backstory="…", llm=llm)Give each agent the model it needs
Crews spend most of their tokens on the busy agents. Put the cheap, fast model on the agents that gather and summarise, and the strong one on the agent that writes or decides:
| Agent | Model id | Price per 1M (in / out) |
|---|---|---|
| Researcher, summariser | deepseek-v4.1-flash | $0.0564 / $0.1692 |
| Analyst | gpt-6.1-sol | $0.582 / $2.91 |
| Final writer, reviewer | claude-sonnet-5-5 | $1.164 / $2.91 |
Each is a separate LLM(...) with the same base URL and key; only model changes.
Environment variables instead of code
When no llm is passed, CrewAI reads OpenAI-style variables: set OPENAI_BASE_URL (or OPENAI_API_BASE) and OPENAI_API_KEY, and pass the model id explicitly. Set both base variables to https://api.uplinkswitch.com/v1 if you aren't sure.
Gotchas
- Model not found: keep the
openai/prefix and use the exact catalog id after it. - Tool-using agents: pick models whose catalog entry lists tools;
gpt-6.1-solandclaude-sonnet-5-5are safe starts. - Runaway crews: set a spend limit on the key the crew uses. At the limit, requests stop instead of billing on.