CometAPI’s CrewAI integration guide includes a small but consequential boundary: inspect the underlying API exception before deciding whether model fallback is appropriate. For a CrewAI application configured with CometAPI’s https://api.cometapi.com/v1 base URL, a generic outer exception is not enough information to switch models.
The guide uses OpenAI SDK exception classes in its classifier. Treat that as an integration prerequisite to verify against your pinned CrewAI and adapter versions—not proof that every failure arriving through CometAPI will retain those classes.
What the tutorial’s classifier actually decides
The guide’s exception_chain keeps a set of visited object IDs. It yields the current exception, then follows __cause__ or __context__, stopping when there is no next exception or an object repeats. That prevents a cyclic chain from looping indefinitely. It does not impose a depth budget on a long acyclic chain, and it does not search both cause and context branches.
Its should_fallback function then:
- Returns true for an
APIConnectionErrororAPITimeoutError. - Returns the status check immediately for an
APIStatusError: 408, 429, or any status at least 500 qualifies. - Returns false if the chosen chain contains no recognized API exception.
The immediate return matters. A recognized 401 encountered before a deeper 503 produces false; this is not “find any transient-looking error anywhere.” Nor does a message containing “429” qualify by itself.
A small fixture matrix before using this with CometAPI
These are proposed checks derived from the tutorial code, not executed test results. Build a fixed, small set of synthetic exceptions locally, using constructors appropriate to your pinned SDK. No CometAPI key or network request is needed to test this classification logic.
| Synthetic chain | Expected result from the guide’s code |
|---|---|
| Generic wrapper whose cause is a recognized 429 status error | True |
| Generic wrapper whose only context is a recognized timeout error | True |
| Recognized 401 status error with a deeper 503 cause | False: the first recognized status decides |
| Generic wrapper with a 401 cause and a separate timeout context | False: the selected cause path wins |
| Two generic exceptions whose causes point back to each other | False after visiting each once |
| Generic exception with only the message “429” | False |
For the cycle fixture, also inspect the yielded identities: there should be two, not an indefinitely repeated sequence. If your application needs a hard traversal budget, add and test a separate depth limit; that would be your extension, not a feature demonstrated by this tutorial.
Keep classification separate from replay
CometAPI’s guide distinguishes an invalid key or request from transient transport/API failures and from agent or tool failures. Preserve that distinction when wiring this helper into the integration. An unknown exception should remain unclassified rather than become permission for a catch-all model switch.
Even a true result is only a candidate for the guide’s bounded fallback policy. The replacement model must support the same request contract, and replaying completed external side effects is a separate safety question. This classifier answers which recognized error was found along one wrapper chain—not whether rerunning the crew is safe or switching models will fix it.