How should CrewAI handle LLM API quotas, retries, and provider failover?

I’m developing an AI API gateway for multi-agent applications built with CrewAI.

The gateway would provide a common OpenAI-compatible interface and handle model routing, customer-level limits, token usage tracking, retries, and fallback policies.

Multi-agent workloads raise several questions:

  • Should quotas be applied per user, crew, task, or agent?
  • How should tool-call retries affect usage accounting?
  • How can a failed model call be retried without duplicating side effects?
  • When should the gateway switch providers?
  • Which metadata is useful when debugging a failed crew execution?

I would appreciate practical feedback from developers running CrewAI systems beyond local experiments.

Disclosure: I’m building the gateway discussed here and am interested in architecture feedback.

On “How can a failed model call be retried without duplicating side effects?”, I’d separate the two things your gateway is retrying.

A failed model call is usually safe to retry on its own, as long as the tools it asked for haven’t run yet. The danger is a retry of the whole step or run, because that re-enters tools that already ran. In a Python test of mine (not with CrewAI), with a real process kill after a tool had finished, replaying the run made 2 effects, and a record written before the tool made 1.

The record needs care in two places:

  • Commit it on its own, before the tool runs. In my test, with the row inside the same transaction as the step, a kill rolled it back and I got 2 effects in 10 of 10 runs. Committed on its own, I got 1.
  • Add a third state. If the process dies during a tool call, nobody knows if it landed. That has to stay “unknown” instead of “failed”, or the retry comes back.

For accounting, I’d charge per attempt and keep a stable logical call id across attempts, so one action retried three times shows up as one action with three attempts.

I maintain Call4Agents, a small open-source Python library on this problem. Your gateway doesn’t need it, but its crash test (call4agents crashtest your_agent.py) can show what a Python agent repeats after a crash. It’s experimental and the actions really run, so use test accounts.