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.1.3.tar.gz (17.4 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.1.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stache_ai_bedrock-0.1.3.tar.gz
  • Upload date:
  • Size: 17.4 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.1.3.tar.gz
Algorithm Hash digest
SHA256 f6b6d4755ef0b4d15480cf454cef372f0429621e31352cb4d7b81ca0142c4806
MD5 0748229da1c276f2a4fbd39836e3dbee
BLAKE2b-256 95f199e8b08231fa16416973cd22fac5fa60b3a0c9ab55bcf004c3602ccad230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stache_ai_bedrock-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 db79716ef63d130a3ed074cdfe0140b88f690714215ae6a81fcd88d7d1027910
MD5 642df590394ad9104281e9f385ba21aa
BLAKE2b-256 4868823fc42deb55556426bbeba35661e4c7f504e0a6f65deb4d1769cc6204ce

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