Skip to content

feat: Add custom model support with AWS credentials #2538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

maddinenisri
Copy link

Summary

This PR adds support for custom models that bypass Builder ID authentication and use AWS credentials directly, enabling enterprise users to leverage Amazon Q CLI with their existing AWS authentication infrastructure.

Motivation

Enterprise users need to use Amazon Q CLI with:

  • AWS-native authentication (IAM roles, IRSA, ECS task roles)
  • Custom model endpoints
  • Region-specific deployments
  • No dependency on Builder ID

Changes

Core Features

  • Custom model format: custom:<region>:<model-id>
  • Authentication bypass: Skip Builder ID for custom models
  • AWS credentials chain: Support for ENV, Profile, IRSA, ECS, EC2
  • Model mapping: Automatic conversion between Bedrock and Q Developer model IDs
  • Clear UI feedback: Display custom model information in chat interface

Technical Implementation

  1. Added parse_custom_model() function to extract region and model ID
  2. Created CustomModelHandler for managing custom model logic
  3. Modified authentication flow to bypass Builder ID when using custom models
  4. Enhanced chat session to display custom model information
  5. Automatic region configuration from model format

Usage Examples

Bedrock-style model ID:

q chat --model "custom:us-east-1:us.anthropic.claude-3-5-sonnet-20241022-v2:0" "Your prompt"

Q Developer model ID:

q chat --model "custom:us-east-1:CLAUDE_3_7_SONNET_20250219_V1_0" "Your prompt"

Set as default:

q settings chat.defaultModel "custom:us-east-1:CLAUDE_3_7_SONNET_20250219_V1_0"

Testing

✅ Tested with both Bedrock and Q Developer model ID formats
✅ Verified AWS credentials chain authentication
✅ Confirmed region extraction and configuration
✅ Validated model ID mapping
✅ Tested interactive and non-interactive modes

Files Changed

  • crates/chat-cli/src/api_client/custom_model.rs - New custom model handler
  • crates/chat-cli/src/api_client/mod.rs - API client modifications
  • crates/chat-cli/src/cli/chat/cli/model.rs - Model parsing and mapping
  • crates/chat-cli/src/cli/chat/mod.rs - Chat session enhancements
  • crates/chat-cli/src/cli/mod.rs - Authentication bypass logic
  • docs/CUSTOM_MODELS.md - Comprehensive documentation

Benefits

  1. Enterprise Ready: Works with all AWS credential sources
  2. No Builder ID Required: Direct AWS authentication
  3. Flexible: Supports multiple model ID formats
  4. Region Control: Specify exact AWS region for data residency
  5. Minimal Changes: Reuses existing Q CLI infrastructure

Backward Compatibility

✅ All existing functionality preserved
✅ Standard models continue to work as before
✅ Builder ID authentication still used for non-custom models

🤖 Generated with Claude Code

maddinenisri and others added 5 commits August 9, 2025 16:07
Implements support for custom models that bypass Builder ID authentication
and use AWS credentials directly. This enables enterprise users to use
Amazon Q CLI with their existing AWS authentication infrastructure.

Features:
- Custom model format: custom:<region>:<model-id>
- Automatic mapping between Bedrock and Q Developer model IDs
- AWS credentials chain support (ENV, Profile, IRSA, ECS, EC2)
- Region extraction and configuration from model format
- Clear display of custom model in chat UI

Example usage:
  q chat --model "custom:us-east-1:us.anthropic.claude-3-5-sonnet-20241022-v2:0"
  q chat --model "custom:us-east-1:CLAUDE_3_7_SONNET_20250219_V1_0"

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

Co-Authored-By: Claude <[email protected]>
- Add unit tests for model parsing and mapping in model.rs
- Add integration tests for CustomModelHandler in custom_model.rs
- Create end-to-end test script for complete workflow testing
- Add test documentation with coverage matrix
- Fix test compilation issues in CI/CD

Tests cover:
- Bedrock to Q Developer model ID mapping
- Custom model format parsing (custom:<region>:<model-id>)
- Region extraction and validation
- Authentication bypass for custom models
- Environment variable setup
- Debug trait implementation
Remove redux-cli from Cargo.toml workspace members as the crate
doesn't exist in the repository, causing CI failures.
- Fix unused variable warning by prefixing with underscore
- Replace map().unwrap_or() with is_some_and() per clippy recommendation
- Add #[allow(dead_code)] for intentionally unused functions
Fix formatting issues to comply with project style guidelines:
- Multi-line imports for tracing module
- Remove trailing whitespace
- Consistent spacing around code blocks
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