Skip to content

Conversation

@elhayef
Copy link

@elhayef elhayef commented Sep 14, 2025

Overview

This PR introduces comprehensive multi-provider support for Claude Code, enabling users to access Claude models through multiple cloud providers while maintaining full backward compatibility.

✨ Features Added

🔧 Multi-Provider Architecture

  • Direct Anthropic API (default) - Original implementation
  • AWS Bedrock - Access Claude through AWS Bedrock service
  • Google Vertex AI - Access Claude through Google Cloud Vertex AI

🏗️ Clean Architecture

  • Abstract base class (ClaudeClientBase) defining common interface
  • Factory pattern (ClaudeClientFactory) for automatic provider selection
  • Provider-specific implementations with unified error handling
  • Robust environment validation and configuration management

🔄 Backward Compatibility

  • Existing code continues to work without changes
  • Original ClaudeAPIClient refactored but API-compatible
  • Same configuration options and method signatures

📁 Files Added/Modified

Core Architecture

  • claudecode/claude_client_base.py - Abstract base class for all providers
  • claudecode/claude_client_factory.py - Factory for provider selection
  • claudecode/claude_api_client.py - Refactored to inherit from base class
  • claudecode/claude_bedrock_client.py - AWS Bedrock implementation
  • claudecode/claude_vertex_client.py - Google Vertex AI implementation
  • claudecode/env_validation.py - Environment validation utilities

Documentation & Examples

  • docs/multi-provider-setup.md - Comprehensive setup guide
  • examples/multi-provider-example.py - Working example demonstrating all providers

Dependencies

  • claudecode/requirements.txt - Added boto3 for Bedrock, anthropic[vertex] for Vertex AI

Testing Suite

  • test_multi_provider.py - Unit tests for all components
  • test_integration_multi_provider.py - Integration tests with real providers
  • test_providers_manually.py - Manual testing script for quick validation
  • test_provider_performance.py - Performance testing and benchmarking

🛠️ Configuration

Anthropic API (Default)

export ANTHROPIC_API_KEY="your-api-key"

AWS Bedrock

export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION="us-east-1"
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"

Google Vertex AI

export CLAUDE_CODE_USE_VERTEX=1
export ANTHROPIC_VERTEX_PROJECT_ID="your-project-id"
export CLOUD_ML_REGION="us-central1"

🧪 Testing

Unit Tests

python -m pytest test_multi_provider.py -v

Integration Tests (requires credentials)

python -m pytest test_integration_multi_provider.py -v

Manual Testing

python test_providers_manually.py
python examples/multi-provider-example.py

💡 Usage Examples

Automatic Provider Selection (recommended)

from claudecode.claude_client_factory import create_claude_client

# Automatically selects provider based on environment variables
client = create_claude_client()
success, result, error = client.analyze_single_finding(finding)

Direct Provider Usage

from claudecode.claude_bedrock_client import ClaudeBedrockClient

client = ClaudeBedrockClient()
success, result, error = client.analyze_single_finding(finding)

🔄 Migration Guide

No changes required - existing code continues to work. To use new providers:

  1. Set appropriate environment variables (see Configuration section)
  2. Install optional dependencies: pip install boto3 for Bedrock or pip install 'anthropic[vertex]' for Vertex AI
  3. Code automatically uses the configured provider

🎯 Benefits

  • Cost Optimization - Choose providers based on pricing and quotas
  • Regional Availability - Access Claude through different regions
  • Redundancy - Fallback options if one provider has issues
  • Enterprise Integration - Use existing cloud provider relationships
  • Compliance - Meet data residency requirements

🧪 Test Coverage

  • ✅ Environment validation for all providers
  • ✅ Provider type detection
  • ✅ Client factory functionality
  • ✅ Base client interface compliance
  • ✅ Error handling and retry logic
  • ✅ Performance benchmarking
  • ✅ Integration testing with real APIs

🔍 Technical Details

Provider-Specific Features:

  • Model Mapping - Automatically maps between generic model names and provider-specific identifiers
  • Error Handling - Provider-specific error detection and retry logic
  • Rate Limiting - Progressive backoff with provider-specific keywords
  • Authentication - Handles different authentication mechanisms per provider

Quality Assurance:

  • Comprehensive test suite with 100+ test cases
  • Manual testing scripts for easy validation
  • Performance benchmarking tools
  • Full backward compatibility testing

📈 Performance Impact

  • Zero overhead when using default Anthropic API
  • Minimal overhead for provider selection (environment variable check)
  • Same API response times - provider selection doesn't affect Claude performance

🚨 Breaking Changes

None - This is a fully backward-compatible change.

Signed-off-by: Efrat Elhay <[email protected]>
@elhayef elhayef changed the title support vertex and bedrock Add Multi-Provider Support for Claude Code Security Reviews Sep 14, 2025
@elhayef
Copy link
Author

elhayef commented Sep 15, 2025

@peterlai-ant @peter-anthropic can you please reivew ?

@Nikhil-1102
Copy link

@peterlai-ant @peter-anthropic Please review we are kind of blocked on this

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.

2 participants