Add `ContextWindowExceeded` exception for context window errors

Closed
DS
2mo ago
+111802-17

Summary

  • Adds ContextWindowExceeded exception to detect when providers return context window/token limit exceeded errors
  • Implemented detection for: OpenAI, Anthropic, Google, Groq, Bedrock, Mistral, Cohere
  • Exception provides status_code, model_name, and raw body for debugging

Test plan

  • VCR tests for all providers that raise ContextWindowExceeded
  • Google test skips when credentials unavailable
  • All existing model tests still pass
  • make typecheck passes

Closes #4060

šŸ¤– Generated with Claude Code

  • Review AI generated code