bedrock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package bedrock implements ai.Provider for Amazon Bedrock using the AWS SDK for Go v2 (bedrockruntime).

Chat uses the model-agnostic Converse / ConverseStream APIs, so any Bedrock text model works (Anthropic Claude, Amazon Nova, Meta Llama, Mistral, Cohere, …); images are sent as bytes. Embeddings use InvokeModel with Amazon Titan Text Embeddings (amazon.titan-embed-*) or Cohere Embed (cohere.embed-*). Image generation uses InvokeModel with Amazon Nova Canvas / Titan Image Generator (TEXT_IMAGE task) or Stability AI models.

Credentials come from the default AWS chain (environment, shared config, IAM role, IRSA, ECS task role…); an api_key is used as a Bedrock API key (bearer token) instead. region is required unless AWS_REGION is set; base_url overrides the endpoint (VPC endpoints, tests).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// HTTPClient performs upstream requests (default: the AWS SDK's client).
	HTTPClient *http.Client
	// Logger receives debug logs (default: slog.Default()).
	Logger *slog.Logger
	// FetchImage downloads URL images (Converse needs bytes). Default: an
	// SSRF-guarded fetcher.
	FetchImage imagefetch.Func
	// AWSConfig replaces config.LoadDefaultConfig (tests, custom credential
	// chains). Region from the provider config still takes precedence.
	AWSConfig *aws.Config
}

Options are optional dependencies.

type Provider

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

Provider is an ai.Provider for Amazon Bedrock. It is safe for concurrent use.

func New

func New(ctx context.Context, name string, pc config.ProviderConfig, opts Options) (*Provider, error)

New creates a Bedrock provider. Loading the AWS configuration reads only local sources (environment, shared files); credentials are resolved per request.

func (*Provider) Chat

func (p *Provider) Chat(ctx context.Context, req ai.ChatRequest) (*ai.ChatResponse, error)

Chat implements ai.Provider using Converse.

func (*Provider) ChatStream

func (p *Provider) ChatStream(ctx context.Context, req ai.ChatRequest, onDelta func(string) error) (*ai.ChatResponse, error)

ChatStream implements ai.Provider using ConverseStream.

func (*Provider) Embed

func (p *Provider) Embed(ctx context.Context, req ai.EmbedRequest) (*ai.EmbedResponse, error)

Embed implements ai.Provider for Titan and Cohere embedding models.

func (*Provider) Image

func (p *Provider) Image(ctx context.Context, req ai.ImageRequest) (*ai.ImageResponse, error)

Image implements ai.Provider for Amazon Nova Canvas / Titan Image Generator and Stability AI models.

func (*Provider) Name

func (p *Provider) Name() string

Name implements ai.Provider.

Jump to

Keyboard shortcuts

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