Skip to main content

Bedrock provider for Stache AI

Project description

stache-ai-bedrock

Amazon Bedrock provider for Stache AI - LLM and embedding support via AWS Bedrock.

Installation

pip install stache-ai-bedrock

Usage

Install the package and configure the provider in your settings:

from stache_ai.config import Settings

settings = Settings(
    llm_provider="bedrock",
    embedding_provider="bedrock",
    bedrock_model_id="anthropic.claude-sonnet-4-20250514-v1:0",  # Optional
    bedrock_embedding_model_id="cohere.embed-english-v3",        # Optional
)

The provider will be automatically discovered via entry points.

Environment Variables

Variable Description Default
LLM_PROVIDER Set to bedrock for LLM -
EMBEDDING_PROVIDER Set to bedrock for embeddings -
BEDROCK_MODEL_ID LLM model ID anthropic.claude-sonnet-4-20250514-v1:0
BEDROCK_EMBEDDING_MODEL_ID Embedding model ID cohere.embed-english-v3
AWS_REGION AWS region us-east-1

Supported Models

LLM Models

The provider supports all Bedrock-available models including:

Provider Models Tier
Anthropic Claude Opus 4, Claude Sonnet 4, Claude Sonnet 3.5 v2, Claude Haiku 3.5 Premium/Balanced/Fast
Amazon Nova Pro, Nova Lite, Nova Micro, Titan Text Balanced/Fast
Meta Llama 3.1 405B, Llama 3.2 90B, Llama 3 70B/8B Premium/Balanced/Fast
Mistral Mistral Large, Mixtral 8x7B, Mistral 7B Premium/Balanced/Fast
Cohere Command R+, Command R Premium/Balanced
AI21 Jamba 1.5 Large, Jamba 1.5 Mini Premium/Balanced

Embedding Models

Model ID Dimensions Description
cohere.embed-english-v3 1024 English text (recommended)
cohere.embed-multilingual-v3 1024 Multilingual text
amazon.titan-embed-text-v2:0 1024 Amazon Titan embeddings

IAM Permissions

The Bedrock provider requires specific IAM permissions for model invocation.

Minimum Required Permissions

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeModel",
        "bedrock:InvokeModelWithResponseStream",
        "bedrock:Converse"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "aws-marketplace:ViewSubscriptions",
        "aws-marketplace:Subscribe"
      ],
      "Resource": "*"
    }
  ]
}

Why Resource: "*"?

Bedrock uses cross-region inference profiles for some models, which require wildcard resource permissions. Specific model ARNs (e.g., arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-*) will fail for cross-region requests.

SAM Template Example

Resources:
  StacheFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          LLM_PROVIDER: bedrock
          EMBEDDING_PROVIDER: bedrock
          BEDROCK_MODEL_ID: anthropic.claude-sonnet-4-20250514-v1:0
          BEDROCK_EMBEDDING_MODEL_ID: cohere.embed-english-v3
      Policies:
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - bedrock:InvokeModel
                - bedrock:InvokeModelWithResponseStream
                - bedrock:Converse
              Resource: '*'
            - Effect: Allow
              Action:
                - aws-marketplace:ViewSubscriptions
                - aws-marketplace:Subscribe
              Resource: '*'

Terraform Example

data "aws_iam_policy_document" "bedrock" {
  statement {
    effect = "Allow"
    actions = [
      "bedrock:InvokeModel",
      "bedrock:InvokeModelWithResponseStream",
      "bedrock:Converse"
    ]
    resources = ["*"]
  }

  statement {
    effect = "Allow"
    actions = [
      "aws-marketplace:ViewSubscriptions",
      "aws-marketplace:Subscribe"
    ]
    resources = ["*"]
  }
}

resource "aws_iam_role_policy" "bedrock" {
  name   = "bedrock-access"
  role   = aws_iam_role.lambda.id
  policy = data.aws_iam_policy_document.bedrock.json
}

Important Notes

Model Access

Before using a model, you must enable access in the AWS Bedrock console:

  1. Go to AWS Console → Bedrock → Model access
  2. Request access to the models you want to use
  3. Wait for access approval (usually instant for most models)

Converse API

This provider uses the Bedrock Converse API (not the legacy InvokeModel API for chat). This requires the bedrock:Converse permission - bedrock:InvokeModel alone is not sufficient for LLM chat operations.

Embeddings

Embeddings use bedrock:InvokeModel with the embedding model. The Cohere embed models return 1024-dimensional vectors by default.

Requirements

  • Python >= 3.10
  • stache-ai >= 0.1.0
  • boto3 >= 1.34.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stache_ai_bedrock-0.2.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stache_ai_bedrock-0.2.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file stache_ai_bedrock-0.2.0.tar.gz.

File metadata

  • Download URL: stache_ai_bedrock-0.2.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for stache_ai_bedrock-0.2.0.tar.gz
Algorithm Hash digest
SHA256 98589ede97d5e272c624601ee89d72228fb20e1007f59c707b1b056371ca16d5
MD5 def2cbff219ec8c594ee1934a5fcb75b
BLAKE2b-256 a9f232ed2922c44cd7e02297da41b38547c88f995ac35077586b42c14e1c81b4

See more details on using hashes here.

File details

Details for the file stache_ai_bedrock-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for stache_ai_bedrock-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cdca060bc361918129b7ef9d30674e7618cb71fd9e3b0f0b185df526fd6ff506
MD5 00fa43c10ef398a6980eecdc36b36b47
BLAKE2b-256 773b10e65d74792f0e1c11a3b6413a6defc2f33b1248602df56e9305805bd43d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page