bedrock

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Claude latest (recommended)
	ModelHaikuLatest  = "anthropic.claude-haiku-4-5-20251001-v1:0"
	ModelOpusLatest   = "anthropic.claude-opus-4-6-v1"
	ModelSonnetLatest = "anthropic.claude-sonnet-4-6"

	// Claude 4.5 series
	ModelOpus45   = "anthropic.claude-opus-4-5-20251101-v1:0"
	ModelSonnet45 = "anthropic.claude-sonnet-4-5-20250929-v1:0"

	// Claude 3.x series
	ModelHaiku3   = "anthropic.claude-3-haiku-20240307-v1:0"
	ModelSonnet35 = "anthropic.claude-3-5-sonnet-20240620-v1:0"
	ModelSonnet37 = "anthropic.claude-3-7-sonnet-20250219-v1:0"
)

Anthropic Claude models.

View Source
const (
	ModelNova2Lite   = "amazon.nova-2-lite-v1:0"
	ModelNovaLite    = "amazon.nova-lite-v1:0"
	ModelNovaMicro   = "amazon.nova-micro-v1:0"
	ModelNovaPremier = "amazon.nova-premier-v1:0"
	ModelNovaPro     = "amazon.nova-pro-v1:0"
)

Amazon Nova models.

View Source
const (
	ModelCohereEmbedV4 = "cohere.embed-v4:0"
	ModelCommandR      = "cohere.command-r-v1:0"
	ModelCommandRPlus  = "cohere.command-r-plus-v1:0"
)

Cohere models.

View Source
const (
	// Llama 4
	ModelLlama4Maverick = "meta.llama4-maverick-17b-instruct-v1:0"
	ModelLlama4Scout    = "meta.llama4-scout-17b-instruct-v1:0"

	// Llama 3.3
	ModelLlama33_70B = "meta.llama3-3-70b-instruct-v1:0"

	// Llama 3.2
	ModelLlama32_1B  = "meta.llama3-2-1b-instruct-v1:0"
	ModelLlama32_3B  = "meta.llama3-2-3b-instruct-v1:0"
	ModelLlama32_11B = "meta.llama3-2-11b-instruct-v1:0"
	ModelLlama32_90B = "meta.llama3-2-90b-instruct-v1:0"

	// Llama 3.1
	ModelLlama31_8B  = "meta.llama3-1-8b-instruct-v1:0"
	ModelLlama31_70B = "meta.llama3-1-70b-instruct-v1:0"

	// Llama 3
	ModelLlama3_8B  = "meta.llama3-8b-instruct-v1:0"
	ModelLlama3_70B = "meta.llama3-70b-instruct-v1:0"
)

Meta Llama models.

View Source
const (
	ModelDevstral2        = "mistral.devstral-2-123b"
	ModelMagistralSmall   = "mistral.magistral-small-2509"
	ModelMinistral3B      = "mistral.ministral-3-3b-instruct"
	ModelMinistral8B      = "mistral.ministral-3-8b-instruct"
	ModelMinistral14B     = "mistral.ministral-3-14b-instruct"
	ModelMistral7B        = "mistral.mistral-7b-instruct-v0:2"
	ModelMistralLarge2402 = "mistral.mistral-large-2402-v1:0"
	ModelMistralLarge3    = "mistral.mistral-large-3-675b-instruct"
	ModelMistralSmall     = "mistral.mistral-small-2402-v1:0"
	ModelMixtral8x7B      = "mistral.mixtral-8x7b-instruct-v0:1"
	ModelPixtralLarge     = "mistral.pixtral-large-2502-v1:0"
	ModelVoxtralMini      = "mistral.voxtral-mini-3b-2507"
	ModelVoxtralSmall     = "mistral.voxtral-small-24b-2507"
)

Mistral models.

View Source
const (
	ModelPalmyraX4 = "writer.palmyra-x4-v1:0"
	ModelPalmyraX5 = "writer.palmyra-x5-v1:0"
)

Writer models.

View Source
const (
	RegionUSEast1      = "us-east-1"
	RegionUSEast2      = "us-east-2"
	RegionUSWest2      = "us-west-2"
	RegionEUCentral1   = "eu-central-1"
	RegionEUWest1      = "eu-west-1"
	RegionAPNortheast1 = "ap-northeast-1"
)

Common AWS regions.

View Source
const (
	PrefixEU     = "eu"
	PrefixUS     = "us"
	PrefixAPAC   = "apac"
	PrefixGlobal = "global"
)

Inference profile prefixes for cross-region inference.

