Skip to content

Conversation

@crystalin
Copy link
Contributor

Summary

Adds multi-provider support to the proxy, enabling users to access Claude models through either Anthropic's direct API or AWS Bedrock. Projects can now configure credentials for either provider, and the proxy automatically routes requests based on the credential type.

Key Changes

Database Schema

  • Renamed anthropic_credentialscredentials table
  • Added provider enum column ('anthropic' | 'bedrock')
  • Added AWS-specific columns: aws_api_key, aws_region
  • Made OAuth columns nullable (only required for Anthropic)
  • Added constraints ensuring provider-specific fields are populated correctly

Type System

  • Created discriminated union types for credentials
  • Credential = AnthropicCredential | BedrockCredential
  • Separate safe types that exclude sensitive data
  • Provider-specific request types for type safety

Proxy Implementation

  • BedrockApiClient: New client handling Bedrock-specific requests
    • Automatic model ID mapping (Anthropic → Bedrock format)
    • Injects anthropic_version: 'bedrock-2023-05-31'
    • Supports streaming and non-streaming
  • AuthenticationService: Extended to handle both OAuth and API key authentication
  • ProxyService: Routes to appropriate client based on credential provider

Model Mapping

  • Comprehensive mapping of Anthropic model IDs to Bedrock equivalents
  • Covers Claude 3, 3.5, 4, and Opus variants
  • Allows pass-through of Bedrock-specific model IDs

Dashboard UI

  • Provider badges: 🔵 Anthropic (blue) / 🟠 Bedrock (orange)
  • Provider-specific details (OAuth expiry vs AWS region)
  • Updated instructions showing both login scripts

Scripts

  • bedrock-login.ts: Interactive CLI for adding Bedrock credentials
    • Prompts for account ID, name, API key, and region
    • Links to AWS console for API key generation
  • Updated oauth-login.ts to use new function names

Migration

  • 017-multi-provider-support.ts: Idempotent schema migration
  • Includes up and down migrations for rollback support
  • Preserves existing Anthropic credentials

Testing

  • TypeScript compilation passes
  • All lint checks pass
  • Manual testing with Bedrock credentials (requires AWS account)
  • Manual testing with Anthropic credentials (existing functionality)

Usage

Adding Bedrock Credentials

bun run scripts/auth/bedrock-login.ts

Adding Anthropic Credentials

bun run scripts/auth/oauth-login.ts

Running Migration

bun run scripts/db/migrations/017-multi-provider-support.ts

Breaking Changes

None. Existing Anthropic credentials are automatically migrated and continue to work.

🤖 Generated with Claude Code

crystalin and others added 13 commits November 5, 2025 11:08
Added multi-provider support to allow using both Anthropic's direct API
and AWS Bedrock for accessing Claude models.

**Database Changes:**
- Renamed `anthropic_credentials` table to `credentials`
- Added `provider` column ('anthropic' | 'bedrock')
- Added AWS Bedrock columns: `aws_api_key`, `aws_region`
- Made OAuth columns nullable (only needed for Anthropic)
- Added validation constraints for provider-specific fields

**Type System:**
- Created discriminated union types for credentials
- `Credential` = `AnthropicCredential | BedrockCredential`
- Separate safe types that exclude sensitive data
- Provider-specific create request types

**Proxy Service:**
- Created `BedrockApiClient` with model ID mapping
- Updated `AuthenticationService` to handle both providers
- Modified `ProxyService` to route based on provider type
- Bedrock requests include `anthropic_version: 'bedrock-2023-05-31'`

**Model Mapping:**
- Maps Anthropic model IDs to Bedrock model IDs
- Supports both streaming and non-streaming requests
- Allows pass-through of Bedrock-specific model IDs

**Dashboard UI:**
- Updated credentials page with provider badges (🔵 Anthropic / 🟠 Bedrock)
- Provider-specific details display (OAuth expiry vs AWS region)
- Instructions for both login scripts

