BedrockRuntime client

This page contains examples with the BedrockRuntime client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The BedrockRuntime package could be installed with Composer.

composer require async-aws/bedrock-runtime

A new client object may be instantiated by:

use AsyncAws\BedrockRuntime\BedrockRuntimeClient; $bedrockRuntime = new BedrockRuntimeClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\BedrockRuntime\BedrockRuntimeClient; $bedrockRuntime = new BedrockRuntimeClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

InvokeModel

use AsyncAws\BedrockRuntime\BedrockRuntimeClient; use AsyncAws\BedrockRuntime\Input\InvokeModelRequest; $bedrockRuntime = new BedrockRuntimeClient(); $body = [ 'anthropic_version' => 'bedrock-2023-05-31', 'max_tokens' => 4096, 'messages' => [ [ 'role' => 'user', 'content' => [ ['type' => 'text', 'text' => 'Write me a love poem.'] ] ] ], 'temperature' => 1 ]; $result = $bedrockRuntime->invokeModel(new InvokeModelRequest([ 'modelId' => 'us.anthropic.claude-3-7-sonnet-20250219-v1:0', 'contentType' => 'application/json', 'body' => json_encode($body, JSON_THROW_ON_ERROR) ])); $response = json_decode($result->getBody(), true, 512, JSON_THROW_ON_ERROR); echo $response['content'][0]['text'];

more information InvokeModel


The source code to this page is found on GitHub.