Registry /
type-stubs / types-boto3-bedrock-runtime
Install & Compatibility
Where this runs
tested against v1.43.30 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.010s · 115MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 5.6s · import 0.007s · 114MB
113MB installed
● package 113MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BedrockRuntimeClient
✓ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types_boto3_bedrock_runtime.client import BedrockRuntimeClient
✗ from types_boto3_bedrock_runtime import BedrockRuntimeClient
Type stub packages should only be imported for type checking purposes to avoid runtime overhead or errors. Use `if TYPE_CHECKING:`.
InvokeModelRequestRequestTypeDef
✓ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types_boto3_bedrock_runtime.type_defs import InvokeModelRequestRequestTypeDef
Specific type definitions for requests/responses are found in `type_defs` and should also be conditionally imported.
This quickstart demonstrates how to initialize a `boto3` Bedrock Runtime client with type annotations. It shows the conditional import of `BedrockRuntimeClient` and `InvokeModelRequestRequestTypeDef` for static analysis and then uses the client to invoke a model. Remember to set your AWS credentials and region via environment variables or other boto3 configuration methods for actual execution.
import boto3
import os
from typing import TYPE_CHECKING
# Conditional import for type checking
if TYPE_CHECKING:
from types_boto3_bedrock_runtime.client import BedrockRuntimeClient
from types_boto3_bedrock_runtime.type_defs import InvokeModelRequestRequestTypeDef
def invoke_bedrock_model(model_id: str, prompt: str):
# Type annotate the client
client: BedrockRuntimeClient = boto3.client(
'bedrock-runtime',
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
body_content = {"prompt": prompt, "max_tokens_to_sample": 200, "temperature": 0.7}
# Example of type-hinted request body (mypy will check its structure)
request_body: InvokeModelRequestRequestTypeDef = {
'body': str(body_content).encode('utf-8'), # In real use, convert dict to JSON string
'contentType': 'application/json',
'accept': 'application/json',
'modelId': model_id
}
try:
response = client.invoke_model(**request_body)
print("Successfully invoked model:")
# Process response body (example)
response_body = response['body'].read().decode('utf-8')
print(response_body)
except client.exceptions.AccessDeniedException as e:
print(f"Access Denied: {e}")
print("Please ensure your AWS credentials and permissions are correctly configured.")
except Exception as e:
print(f"An error occurred: {e}")
# Example usage:
if __name__ == "__main__":
# Replace with an actual model ID available in your region
# e.g., 'anthropic.claude-v2' or 'amazon.titan-text-express-v1'
model = "DUMMY_MODEL_ID"
user_prompt = "Hello, how are you?"
invoke_bedrock_model(model, user_prompt)
Upgrade
Version history
1.43.30latest on PyPI · released Jun 15, 2026
Audit
Dependencies
boto3requiredThis package provides type stubs for `boto3`. `boto3` must be installed for runtime execution.
mypyoptionalStatic type checker that consumes these type annotations.
typing-extensionsoptionalRequired for Python versions < 3.11 for certain typing features.