Environment:Cohere ai Cohere python AWS Integration Dependencies
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, AWS, Cloud_Deployment |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Optional AWS dependency environment (boto3, botocore, sagemaker) required for Cohere model access through AWS Bedrock and SageMaker.
Description
This environment extends the base Python SDK runtime with AWS-specific dependencies for accessing Cohere models deployed on AWS Bedrock and AWS SageMaker. These dependencies are not bundled with the core SDK; they are lazily imported at runtime only when an AWS client is instantiated. This keeps the base install lightweight for users who only need the Cohere API directly.
Usage
Use this environment when deploying Cohere models through AWS Bedrock or AWS SageMaker endpoints. It is the mandatory prerequisite for the `BedrockClient`, `BedrockClientV2`, `SagemakerClient`, and `SagemakerClientV2` classes. If only using the standard Cohere API (`Client` or `ClientV2`), this environment is not required.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, or Windows | Same as base SDK |
| Python | >= 3.9 | Same as base SDK |
| AWS Account | Active AWS account | With Bedrock or SageMaker access enabled |
| IAM | Appropriate IAM permissions | For `bedrock:InvokeModel` or `sagemaker:InvokeEndpoint` |
Dependencies
Python Packages
- `boto3` -- AWS SDK for Python; provides high-level resource access
- `botocore` -- Low-level AWS service interface; used for SigV4 request signing
- `sagemaker` -- SageMaker Python SDK; required for SageMaker endpoint access
System Packages
- No additional system packages required beyond the base SDK
Credentials
The following environment variables are used:
- `AWS_ACCESS_KEY_ID`: AWS access key for authentication.
- `AWS_SECRET_ACCESS_KEY`: AWS secret key for authentication.
- `AWS_SESSION_TOKEN`: Session token for temporary credentials (optional).
- `AWS_DEFAULT_REGION`: AWS region for endpoint routing (set by SDK if not present).
- `CO_API_KEY`: Still required in some configurations for Cohere model identification.
Quick Install
# Install Cohere SDK with AWS dependencies
pip install cohere boto3 botocore sagemaker
Code Evidence
Lazy dependency loading from `manually_maintained/lazy_aws_deps.py:1-24`:
warning = "AWS dependencies are not installed. Please install boto3, botocore, and sagemaker."
def lazy_sagemaker():
try:
import sagemaker as sage
return sage
except ImportError:
raise ImportError(warning)
def lazy_boto3():
try:
import boto3
return boto3
except ImportError:
raise ImportError(warning)
def lazy_botocore():
try:
import botocore
return botocore
except ImportError:
raise ImportError(warning)
AWS region override from `manually_maintained/cohere_aws/client.py:30-31`:
if aws_region is not None and os.environ.get("AWS_DEFAULT_REGION") is None:
os.environ["AWS_DEFAULT_REGION"] = aws_region
Bedrock endpoint construction from `aws_client.py:271-284`:
def get_url(*, platform: str, aws_region: typing.Optional[str],
model: str, stream: bool) -> str:
if platform == "bedrock":
endpoint = "invoke" if not stream else "invoke-with-response-stream"
return f"https://{platform}-runtime.{aws_region}.amazonaws.com/model/{model}/{endpoint}"
elif platform == "sagemaker":
endpoint = "invocations" if not stream else "invocations-response-stream"
return f"https://runtime.sagemaker.{aws_region}.amazonaws.com/endpoints/{model}/{endpoint}"
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ImportError: AWS dependencies are not installed. Please install boto3, botocore, and sagemaker.` | Missing AWS packages | `pip install boto3 botocore sagemaker` |
| `botocore.exceptions.NoCredentialsError` | AWS credentials not configured | Run `aws configure` or set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` |
| `botocore.exceptions.ClientError: AccessDeniedException` | IAM permissions insufficient | Ensure IAM role has `bedrock:InvokeModel` or `sagemaker:InvokeEndpoint` permissions |
Compatibility Notes
- Lazy Loading: AWS dependencies are imported at first use, not at SDK import time. This means `import cohere` will succeed even without AWS packages installed.
- SageMaker Finetuning: The `SagemakerClient` silently skips finetuning client initialization if it fails (`try/except Exception: pass`), so SageMaker finetuning failures are silent.
- Region Override: The SDK sets `AWS_DEFAULT_REGION` in the process environment if `aws_region` is passed to the constructor and no region is set, which can affect other AWS clients in the same process.