Skip to content

Amazon Bedrock

The Bedrock provider uses provider key bedrock and the HPD-Agent.Providers.Bedrock package. ModelName is an Amazon Bedrock model id, such as an Anthropic Claude model id in Bedrock format.

Set a region:

bash
export AWS_REGION="us-east-1"
# or
export AWS_DEFAULT_REGION="us-east-1"

Credentials usually come from the AWS SDK default credential chain: environment variables such as AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN, shared AWS profile, IAM role, or other SDK-supported sources. Use your normal AWS credential setup for the host environment.

Use fluent setup first:

csharp
using HPD.Agent;
using HPD.Agent.Providers.Bedrock;
using Amazon.Runtime;

var agent = await new AgentBuilder()
    .WithBedrock(model: "anthropic.claude-3-5-sonnet-20240620-v1:0", region: "us-east-1")
    .BuildAsync();

var result = await agent.RunAsync("Write one sentence about Bedrock setup.");
Console.WriteLine(result.Text);

Runtime chat behavior such as model selection overrides, temperature, top-p, max output tokens, stop sequences, tools, structured output, and reasoning belongs in ChatDefaults or per-run AgentRunConfig.Chat:

csharp
var agent = await new AgentBuilder()
    .WithBedrock(model: "anthropic.claude-3-5-sonnet-20240620-v1:0", region: "us-east-1")
    .WithChatDefaults(chat =>
    {
        chat.Temperature = 0.2;
        chat.TopP = 0.95;
        chat.MaxOutputTokens = 4096;
        chat.Reasoning = new()
        {
            Effort = ReasoningEffort.High
        };
    })
    .BuildAsync();

BedrockProviderConfig is for AWS-native client construction:

csharp
var agent = await new AgentBuilder()
    .WithBedrock(
        model: "anthropic.claude-3-5-sonnet-20240620-v1:0",
        region: "us-east-1",
        configure: bedrock =>
        {
            bedrock.ProfileName = "hpd-dev";
            bedrock.ServiceUrl = "https://vpce-xxx.bedrock-runtime.us-east-1.vpce.amazonaws.com";
            bedrock.AuthenticationRegion = "us-east-1";
            bedrock.SigV4aSigningRegionSet = ["us-east-1", "us-west-2"];
            bedrock.UseFipsEndpoint = true;
            bedrock.UseDualstackEndpoint = true;
            bedrock.RequestTimeoutMs = 120000;
            bedrock.ConnectTimeoutMs = 5000;
            bedrock.MaxRetryAttempts = 4;
            bedrock.RetryMode = RequestRetryMode.Adaptive;
            bedrock.DefaultConfigurationMode = DefaultConfigurationMode.CrossRegion;
        })
    .BuildAsync();

The equivalent Clients.Chat shape is:

json
{
  "Clients": {
    "Chat": {
      "ProviderKey": "bedrock",
      "ModelName": "anthropic.claude-3-5-sonnet-20240620-v1:0",
      "ProviderOptions": {
        "region": "us-east-1",
        "profileName": "hpd-dev",
        "serviceUrl": "https://vpce-xxx.bedrock-runtime.us-east-1.vpce.amazonaws.com",
        "authenticationRegion": "us-east-1",
        "sigV4aSigningRegionSet": ["us-east-1", "us-west-2"],
        "useFipsEndpoint": true,
        "useDualstackEndpoint": true,
        "requestTimeoutMs": 120000,
        "connectTimeoutMs": 5000,
        "maxRetryAttempts": 4,
        "retryMode": "Adaptive",
        "defaultConfigurationMode": "CrossRegion"
      }
    }
  }
}

Provider Options

BedrockProviderConfig is for AWS SDK client construction. Production applications should normally lean on the AWS SDK credential chain or host identity, and only set explicit credentials when the host environment cannot provide them.

Identity And Region

OptionPurpose
RegionAWS region where Bedrock Runtime is hosted.
AccessKeyIdExplicit AWS access key id. Prefer the AWS SDK credential chain when possible.
SecretAccessKeyExplicit AWS secret access key. Prefer the AWS SDK credential chain when possible.
SessionTokenAWS session token for temporary credentials.
ProfileNameShared AWS profile name from local AWS config/credentials files.

Endpoint And Signing

OptionPurpose
ServiceUrlCustom Bedrock Runtime endpoint URL, such as a VPC endpoint.
AuthenticationRegionAWS signing region, useful when it cannot be inferred from a custom endpoint.
AuthenticationServiceNameAWS signing service name.
AuthSchemePreferenceOrdered list of preferred AWS auth schemes, such as sigv4 or sigv4a.
SigV4aSigningRegionSetAWS SigV4a signing region set.
UseFipsEndpointUses FIPS-compliant endpoints when available.
UseDualstackEndpointUses dual-stack endpoints when available.
UseHttpUses HTTP instead of HTTPS.
IgnoreConfiguredEndpointUrlsIgnores endpoint URLs configured outside this provider config.
DisableHostPrefixInjectionDisables SDK host prefix injection for custom/local endpoint scenarios.
EndpointDiscoveryEnabledEnables AWS endpoint discovery.

Timeouts And Retries

OptionPurpose
RequestTimeoutMsOverall request timeout in milliseconds.
ConnectTimeoutMsConnection timeout in milliseconds.
MaxRetryAttemptsMaximum number of retry attempts for failed requests.
RetryModeAWS SDK retry mode, such as Standard or Adaptive.
DefaultConfigurationModeAWS SDK default configuration mode, such as Standard, InRegion, or CrossRegion.
MaxStaleConnectionRetriesMaximum retry attempts for stale HTTP connections.
ThrottleRetriesEnables AWS SDK retry throttling.
FastFailRequestsFails quickly when retry capacity is unavailable.
ResignRetriesRe-signs requests on retry.

HTTP Pipeline

OptionPurpose
DisableRequestCompressionDisables SDK request compression.
RequestMinCompressionSizeBytesMinimum request size in bytes before compression is considered.
CacheHttpClientCaches HTTP clients created by the AWS SDK.
HttpClientCacheSizeMaximum AWS SDK HTTP client cache size.
ProxyHostProxy host used by the AWS SDK HTTP pipeline.
ProxyPortProxy port used by the AWS SDK HTTP pipeline.
MaxConnectionsPerServerMaximum concurrent HTTP connections per server.
AllowAutoRedirectAllows automatic HTTP redirects.

Diagnostics And Transfer

OptionPurpose
ClientAppIdAWS SDK client application identifier.
LogResponseLogs response bodies through AWS SDK logging.
BufferSizeAWS SDK transfer buffer size.
ProgressUpdateIntervalMsAWS SDK progress update interval in milliseconds.
LogMetricsEnables AWS SDK metrics logging.
DisableLoggingDisables AWS SDK logging.

ReadWriteTimeout is not exposed because the current AWS SDK only exposes it on the .NET Framework asset, not the net8/net9/net10 assets HPD targets.

Reasoning is passed through ChatOptions.Reasoning to Bedrock Converse extended thinking when the selected model supports it. Models without extended thinking support return a Bedrock API error.

Built for production .NET agent applications.