Frameworks

CrewAI cost tracking and budget limits: see and cap what each crew spends

Point CrewAI agents at an OpenAI-compatible LLM gateway to track spend per crew, use any model (Claude, Gemini, GPT, Bedrock), and stop a runaway crew with a budget enforced before each call.

CrewAI agents delegate to each other and retry tool use until they are satisfied, so the cost of one kickoff() is hard to predict in advance. Routing a crew through the gateway gives you its real cost per run and a hard stop.

Setup

from crewai import Agent, Crew, Task, LLM
 
llm = LLM(
    model="openai/claude-sonnet-4-6",            # "openai/" = OpenAI-compatible client
    base_url="https://api.cognocient.com/v1",
    api_key="sk-cog-RESEARCH-CREW-KEY",
)
 
researcher = Agent(role="Researcher", goal="Find pricing for three vendors",
                   backstory="Careful analyst", llm=llm, max_iter=10)
task = Task(description="Compare vendor pricing", expected_output="A table", agent=researcher)
 
Crew(agents=[researcher], tasks=[task]).kickoff()

Use different models per agent by giving each its own LLM (for example a cheap model for the researcher and a stronger one for the reviewer). Any gateway model name works after openai/: openai/gpt-4o-mini, openai/gemini-2.5-flash, openai/amazon.nova-pro-v1:0.

Attribute spend by proxy key

CrewAI builds requests for you, so the simplest reliable way to attribute spend is one proxy key per crew (or per crew and environment). Free accounts have one proxy key; paid plans can create more in Settings → Proxy Keys, every call is tagged with the key that made it, and Live Calls and the API call log filter by key.

Need per-run or per-user tags?

X-Cost-* headers need a client that lets you set request headers, which CrewAI's LLM class doesn't document consistently across versions. Tagging by key works on every version. If you need per-run or per-user cost, make those model calls from a custom tool built on the OpenAI SDK with default_headers, or run that part of the workflow in a framework that exposes headers, such as LangGraph.

Cap a crew

  • Budget per key (Growth and above): Budgets → New Budget → Scope: Key. On Free and Base, a Global budget caps the whole account instead. When the crew's key has spent its limit, calls are blocked, degraded to a cheaper model, or alerted on.
  • Velocity circuit breaker: on by default per key; trips at 10× the key's own rolling token-rate baseline within a 60-second window. Set a manual tokens-per-minute cap in Settings → Proxy Keys → Velocity Limit.
  • Emergency Freeze: stops every proxied call in the account at once, from the dashboard or automatically.

max_iter limits steps per agent; a budget limits dollars, which is what the bill measures.

On this page