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.

Checked 2026-11-21

·All guides·Models

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

python
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:

AgentModel idPrice per 1M (in / out)
Researcher, summariserdeepseek-v4.1-flash$0.0564 / $0.1692
Analystgpt-6.1-sol$0.582 / $2.91
Final writer, reviewerclaude-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-sol and claude-sonnet-5-5 are safe starts.
  • Runaway crews: set a spend limit on the key the crew uses. At the limit, requests stop instead of billing on.

Questions and answers

Yes. Use openai/claude-sonnet-5-5 with the same base URL. The OpenAI-format request reaches Claude at the same price as the Anthropic format.

CrewAI routes models through LiteLLM-style provider prefixes, and openai/ means "an OpenAI-compatible endpoint at this base URL". Without it, CrewAI may try to guess the provider from the model name.

Sum each agent's tokens times its model's price. The usage page breaks spend down per request, so run the crew once and read the total before scheduling it.
Join on Telegram
Help