Table of Contents

Namespace Mythosia.AI.Exceptions

Classes

AIHttpErrorFactory

Translates a provider's HTTP failure into the library's exception vocabulary.

Every provider words its errors differently, so detection lives here rather than in the core or in the consuming app — the app should only ever learn that the context overflowed, never how a particular vendor phrases it.

Detection is deliberately narrow. A false positive is worse than a miss: it makes the core compact the conversation (which deletes messages irreversibly) in response to an unrelated 400. When in doubt this returns a plain AIServiceException.

AIServiceException

Base exception for all AI service related errors

AgentMaxStepsExceededException

Exception thrown when a ReAct agent exceeds the maximum number of steps without producing a final answer.

AuthenticationException

Exception thrown when API authentication fails

ContentValidationException

Exception thrown when content validation fails

ContextLengthExceededException

Thrown when the provider rejects a request because the prompt exceeds the model's context window.

This is usually a recoverable condition: the core AIService catches it, compacts the conversation, and retries. When it does reach the caller, RecoverySkipReason says why recovery could not save it — no conversation policy, nothing left to compact, a tool had already run, the retry budget ran out, and so on. A null reason means recovery never got the chance — the caller invoked the raw GetCompletionAsync(Message) provider overload, which is not routed through it.

StreamAsync never throws this: there the overflow arrives as an error chunk carrying context_length_exceeded metadata, and recovery happens inside the round loop. The legacy callback API StreamCompletionAsync has no round loop and does throw it.

The context limit is owned and enforced by the server, never guessed by the client. That is the whole point of reacting to this exception rather than estimating token counts.

InvalidModelException

Exception thrown when an invalid model is specified

MultimodalNotSupportedException

Exception thrown when multimodal features are not supported by the service

RateLimitExceededException

Exception thrown when API rate limit is exceeded

ServiceUnavailableException

Exception thrown when the service is temporarily unavailable

StructuredOutputException

Exception thrown when structured output deserialization fails after all retry attempts. Contains rich diagnostic context: raw LLM responses, parse errors, attempt count, and schema.

TokenLimitExceededException

Exception thrown when token limit is exceeded