Exceptions¶
bruno_llm.exceptions
¶
Exception hierarchy for bruno-llm.
Defines custom exceptions for LLM provider errors, enabling consistent error handling across all providers.
LLMError
¶
Bases: Exception
Base exception for all LLM-related errors.
All custom exceptions in bruno-llm inherit from this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message |
required |
provider
|
Optional[str]
|
Name of the provider that raised the error |
None
|
original_error
|
Optional[Exception]
|
Original exception if available |
None
|
Source code in bruno_llm/exceptions.py
format_message()
¶
Format the error message with provider context.
Source code in bruno_llm/exceptions.py
AuthenticationError
¶
Bases: LLMError
Raised when authentication with LLM provider fails.
Common causes: - Invalid API key - Expired API key - Missing API key - Invalid organization ID
Example
raise AuthenticationError("Invalid API key", provider="openai")
Source code in bruno_llm/exceptions.py
RateLimitError
¶
Bases: LLMError
Raised when API rate limits are exceeded.
Attributes:
| Name | Type | Description |
|---|---|---|
retry_after |
Seconds to wait before retrying (if provided) |
Example
raise RateLimitError("Rate limit exceeded", provider="openai", retry_after=60)
Source code in bruno_llm/exceptions.py
ModelNotFoundError
¶
Bases: LLMError
Raised when requested model is not found or not available.
Common causes: - Model name misspelled - Model not available in region - Model access not granted - Model has been deprecated
Example
raise ModelNotFoundError("Model 'gpt-5' not found", provider="openai")
Source code in bruno_llm/exceptions.py
ContextLengthExceededError
¶
Bases: LLMError
Raised when input exceeds model's context length.
Attributes:
| Name | Type | Description |
|---|---|---|
max_tokens |
Maximum tokens allowed |
|
actual_tokens |
Actual token count in request |
Example
raise ContextLengthExceededError( ... "Context length exceeded", ... provider="openai", ... max_tokens=8192, ... actual_tokens=10000 ... )
Source code in bruno_llm/exceptions.py
StreamError
¶
Bases: LLMError
Raised when streaming response encounters an error.
Common causes: - Network connection lost - Server-side error during streaming - Invalid chunk format - Stream interrupted
Example
raise StreamError("Stream connection lost", provider="openai")
Source code in bruno_llm/exceptions.py
ConfigurationError
¶
Bases: LLMError
Raised when provider configuration is invalid.
Common causes: - Missing required configuration - Invalid configuration values - Conflicting configuration options
Example
raise ConfigurationError("Missing base_url", provider="ollama")
Source code in bruno_llm/exceptions.py
TimeoutError
¶
Bases: LLMError
Raised when request times out.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout |
Timeout value in seconds |
Example
raise TimeoutError("Request timed out after 30s", provider="openai", timeout=30)
Source code in bruno_llm/exceptions.py
InvalidResponseError
¶
Bases: LLMError
Raised when provider returns invalid or unexpected response.
Common causes: - Malformed JSON response - Missing required fields - Unexpected response structure
Example
raise InvalidResponseError("Missing 'content' field", provider="openai")