AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-07-01 · Documentation low

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

Summary

Removed AI21 Labs Jurassic-2 and Mistral AI model documentation. Updated code examples to use InvokeModel/InvokeModelWithResponseStream APIs instead of Converse API across multiple model providers (Amazon Titan, Anthropic Claude, Cohere Command, Meta Llama). Added response streaming examples and updated model IDs/request structures for various providers.

Security assessment

Changes involve API usage patterns and model support updates without any explicit security context. No vulnerabilities or security features mentioned in the diff.

Diff

diff --git a/code-library/latest/ug/csharp_3_bedrock-runtime_code_examples.md b/code-library/latest/ug/csharp_3_bedrock-runtime_code_examples.md
index b0105390f..48d133b5d 100644
--- a//code-library/latest/ug/csharp_3_bedrock-runtime_code_examples.md
+++ b//code-library/latest/ug/csharp_3_bedrock-runtime_code_examples.md
@@ -5 +5 @@
-ScenariosAI21 Labs Jurassic-2Amazon NovaAmazon Nova CanvasAmazon Titan TextAnthropic ClaudeCohere CommandMeta LlamaMistral AI
+ScenariosAmazon NovaAmazon Nova CanvasAmazon Titan TextAnthropic ClaudeCohere CommandMeta LlamaMistral AI
@@ -21,2 +20,0 @@ Each example includes a link to the complete source code, where you can find ins
-  * AI21 Labs Jurassic-2
-
@@ -619,147 +616,0 @@ The Converse API action with a tool configuration.
-## AI21 Labs Jurassic-2
-
-The following code example shows how to send a text message to AI21 Labs Jurassic-2, using Bedrock's Converse API.
-
-**SDK for .NET**
-    
-
-###### 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/dotnetv3/Bedrock-runtime#code-examples). 
-
-Send a text message to AI21 Labs Jurassic-2, using Bedrock's Converse API.
-    
-    
-    // Use the Converse API to send a text message to AI21 Labs Jurassic-2.
-    
-    using System;
-    using System.Collections.Generic;
-    using Amazon;
-    using Amazon.BedrockRuntime;
-    using Amazon.BedrockRuntime.Model;
-    
-    // Create a Bedrock Runtime client in the AWS Region you want to use.
-    var client = new AmazonBedrockRuntimeClient(RegionEndpoint.USEast1);
-    
-    // Set the model ID, e.g., Jurassic-2 Mid.
-    var modelId = "ai21.j2-mid-v1";
-    
-    // Define the user message.
-    var userMessage = "Describe the purpose of a 'hello world' program in one line.";
-    
-    // Create a request with the model ID, the user message, and an inference configuration.
-    var request = new ConverseRequest
-    {
-        ModelId = modelId,
-        Messages = new List<Message>
-        {
-            new Message
-            {
-                Role = ConversationRole.User,
-                Content = new List<ContentBlock> { new ContentBlock { Text = userMessage } }
-            }
-        },
-        InferenceConfig = new InferenceConfiguration()
-        {
-            MaxTokens = 512,
-            Temperature = 0.5F,
-            TopP = 0.9F
-        }
-    };
-    
-    try
-    {
-        // Send the request to the Bedrock Runtime and wait for the result.
-        var response = await client.ConverseAsync(request);
-    
-        // Extract and print the response text.
-        string responseText = response?.Output?.Message?.Content?[0]?.Text ?? "";
-        Console.WriteLine(responseText);
-    }
-    catch (AmazonBedrockRuntimeException e)
-    {
-        Console.WriteLine($"ERROR: Can't invoke '{modelId}'. Reason: {e.Message}");
-        throw;
-    }
-    
-    
-    
-
-  * For API details, see [Converse](https://docs.aws.amazon.com/goto/DotNetSDKV3/bedrock-runtime-2023-09-30/Converse) in _AWS SDK for .NET API Reference_. 
-
-
-
-
-The following code example shows how to send a text message to AI21 Labs Jurassic-2, using the Invoke Model API.
-
-**SDK for .NET**
-    
-
-###### 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/dotnetv3/Bedrock-runtime#code-examples). 
-
-Use the Invoke Model API to send a text message.
-    
-    
-    // Use the native inference API to send a text message to AI21 Labs Jurassic-2.
-    
-    using System;
-    using System.IO;
-    using System.Text.Json;
-    using System.Text.Json.Nodes;
-    using Amazon;
-    using Amazon.BedrockRuntime;
-    using Amazon.BedrockRuntime.Model;
-    
-    // Create a Bedrock Runtime client in the AWS Region you want to use.
-    var client = new AmazonBedrockRuntimeClient(RegionEndpoint.USEast1);
-    
-    // Set the model ID, e.g., Jurassic-2 Mid.
-    var modelId = "ai21.j2-mid-v1";
-    
-    // Define the user message.
-    var userMessage = "Describe the purpose of a 'hello world' program in one line.";
-    
-    //Format the request payload using the model's native structure.
-    var nativeRequest = JsonSerializer.Serialize(new
-    {
-        prompt = userMessage,
-        maxTokens = 512,
-        temperature = 0.5
-    });
-    
-    // Create a request with the model ID and the model's native request payload.
-    var request = new InvokeModelRequest()
-    {
-        ModelId = modelId,
-        Body = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(nativeRequest)),
-        ContentType = "application/json"
-    };
-    
-    try
-    {
-        // Send the request to the Bedrock Runtime and wait for the response.
-        var response = await client.InvokeModelAsync(request);
-    
-        // Decode the response body.
-        var modelResponse = await JsonNode.ParseAsync(response.Body);
-    
-        // Extract and print the response text.
-        var responseText = modelResponse["completions"]?[0]?["data"]?["text"] ?? "";
-        Console.WriteLine(responseText);
-    }
-    catch (AmazonBedrockRuntimeException e)
-    {
-        Console.WriteLine($"ERROR: Can't invoke '{modelId}'. Reason: {e.Message}");
-        throw;
-    }
-    
-    
-    
-
-  * For API details, see [InvokeModel](https://docs.aws.amazon.com/goto/DotNetSDKV3/bedrock-runtime-2023-09-30/InvokeModel) in _AWS SDK for .NET API Reference_. 
-
-
-
-
@@ -1638 +1489 @@ Create an image with Amazon Nova Canvas.
-The following code example shows how to send a text message to Amazon Titan Text, using Bedrock's Converse API.
+The following code example shows how to send a text message to Amazon Titan Text models, using the Invoke Model API, and print the response stream.
@@ -1647 +1498 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-Send a text message to Amazon Titan Text, using Bedrock's Converse API.
+Use the Invoke Model API to send a text message and process the response stream in real-time.
@@ -1650 +1501,2 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-    // Use the Converse API to send a text message to Amazon Titan Text.
+    // Use the native inference API to send a text message to Amazon Titan Text
+    // and print the response stream.
@@ -1653 +1505,3 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-    using System.Collections.Generic;
+    using System.IO;
+    using System.Text.Json;
+    using System.Text.Json.Nodes;
@@ -1667,5 +1521,2 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-    // Create a request with the model ID, the user message, and an inference configuration.
-    var request = new ConverseRequest
-    {
-        ModelId = modelId,
-        Messages = new List<Message>
+    //Format the request payload using the model's native structure.
+    var nativeRequest = JsonSerializer.Serialize(new
@@ -1673 +1524,2 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-            new Message
+        inputText = userMessage,
+        textGenerationConfig = new
@@ -1675,2 +1527,2 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-                Role = ConversationRole.User,
-                Content = new List<ContentBlock> { new ContentBlock { Text = userMessage } }
+            maxTokenCount = 512,
+            temperature = 0.5
@@ -1678,2 +1530,4 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-        },
-        InferenceConfig = new InferenceConfiguration()
+    });
+    
+    // Create a request with the model ID and the model's native request payload.
+    var request = new InvokeModelWithResponseStreamRequest()
@@ -1681,4 +1535,3 @@ Send a text message to Amazon Titan Text, using Bedrock's Converse API.
-            MaxTokens = 512,
-            Temperature = 0.5F,