AWS Security ChangesHomeSearch

AWS bedrock documentation change

Service: bedrock · 2025-03-23 · Documentation low

File: bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md

Summary

Added Kotlin SDK code example for non-streaming text generation with Amazon Nova via Bedrock's Converse API

Security assessment

Routine documentation update adding programming language example implementation without any security context or security feature explanations

Diff

diff --git a/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md b/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md
index ae0304fdb..a70b4638d 100644
--- a/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md
+++ b/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md
@@ -429,0 +430,75 @@ Send a text message to Amazon Nova, using Bedrock's Converse API.
+Kotlin
+    
+
+**SDK for Kotlin**
+    
+
+###### 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/kotlin/services/bedrock-runtime#code-examples). 
+
+Send a text message to Amazon Nova, using Bedrock's Converse API.
+    
+    
+    import aws.sdk.kotlin.services.bedrockruntime.BedrockRuntimeClient
+    import aws.sdk.kotlin.services.bedrockruntime.model.ContentBlock
+    import aws.sdk.kotlin.services.bedrockruntime.model.ConversationRole
+    import aws.sdk.kotlin.services.bedrockruntime.model.ConverseRequest
+    import aws.sdk.kotlin.services.bedrockruntime.model.Message
+    
+    /**
+     * This example demonstrates how to use the Amazon Nova foundation models to generate text.
+     * It shows how to:
+     * - Set up the Amazon Bedrock runtime client
+     * - Create a message
+     * - Configure and send a request
+     * - Process the response
+     */
+    suspend fun main() {
+        converse().also { println(it) }
+    }
+    
+    suspend fun converse(): String {
+        // Create and configure the Bedrock runtime client
+        BedrockRuntimeClient { region = "us-east-1" }.use { client ->
+    
+            // Specify the model ID. For the latest available models, see:
+            // https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
+            val modelId = "amazon.nova-lite-v1:0"
+    
+            // Create the message with the user's prompt
+            val prompt = "Describe the purpose of a 'hello world' program in one line."
+            val message = Message {
+                role = ConversationRole.User
+                content = listOf(ContentBlock.Text(prompt))
+            }
+    
+            // Configure the request with optional model parameters
+            val request = ConverseRequest {
+                this.modelId = modelId
+                messages = listOf(message)
+                inferenceConfig {
+                    maxTokens = 500 // Maximum response length
+                    temperature = 0.5F // Lower values: more focused output
+                    // topP = 0.8F // Alternative to temperature
+                }
+            }
+    
+            // Send the request and process the model's response
+            runCatching {
+                val response = client.converse(request)
+                return response.output!!.asMessage().content.first().asText()
+            }.getOrElse { error ->
+                error.message?.let { e -> System.err.println("ERROR: Can't invoke '$modelId'. Reason: $e") }
+                throw RuntimeException("Failed to generate text with model $modelId", error)
+            }
+        }
+    }
+    
+    
+
+  * For API details, see [Converse](https://sdk.amazonaws.com/kotlin/api/latest/index.html) in _AWS SDK for Kotlin API reference_. 
+
+
+
+