Skip to main content

Module bedrock

Module bedrock 

Source
Available on crate feature bedrock only.
Expand description

AWS Bedrock support: a RequestSigner that signs HTTP requests with sigv4.

claude-api is the Anthropic API client; this module exposes the signing primitive only. Users who want to talk to Bedrock Anthropic models still need to:

  1. Set Client::builder().base_url("https://bedrock-runtime.{region}.amazonaws.com"),
  2. Use Bedrock’s URL shape (/model/{model_id}/invoke),
  3. Inject anthropic_version: "bedrock-2023-05-31" and remove the model field from the body (Bedrock takes the model in the URL).

The typed namespace handles still use Anthropic’s URL shape; Bedrock model IDs and the anthropic_version header must be supplied by the caller. See examples/bedrock.rs for a complete working sketch.

Gated on the bedrock feature.

§Set up the client

use std::sync::Arc;
use claude_api::{Client, bedrock::{BedrockCredentials, BedrockSigner}};
let region = std::env::var("AWS_REGION").unwrap_or_else(|_| "us-east-1".into());
let creds = BedrockCredentials::from_env()
    .expect("AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set");
let client = Client::builder()
    .signer(Arc::new(BedrockSigner::new(creds, &region)))
    .base_url(format!("https://bedrock-runtime.{region}.amazonaws.com"))
    .build()?;

Structs§

BedrockCredentials
AWS access credentials. Carries the same fields as aws_credential_types::Credentials but is owned, Clone, and kept opaque – the underlying secret is moved into a fresh Credentials per call so this type is safe to share via Arc.
BedrockSigner
AWS sigv4 signer for the bedrock service.