AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-05-25 · Documentation low

File: code-library/latest/ug/python_3_bedrock-runtime_code_examples.md

Summary

Added DeepSeek to model list and documentation for processing documents with various AI models (Amazon Nova, Anthropic Claude, Cohere Command, DeepSeek, Meta Llama, Mistral AI)

Security assessment

Changes add documentation for new model integrations and document processing examples. No security vulnerabilities or specific security features are mentioned. Changes demonstrate standard API usage patterns without security-specific content.

Diff

diff --git a/code-library/latest/ug/python_3_bedrock-runtime_code_examples.md b/code-library/latest/ug/python_3_bedrock-runtime_code_examples.md
index 69564a574..70edde4db 100644
--- a//code-library/latest/ug/python_3_bedrock-runtime_code_examples.md
+++ b//code-library/latest/ug/python_3_bedrock-runtime_code_examples.md
@@ -5 +5 @@
-ScenariosAI21 Labs Jurassic-2Amazon NovaAmazon Nova CanvasAmazon Nova ReelAmazon Titan Image GeneratorAmazon Titan TextAmazon Titan Text EmbeddingsAnthropic ClaudeCohere CommandMeta LlamaMistral AIStable Diffusion
+ScenariosAI21 Labs Jurassic-2Amazon NovaAmazon Nova CanvasAmazon Nova ReelAmazon Titan Image GeneratorAmazon Titan TextAmazon Titan Text EmbeddingsAnthropic ClaudeCohere CommandDeepSeekMeta LlamaMistral AIStable Diffusion
@@ -220,0 +221,2 @@ Send a user message to a model with the Converse operation.
+  * DeepSeek
+
@@ -1073,0 +1076,69 @@ Send a text message to Amazon Nova, using Bedrock's Converse API and process the
+The following code example shows how to send and process a document with Amazon Nova on Amazon Bedrock.
+
+**SDK for Python (Boto3)**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-runtime#code-examples). 
+
+Send and process a document with Amazon Nova on Amazon Bedrock.
+    
+    
+    # Send and process a document with Amazon Nova on Amazon Bedrock.
+    
+    import boto3
+    from botocore.exceptions import ClientError
+    
+    # Create a Bedrock Runtime client in the AWS Region you want to use.
+    client = boto3.client("bedrock-runtime", region_name="us-east-1")
+    
+    # Set the model ID, e.g. Amazon Nova Lite.
+    model_id = "amazon.nova-lite-v1:0"
+    
+    # Load the document
+    with open("example-data/amazon-nova-service-cards.pdf", "rb") as file:
+        document_bytes = file.read()
+    
+    # Start a conversation with a user message and the document
+    conversation = [
+        {
+            "role": "user",
+            "content": [
+                {"text": "Briefly compare the models described in this document"},
+                {
+                    "document": {
+                        # Available formats: html, md, pdf, doc/docx, xls/xlsx, csv, and txt
+                        "format": "pdf",
+                        "name": "Amazon Nova Service Cards",
+                        "source": {"bytes": document_bytes},
+                    }
+                },
+            ],
+        }
+    ]
+    
+    try:
+        # Send the message to the model, using a basic inference configuration.
+        response = client.converse(
+            modelId=model_id,
+            messages=conversation,
+            inferenceConfig={"maxTokens": 500, "temperature": 0.3},
+        )
+    
+        # Extract and print the response text.
+        response_text = response["output"]["message"]["content"][0]["text"]
+        print(response_text)
+    
+    except (ClientError, Exception) as e:
+        print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")
+        exit(1)
+    
+    
+    
+
+  * For API details, see [Converse](https://docs.aws.amazon.com/goto/boto3/bedrock-runtime-2023-09-30/Converse) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+
@@ -1807,0 +1879,69 @@ Send a text message to Anthropic Claude, using Bedrock's Converse API and proces
+The following code example shows how to send and process a document with Anthropic Claude on Amazon Bedrock.
+
+**SDK for Python (Boto3)**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-runtime#code-examples). 
+
+Send and process a document with Anthropic Claude on Amazon Bedrock.
+    
+    
+    # Send and process a document with Anthropic Claude on Amazon Bedrock.
+    
+    import boto3
+    from botocore.exceptions import ClientError
+    
+    # Create a Bedrock Runtime client in the AWS Region you want to use.
+    client = boto3.client("bedrock-runtime", region_name="us-east-1")
+    
+    # Set the model ID, e.g. Claude 3 Haiku.
+    model_id = "anthropic.claude-3-haiku-20240307-v1:0"
+    
+    # Load the document
+    with open("example-data/amazon-nova-service-cards.pdf", "rb") as file:
+        document_bytes = file.read()
+    
+    # Start a conversation with a user message and the document
+    conversation = [
+        {
+            "role": "user",
+            "content": [
+                {"text": "Briefly compare the models described in this document"},
+                {
+                    "document": {
+                        # Available formats: html, md, pdf, doc/docx, xls/xlsx, csv, and txt
+                        "format": "pdf",
+                        "name": "Amazon Nova Service Cards",
+                        "source": {"bytes": document_bytes},
+                    }
+                },
+            ],
+        }
+    ]
+    
+    try:
+        # Send the message to the model, using a basic inference configuration.
+        response = client.converse(
+            modelId=model_id,
+            messages=conversation,
+            inferenceConfig={"maxTokens": 500, "temperature": 0.3},
+        )
+    
+        # Extract and print the response text.
+        response_text = response["output"]["message"]["content"][0]["text"]
+        print(response_text)
+    
+    except (ClientError, Exception) as e:
+        print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")
+        exit(1)
+    
+    
+    
+
+  * For API details, see [Converse](https://docs.aws.amazon.com/goto/boto3/bedrock-runtime-2023-09-30/Converse) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+
@@ -2386,0 +2527,69 @@ Send a text message to Cohere Command, using Bedrock's Converse API and process
+The following code example shows how to send and process a document with Cohere Command models on Amazon Bedrock.
+
+**SDK for Python (Boto3)**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-runtime#code-examples). 
+
+Send and process a document with Cohere Command models on Amazon Bedrock.
+    
+    
+    # Send and process a document with Cohere Command models on Amazon Bedrock.
+    
+    import boto3
+    from botocore.exceptions import ClientError
+    
+    # Create a Bedrock Runtime client in the AWS Region you want to use.
+    client = boto3.client("bedrock-runtime", region_name="us-east-1")
+    
+    # Set the model ID, e.g. Command R+.
+    model_id = "cohere.command-r-plus-v1:0"
+    
+    # Load the document
+    with open("example-data/amazon-nova-service-cards.pdf", "rb") as file:
+        document_bytes = file.read()
+    
+    # Start a conversation with a user message and the document
+    conversation = [
+        {
+            "role": "user",
+            "content": [
+                {"text": "Briefly compare the models described in this document"},
+                {
+                    "document": {
+                        # Available formats: html, md, pdf, doc/docx, xls/xlsx, csv, and txt
+                        "format": "pdf",
+                        "name": "Amazon Nova Service Cards",
+                        "source": {"bytes": document_bytes},
+                    }
+                },
+            ],
+        }
+    ]
+    
+    try:
+        # Send the message to the model, using a basic inference configuration.
+        response = client.converse(
+            modelId=model_id,