View Source
const (
	EnvAWSAccessKeyID     = "AWS_ACCESS_KEY_ID"
	EnvAWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
	EnvAWSRegion          = "AWS_REGION"
	EnvAWSDefaultRegion   = "AWS_DEFAULT_REGION"
	EnvAWSProfile         = "AWS_PROFILE"
)

Environment variable names for AWS configuration.

View Source
const DefaultRegion = RegionUSEast1

DefaultRegion is the default AWS region for Bedrock.

View Source
const (
	ModelDeepSeekR1 = "deepseek.r1-v1:0"
)

DeepSeek models.

Variables

View Source
var DefaultModel = ModelSonnetLatest

DefaultModel is the recommended default model (Claude Sonnet 4.6).

Functions

func MaybeRegister

func MaybeRegister(reg *llm.Registry)

MaybeRegister registers the Bedrock provider if AWS credentials are available. Credentials are detected from:

  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • Shared credentials file (~/.aws/credentials)
  • IAM role (for EC2/ECS/Lambda) - detected at request time

Region is configured from AWS_REGION or AWS_DEFAULT_REGION environment variables, defaulting to us-east-1 if not set.

Types

type InferenceProfile added in v0.16.0

type InferenceProfile struct {
	Prefixes []string // Available: PrefixEU, PrefixUS, PrefixAPAC, PrefixGlobal
}

InferenceProfile defines available region prefixes for a model.

type Option

type Option func(*Provider)

Option configures a Bedrock provider.

func WithCredentialsProvider added in v0.14.0

func WithCredentialsProvider(cp aws.CredentialsProvider) Option

WithCredentialsProvider sets a custom AWS credentials provider. When set, the AWS client is created lazily on first use, allowing credentials to be fetched at request time rather than at construction. This enables integration with external secret managers or dynamic credential sources.

func WithDefaultModel

func WithDefaultModel(model string) Option

WithDefaultModel sets the default model ID.

func WithProfile added in v0.18.0

func WithProfile(profile string) Option

WithProfile sets the AWS profile to use for credentials and configuration. This allows using a specific profile from ~/.aws/credentials or ~/.aws/config instead of the default profile or AWS_PROFILE environment variable.

func WithRegion

func WithRegion(region string) Option

WithRegion sets the AWS region for Bedrock explicitly. By default, New() reads the region from AWS_REGION or AWS_DEFAULT_REGION environment variables, falling back to DefaultRegion (us-east-1).

func WithRegionFromEnv added in v0.18.0

func WithRegionFromEnv() Option

WithRegionFromEnv reads the region from AWS_REGION or AWS_DEFAULT_REGION environment variables. This is useful to re-enable environment variable lookup after WithRegion() has been called.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the AWS Bedrock LLM backend.

func New

func New(opts ...Option) *Provider

New creates a new AWS Bedrock provider. The provider uses the AWS SDK's default credential chain:

  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • Shared credentials file (~/.aws/credentials)
  • IAM role (for EC2/ECS/Lambda)
  • SSO credentials

Region is determined from:

  • AWS_REGION environment variable
  • AWS_DEFAULT_REGION environment variable
  • DefaultRegion (us-east-1) if neither is set

The AWS_PROFILE environment variable is honored automatically by the SDK. Use WithProfile() to explicitly select a different profile.

When WithCredentialsProvider is used, client creation is deferred until the first CreateStream call, allowing credentials to be fetched lazily.

Example usage:

// Use defaults (reads AWS_REGION, AWS_PROFILE from env)
p := bedrock.New()

// Specify region explicitly
p := bedrock.New(bedrock.WithRegion(bedrock.RegionEUCentral1))

// Use a specific AWS profile
p := bedrock.New(bedrock.WithProfile("production"))

// Combine options
p := bedrock.New(
    bedrock.WithProfile("production"),
    bedrock.WithRegion(bedrock.RegionEUWest1),
)

// Specify default model
p := bedrock.New(bedrock.WithDefaultModel(bedrock.ModelHaikuLatest))

// Use custom credentials provider (lazy initialization)
p := bedrock.New(bedrock.WithCredentialsProvider(myProvider))

func (*Provider) CreateStream

func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)

func (*Provider) DefaultModel

func (p *Provider) DefaultModel() string

DefaultModel returns the configured default model ID.

func (*Provider) Models

func (p *Provider) Models() []llm.Model

Models returns a curated list of popular Bedrock models.

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) RegionPrefix added in v0.16.0

func (p *Provider) RegionPrefix() string

RegionPrefix returns the computed inference profile prefix for this provider's region. Returns PrefixEU, PrefixUS, PrefixAPAC, or PrefixGlobal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL