Skip to content

Conversation

johnib
Copy link

@johnib johnib commented Sep 20, 2025

Summary

Adds configurable API timeout functionality to prevent legitimate long-running operations from failing due to hardcoded timeouts.

Fixes #97

Changes

  • New CLI option: --timeout (alias -t) to set API timeout in milliseconds
  • Higher default: Increased from ~30s to 120000ms (2 minutes) for better reliability
  • AbortController implementation: Proper timeout handling across all API calls
  • Comprehensive coverage: Applies to both chat completions and GitHub token polling
  • Documentation: Updated README with usage examples and tips

Usage Examples

# Use default 2-minute timeout
npx copilot-api start

# Set 3-minute timeout for complex operations
npx copilot-api start --timeout 180000

# Short alias also works
npx copilot-api start -t 300000

Technical Implementation

  • Implements AbortController with setTimeout for clean cancellation
  • Graceful error handling for timeout scenarios
  • Backward compatible with existing functionality
  • Added timeout parameter to state management
  • Proper cleanup with finally blocks

Benefits

  • ✅ Prevents legitimate long-running operations from failing
  • ✅ Maintains protection against truly hung requests
  • ✅ Particularly improves Claude Code experience with complex tasks
  • ✅ User-configurable based on specific use cases
  • ✅ Better out-of-the-box reliability with higher default

Testing

  • ✅ Passes all existing tests
  • ✅ Lint and typecheck validation
  • ✅ Timeout functionality verified in development

This resolves timeout issues that users experience with complex prompts, large context windows, and multi-step reasoning operations that regularly exceed the previous timeout limits.

- Add --timeout CLI flag to configure API timeout in milliseconds
- Increase default timeout from 30s to 120s (2 minutes) for better reliability
- Implement AbortController with configurable timeout for all API calls:
  - GitHub Copilot API calls (chat, embeddings, models, token, usage)
  - GitHub API calls (user, device code, OAuth polling)
- Add proper timeout handling and cleanup in all service functions
- Update documentation with new timeout option and usage examples

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@johnib johnib closed this Oct 3, 2025
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.

Feature Request: Configurable API Timeout
1 participant