Skip to content

Fix: Improve Claude API error handling with OpenAI fallback#28

Open
swinney wants to merge 2 commits into
mainfrom
bugfix/claude-api-credit-error
Open

Fix: Improve Claude API error handling with OpenAI fallback#28
swinney wants to merge 2 commits into
mainfrom
bugfix/claude-api-credit-error

Conversation

@swinney

@swinney swinney commented Sep 5, 2025

Copy link
Copy Markdown
Member

Summary

  • Fixed Claude API insufficient credit errors by implementing automatic fallback to OpenAI
  • Enhanced error messages to provide clear guidance for users
  • Improved user experience when Claude credits are exhausted

Problem

The recent model updates exposed an issue where insufficient Claude API credits would cause all documentation generation to fail with cryptic error messages, even though OpenAI was available as an alternative provider.

Solution

  1. Better Error Detection: Modified ClaudeProvider to detect credit-related errors specifically and provide helpful error messages with links to billing page
  2. Automatic Fallback: Implemented automatic fallback to OpenAI provider when Claude credits are insufficient
  3. Clear User Feedback: Added informative messages showing when fallback occurs and which model is being used

Testing

  • ✅ Tested Claude API with insufficient credits - properly detects and reports the issue
  • ✅ Verified automatic fallback to OpenAI (gpt-4o-mini) works correctly
  • ✅ Confirmed OpenAI provider still works normally when used directly
  • ✅ Successfully generated documentation using the fallback mechanism

Example Output

⚠️  Claude API credits insufficient. Switching to OpenAI provider...
✓ Using OpenAI model: gpt-4o-mini
✓ Generated: test_documentation_openai_gpt4omini_temp07_v1.html

This ensures users can continue working even when one provider has issues.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

- Add create_file_url() and format_output_summary() utility functions
- Update all CLI output to show clickable file:// URLs for generated files
- Enhanced output format shows output directory followed by individual files
- Works with both legacy flag-based CLI and new command pattern
- Each file path is fully qualified and clickable in supported terminals

Output format:
📁 Output directory: file:///path/to/output/
   📄 Generated: file:///path/to/output/document_v1.md
   📄 Generated: file:///path/to/output/document_v2.md
   ⭐ Best compilation: file:///path/to/output/document_best.md

Updated functions:
- run_generation() - Legacy topic mode
- run_readme_generation() - Legacy README mode
- run_standardization() - Legacy standardization mode
- GenerateCommand.run() - New command pattern
- ReadmeCommand._display_results() - New command pattern
- StandardizeCommand._display_results() - New command pattern

This improves UX by making generated files easily accessible via click-to-open functionality in modern terminals.
- Enhanced error messages for insufficient Claude API credits
- Added automatic fallback to OpenAI when Claude credits are low
- Improved user feedback with clear instructions for resolving credit issues
- Tested fallback mechanism successfully switches to gpt-4o-mini
- Maintains normal operation for both providers when credits are available

This fix ensures documentation generation continues even when Claude API
credits are exhausted by automatically switching to OpenAI as a fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant