Skip to content

AttributeError when LiteLLM encounters API errors #98

@couragec

Description

@couragec

Bug: AttributeError - 'Exception' object has no attribute 'request'

Error

'Exception' object has no attribute 'request'

Environment

  • LiteLLM + CrewAI + OpenRouter API
  • Python 3.12
  • Model: qwen/qwen3-8b

Problem

When OpenRouter API returns an error, LiteLLM's exception mapper tries to access exception.request attribute, but not all exception types have this attribute.

Root Cause

File: litellm/litellm_core_utils/exception_mapping_utils.py (lines 1444, 1519, 1578, etc.)

raise BadRequestError(
    ...
    request=original_exception.request,  # ❌ Assumes .request exists
)

Impact

  • Tool calls fail repeatedly
  • Agent gets stuck in infinite loop
  • Tasks never complete
  • No retry mechanism triggered

Suggested Fix

Use safe attribute access:

request=getattr(original_exception, 'request', None),  # ✅ Safe

Reproduce

  1. Run agent with OpenRouter API
  2. Wait for intermittent API error
  3. Observe AttributeError in logs

Logs

2025-10-17 08:10:28 - stratus.tools.kubectl.nl2kubectl - ERROR - NL2Kubectl Tool failed with: 'Exception' object has no attribute 'request'

Error repeats every 2-5 minutes, agent never exits.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions