feat: add AWS Bedrock support

This commit is contained in:
Abhishek Kumar 2026-03-19 15:06:59 +05:30
parent 1604e306ec
commit fe84f086ba
30 changed files with 546 additions and 195 deletions

View file

@ -38,6 +38,7 @@ class UserConfigurationValidator:
ServiceProviders.DOGRAH.value: self._check_dograh_api_key,
ServiceProviders.SARVAM.value: self._check_sarvam_api_key,
ServiceProviders.SPEECHMATICS.value: self._check_speechmatics_api_key,
ServiceProviders.AWS_BEDROCK.value: self._check_aws_bedrock_api_key,
}
async def validate(self, configuration: UserConfiguration) -> APIKeyStatusResponse:
@ -71,6 +72,21 @@ class UserConfigurationValidator:
return [] # Optional service not configured is OK
provider = service_config.provider
# AWS Bedrock uses AWS credentials instead of api_key
if provider == ServiceProviders.AWS_BEDROCK.value:
try:
if not self._check_aws_bedrock_api_key(provider, service_config):
return [
{
"model": service_name,
"message": f"Invalid {provider} credentials",
}
]
except ValueError as e:
return [{"model": service_name, "message": str(e)}]
return []
api_key = service_config.api_key
try:
@ -143,3 +159,8 @@ class UserConfigurationValidator:
def _check_speechmatics_api_key(self, model: str, api_key: str) -> bool:
return True
def _check_aws_bedrock_api_key(self, model: str, service_config) -> bool:
if not service_config.aws_access_key or not service_config.aws_secret_key:
raise ValueError("AWS access key and secret key are required for Bedrock")
return True

View file

@ -25,6 +25,7 @@ class ServiceProviders(str, Enum):
DOGRAH = "dograh"
SARVAM = "sarvam"
SPEECHMATICS = "speechmatics"
AWS_BEDROCK = "aws_bedrock"
class BaseServiceConfiguration(BaseModel):
@ -37,6 +38,7 @@ class BaseServiceConfiguration(BaseModel):
ServiceProviders.GOOGLE,
ServiceProviders.AZURE,
ServiceProviders.DOGRAH,
ServiceProviders.AWS_BEDROCK,
# ServiceProviders.SARVAM,
]
api_key: str | list[str]
@ -44,6 +46,8 @@ class BaseServiceConfiguration(BaseModel):
@field_validator("api_key")
@classmethod
def validate_api_key(cls, v):
if v is None:
return v
if isinstance(v, list) and len(v) == 0:
raise ValueError("api_key list must not be empty")
return v
@ -51,6 +55,8 @@ class BaseServiceConfiguration(BaseModel):
def __getattribute__(self, name: str):
if name == "api_key":
value = super().__getattribute__(name)
if value is None:
return value
if isinstance(value, list):
return random.choice(value)
return value
@ -59,6 +65,8 @@ class BaseServiceConfiguration(BaseModel):
def get_all_api_keys(self) -> list[str]:
"""Get all API keys as a list (bypasses random selection)."""
value = super().__getattribute__("api_key")
if value is None:
return []
if isinstance(value, list):
return list(value)
return [value]
@ -167,6 +175,14 @@ OPENROUTER_MODELS = [
]
AZURE_MODELS = ["gpt-4.1-mini"]
DOGRAH_LLM_MODELS = ["default", "accurate", "fast", "lite", "zen"]
AWS_BEDROCK_MODELS = [
"us.amazon.nova-pro-v1:0",
"us.amazon.nova-lite-v1:0",
"us.amazon.nova-micro-v1:0",
"us.anthropic.claude-sonnet-4-20250514-v1:0",
"us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"us.anthropic.claude-haiku-4-5-20251001-v1:0",
]
@register_llm
@ -219,6 +235,19 @@ class DograhLLMService(BaseLLMConfiguration):
)
@register_llm
class AWSBedrockLLMConfiguration(BaseLLMConfiguration):
provider: Literal[ServiceProviders.AWS_BEDROCK] = ServiceProviders.AWS_BEDROCK
model: str = Field(
default="us.amazon.nova-pro-v1:0",
json_schema_extra={"examples": AWS_BEDROCK_MODELS},
)
aws_access_key: str = Field(default="")
aws_secret_key: str = Field(default="")
aws_region: str = Field(default="us-east-1")
api_key: str | list[str] | None = Field(default=None)
LLMConfig = Annotated[
Union[
OpenAILLMService,
@ -227,6 +256,7 @@ LLMConfig = Annotated[
GoogleLLMService,
AzureLLMService,
DograhLLMService,
AWSBedrockLLMConfiguration,
],
Field(discriminator="provider"),
]