Why typed exceptions?
LLM providers format errors differently (status codes, messages, exception classes). The SDK maps those into stable types so client apps don’t depend on provider‑specific details. Typical benefits:- One code path to handle auth, rate limits, timeouts, service issues, and bad requests
- Clear behavior when conversation history exceeds the context window
- Backward compatibility when you switch providers or SDK versions
Quick start: Using agents and conversations
Agent-driven conversations are the common entry point. Exceptions from the underlying LLM calls bubble up fromconversation.run() and conversation.send_message(...) when a condenser is not configured.
Avoiding context‑window errors with a condenser
If a condenser is configured, the SDK emits a condensation request event instead of raisingLLMContextWindowExceedError. The agent will summarize older history and continue.
Handling errors with direct LLM calls
The same exceptions are raised from bothLLM.completion() and LLM.responses() paths, so you can share handlers.
Example: Using .completion()
Example: Using .responses()
Rate Limits, Quota, and Budget Denials
LLMRateLimitError can represent a temporary rate limit or an exhausted allowance.
Use is_quota_exhaustion_error() to distinguish them instead of parsing the
error message in your application:
insufficient_quota and usage_limit_reached, skip retries and
can use a configured fallback model. Explicit budget_exceeded denials stop
both retries and fallback. A fallback model still uses its own retry policy for
temporary failures.
Profile pre-flight validation follows the same distinction: an exhausted quota
or budget returns valid: false, while a temporary 429 returns valid: true.
Structured provider
code and type fields are recognized even when the
human-readable message omits the machine code. This handling is part of the
unreleased structured quota fix.
Earlier releases can treat these responses as temporary rate limits.Exception reference
All exceptions live underopenhands.sdk.llm.exceptions unless noted.