**Scripts:**
- `bedrock-login.ts`: Interactive CLI for adding Bedrock credentials
- Updated `oauth-login.ts` to use new function names

**Migration:**
- `017-multi-provider-support.ts`: Idempotent schema migration
- Supports rollback with `down` migration

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

Co-Authored-By: Claude <[email protected]>
- Add Claude Haiku 4.5 (October 2025 release)
- Add Claude Opus 4.1 (August 2025 release)
- Add core model ID mappings (claude-haiku-4-5, claude-sonnet-4-5, claude-opus-4-1)
- Add dated snapshot mappings for precise version control
- Update timestamp comment to November 2025

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

Co-Authored-By: Claude <[email protected]>
- Remove deprecated createCredential function (not used anywhere)
- Remove CreateCredentialRequest type (no longer needed)
- Use createAnthropicCredential and createBedrockCredential directly
- Clean up imports in credential-queries.ts

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

Co-Authored-By: Claude <[email protected]>
- Add ADR-030: Multi-Provider Support for Claude API Access
- Update scripts/README.md with bedrock-login.ts documentation
- Update IMPLEMENTATION_GUIDE.md to use createAnthropicCredential
- Document Bedrock provider setup and prerequisites
- Reference multi-provider architecture and model mapping

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

Co-Authored-By: Claude <[email protected]>
- Show first 3 and last 4 chars for Bearer tokens (e.g., "Bearer cnp...kZwU")
- Show first 10 and last 4 chars for API keys (e.g., "sk-ant-api...AbCd")
- Show first 3 and last 4 chars for other sensitive values
- Better debugging while maintaining security

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

Co-Authored-By: Claude <[email protected]>
- Log API key verification results with token preview
- Log project ID context setting in client auth
- Log project ID extractor decision making
- Show whether projectId was set by auth or header
- Help diagnose why fallback is being used

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

Co-Authored-By: Claude <[email protected]>
- AWS Bedrock long-term API keys require Authorization header
- Add detailed error logging for Bedrock API responses
- Log URL, status, error body, and response headers
- Helps diagnose authentication and API issues

Fixes 403 "Authorization header is missing" error

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

Co-Authored-By: Claude <[email protected]>
- Use x-api-key header for Bedrock authentication (not Authorization)
- Build Bedrock-specific headers directly instead of using createHeaders()
- Prevents client's Authorization header from being forwarded to Bedrock
- Add detailed request logging for debugging

Fixes: 403 "Authorization header must begin with algorithm name" error

The issue was that the client's Authorization header (Bearer token for proxy)
was being forwarded to Bedrock, which interpreted it as a malformed SigV4
signature. Bedrock requires only the x-api-key header.

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

Co-Authored-By: Claude <[email protected]>
- Blacklist only: authorization, host, content-length
- Pass through all other headers (anthropic-beta, user-agent, etc.)
- Preserves important client headers while removing proxy-specific ones
- More maintainable than whitelist approach

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

Co-Authored-By: Claude <[email protected]>
Extract raw request headers from Hono context and pass them to
BedrockApiClient. Headers are filtered through a blacklist (removes
authorization, host, content-length, connection) to prevent conflicts
while preserving important headers like anthropic-beta, user-agent,
and x-stainless-*.

This ensures Bedrock requests include all necessary client headers
for proper API functionality.

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

Co-Authored-By: Claude <[email protected]>
Bedrock API does not accept 'stream' or 'model' fields in the request body:
- Model ID is specified in the URL path
- Streaming mode is determined by endpoint suffix (/invoke vs /invoke-with-response-stream)

Also removed excessive debug logging from:
- client-auth.ts: Removed API key verification debug logs
- project-id-extractor.ts: Removed project ID checking debug logs
- BedrockApiClient.ts: Removed request details debug log

Updated ADR-030 to document this Bedrock API requirement.

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

Co-Authored-By: Claude <[email protected]>
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