Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Bedrock Inference-profielen

Configureer en gebruik AWS Bedrock custom inference profiles met LibreChat voor cross-region load balancing, kostenallocatie en compliance-controles.

Deze handleiding legt uit hoe je AWS Bedrock custom inference profiles configureert en gebruikt met LibreChat, waardoor je modelverzoeken kunt routeren via aangepaste application inference profiles voor betere controle, kostenallocatie en load balancing tussen regio's.

Overzicht

AWS Bedrock inference profiles stellen je in staat om aangepaste routeringsconfiguraties voor foundation models te maken. Wanneer je een aangepast (applicatie) inference profile aanmaakt, genereert AWS een unieke ARN die geen informatie over de modelnaam bevat:

arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123def456

De inference profile mapping-functie van LibreChat stelt je in staat om:

  1. Wijs gebruiksvriendelijke model-ID's toe aan aangepaste inference profile ARN's
  2. Routeer verzoeken via je aangepaste profielen terwijl je de detectie van modelmogelijkheden behoudt
  3. Gebruik omgevingsvariabelen voor veilig ARN-beheer

Waarom Custom Inference Profiles gebruiken?

VoordeelBeschrijving
Cross-Region Load BalancingVerdeel verzoeken automatisch over meerdere AWS-regio's
KostenallocatieTag en volg kosten per applicatie of team
DoorvoermanagementConfigureer toegewezen doorvoer voor uw applicaties
ComplianceRouteer verzoeken via specifieke regio's voor datalocatie
MonitoringVolg het gebruik per inferentieprofiel in CloudWatch

Vereisten

Voordat je begint, moet je ervoor zorgen dat je beschikt over:

  1. AWS-account met Bedrock-toegang ingeschakeld
  2. AWS CLI geïnstalleerd en geconfigureerd
  3. IAM-machtigingen:
    • bedrock:CreateInferenceProfile
    • bedrock:ListInferenceProfiles
    • bedrock:GetInferenceProfile
    • bedrock:InvokeModel / bedrock:InvokeModelWithResponseStream
  4. LibreChat met Bedrock endpoint geconfigureerd (zie AWS Bedrock Setup)

Aangepaste Inference-profielen maken

Belangrijk: Custom inference profiles kunnen alleen via API (AWS CLI, SDK, enz.) worden aangemaakt en kunnen niet worden aangemaakt vanuit de AWS Console.

Stap 1: Lijst met beschikbare System Inference Profiles

# List all inference profiles
aws bedrock list-inference-profiles --region us-east-1

# Filter for Claude models
aws bedrock list-inference-profiles --region us-east-1 \
  --query "inferenceProfileSummaries[?contains(inferenceProfileId, 'claude')]"

Stap 2: Maak een Custom Inference Profile

# Get the system inference profile ARN to copy from
export SOURCE_PROFILE_ARN=$(aws bedrock list-inference-profiles --region us-east-1 \
  --query "inferenceProfileSummaries[?inferenceProfileId=='us.anthropic.claude-3-7-sonnet-20250219-v1:0'].inferenceProfileArn" \
  --output text)

# Create your custom inference profile
aws bedrock create-inference-profile \
  --inference-profile-name "MyApp-Claude-3-7-Sonnet" \
  --description "Custom inference profile for my application" \
  --model-source copyFrom="$SOURCE_PROFILE_ARN" \
  --region us-east-1

Stap 3: Controleer de aanmaak

# List your custom profiles
aws bedrock list-inference-profiles --type-equals APPLICATION --region us-east-1

# Get details of a specific profile
aws bedrock get-inference-profile \
  --inference-profile-identifier "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123" \
  --region us-east-1

Methode 2: Python-script

import boto3

AWS_REGION = 'us-east-1'

def create_inference_profile(profile_name: str, source_model_id: str):
    """
    Create a custom inference profile for LibreChat.

    Args:
        profile_name: Name for your custom profile
        source_model_id: The system inference profile ID to copy from
                        (e.g., 'us.anthropic.claude-3-7-sonnet-20250219-v1:0')
    """
    bedrock = boto3.client('bedrock', region_name=AWS_REGION)

    profiles = bedrock.list_inference_profiles()
    source_arn = None
    for profile in profiles['inferenceProfileSummaries']:
        if profile['inferenceProfileId'] == source_model_id:
            source_arn = profile['inferenceProfileArn']
            break

    if not source_arn:
        raise ValueError(f"Source profile {source_model_id} not found")

    response = bedrock.create_inference_profile(
        inferenceProfileName=profile_name,
        description=f'Custom inference profile for {profile_name}',
        modelSource={'copyFrom': source_arn},
        tags=[
            {'key': 'Application', 'value': 'LibreChat'},
            {'key': 'Environment', 'value': 'Production'}
        ]
    )

    print(f"Created profile: {response['inferenceProfileArn']}")
    return response['inferenceProfileArn']

if __name__ == "__main__":
    create_inference_profile(
        "LibreChat-Claude-3-7-Sonnet",
        "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
    )
    create_inference_profile(
        "LibreChat-Claude-Sonnet-4-5",
        "us.anthropic.claude-sonnet-4-5-20250929-v1:0"
    )

LibreChat configureren

librechat.yaml Configuratie

Voeg de bedrock endpoint-configuratie toe aan je librechat.yaml. Zie AWS Bedrock Object Structure voor de volledige veldreferentie.

endpoints:
  bedrock:
    # List the models you want available in the UI
    models:
      - 'us.anthropic.claude-3-7-sonnet-20250219-v1:0'
      - 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
      - 'global.anthropic.claude-opus-4-5-20251101-v1:0'
    # Map model IDs to their custom inference profile ARNs
    inferenceProfiles:
      # Using environment variable (recommended for security)
      'us.anthropic.claude-3-7-sonnet-20250219-v1:0': '${BEDROCK_CLAUDE_37_PROFILE}'
      # Using direct ARN
      'us.anthropic.claude-sonnet-4-5-20250929-v1:0': 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123'
      # Another env variable example
      'global.anthropic.claude-opus-4-5-20251101-v1:0': '${BEDROCK_OPUS_45_PROFILE}'
    # Optional: Configure available regions for cross-region inference
    availableRegions:
      - 'us-east-1'
      - 'us-west-2'

Omgevingsvariabelen

Voeg je Bedrock-regio, AWS-authenticatie-instellingen en inference profile ARNs toe aan je .env bestand:

#===================================#
# AWS Bedrock Configuration         #
#===================================#

BEDROCK_AWS_DEFAULT_REGION=us-east-1

# Option 1: Use an AWS profile
BEDROCK_AWS_PROFILE=your-profile-name

# Option 2: Omit BEDROCK_AWS_PROFILE and Bedrock-specific static credentials
# to use the AWS SDK default credential provider chain.

# Option 3: Static Bedrock credentials, if profiles or IAM roles are not suitable
# BEDROCK_AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
# BEDROCK_AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
# BEDROCK_AWS_SESSION_TOKEN=your-session-token

# Option 4: Bedrock API key (bearer auth)
# BEDROCK_AWS_BEARER_TOKEN=your-bedrock-api-key

# Inference Profile ARNs
BEDROCK_CLAUDE_37_PROFILE=arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123
BEDROCK_OPUS_45_PROFILE=arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/def456

Logging instellen

Om te verifiëren dat je inference profiles correct worden gebruikt, schakel je AWS Bedrock model invocation logging in.

1. CloudWatch Log Group aanmaken

aws logs create-log-group \
  --log-group-name /aws/bedrock/model-invocations \
  --region us-east-1

2. Maak IAM-rol voor Bedrock-logging

Maak het trust policy-bestand (bedrock-logging-trust.json):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "bedrock.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "YOUR_ACCOUNT_ID"
        },
        "ArnLike": {
          "aws:SourceArn": "arn:aws:bedrock:us-east-1:YOUR_ACCOUNT_ID:*"
        }
      }
    }
  ]
}

Maak de rol aan:

aws iam create-role \
  --role-name BedrockLoggingRole \
  --assume-role-policy-document file://bedrock-logging-trust.json

Koppel CloudWatch Logs-machtigingen:

aws iam put-role-policy \
  --role-name BedrockLoggingRole \
  --policy-name BedrockLoggingPolicy \
  --policy-document '{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "logs:CreateLogStream",
          "logs:PutLogEvents"
        ],
        "Resource": "arn:aws:logs:us-east-1:YOUR_ACCOUNT_ID:log-group:/aws/bedrock/model-invocations:*"
      }
    ]
  }'

Maak een S3-bucket aan voor grote data (vereist):

aws s3 mb s3://bedrock-logs-YOUR_ACCOUNT_ID --region us-east-1

aws iam put-role-policy \
  --role-name BedrockLoggingRole \
  --policy-name BedrockS3Policy \
  --policy-document '{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": ["s3:PutObject"],
        "Resource": "arn:aws:s3:::bedrock-logs-YOUR_ACCOUNT_ID/*"
      }
    ]
  }'

3. Schakel Model Invocation Logging in

aws bedrock put-model-invocation-logging-configuration \
  --logging-config '{
    "cloudWatchConfig": {
      "logGroupName": "/aws/bedrock/model-invocations",
      "roleArn": "arn:aws:iam::YOUR_ACCOUNT_ID:role/BedrockLoggingRole",
      "largeDataDeliveryS3Config": {
        "bucketName": "bedrock-logs-YOUR_ACCOUNT_ID",
        "keyPrefix": "large-data"
      }
    },
    "textDataDeliveryEnabled": true,
    "imageDataDeliveryEnabled": true,
    "embeddingDataDeliveryEnabled": true
  }' \
  --region us-east-1

Controleer of logging is ingeschakeld:

aws bedrock get-model-invocation-logging-configuration --region us-east-1

Je configuratie verifiëren

Logs bekijken via CLI

Nadat je een verzoek hebt gedaan via LibreChat, controleer de logs:

# Tail logs in real-time
aws logs tail /aws/bedrock/model-invocations --follow --region us-east-1

# View recent logs
aws logs tail /aws/bedrock/model-invocations --since 5m --region us-east-1

Waar je op moet letten

Zoek in de loguitvoer naar het veld modelId:

{
  "timestamp": "2026-01-16T16:56:15Z",
  "accountId": "123456789012",
  "region": "us-east-1",
  "requestId": "a8b9d8c9-87b3-41ea-8a02-e8bfdba7782f",
  "operation": "ConverseStream",
  "modelId": "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123",
  "inferenceRegion": "us-west-2"
}

Succesindicatoren:

  • modelId toont je aangepaste inference profile ARN (bevat application-inference-profile)
  • inferenceRegion kan variëren (dit toont aan dat cross-region routing werkt)

Als mapping niet werkt:

  • modelId zal de onbewerkte model-ID tonen in plaats van de ARN

Logs bekijken via AWS Console

  1. Open CloudWatch in de AWS Console
  2. Navigeer naar Logs > Log groups
  3. Selecteer /aws/bedrock/model-invocations
  4. Klik op de nieuwste logstream
  5. Zoek naar je inference profile ID

Gebruik monitoren

CloudWatch-metrieken

Bekijk Bedrock-statistieken in CloudWatch:

aws cloudwatch list-metrics --namespace AWS/Bedrock --region us-east-1

AWS Console

  1. Bedrock Console > Inference profiles > Application tab
  2. Klik op je aangepaste profiel
  3. Bekijk aanroepstatistieken en gebruiksgegevens

Probleemoplossing

Veelvoorkomende problemen

ProbleemOorzaakOplossing
Model niet herkendModel ontbreekt in models arrayVoeg de model-ID toe aan models in librechat.yaml
ARN wordt niet gebruiktModel-ID komt niet overeenZorg ervoor dat de model-ID in inferenceProfiles exact overeenkomt met wat er in models staat
Omgevingsvariabele niet opgelostTypefout of niet ingesteldControleer het .env bestand en zorg ervoor dat de variabelenaam overeenkomt met ${VAR_NAME}
Toegang geweigerdOntbrekende IAM-rechtenVoeg bedrock:InvokeModel* rechten toe voor de inference profile ARN
Toegang tot model geweigerdModelovereenkomst ontbreekt of wordt doorgevoerdAccepteer de Bedrock-modelovereenkomst en wacht tot de beschikbaarheid is doorgevoerd
Profiel niet gevondenVerkeerde regioZorg ervoor dat je profielen aanmaakt/gebruikt in dezelfde regio

Verspreiding van de Model Access Agreement

Het aanmaken van een application inference profile schakelt niet automatisch het onderliggende foundation model in uw AWS-account in. Als de modeltoegang zojuist is ingeschakeld, heeft AWS mogelijk ook een korte propagatietijd nodig voordat verzoeken via het inference profile slagen.

Dit kan verschijnen als een AccessDeniedException, zelfs wanneer het inference profile bestaat en je IAM-rol over bedrock:InvokeModel rechten beschikt. De foutmelding kan aws-marketplace:ViewSubscriptions of aws-marketplace:Subscribe vermelden, of je vragen om het na een paar minuten opnieuw te proberen.

Controleer de beschikbaarheid van het onderliggende model voordat je de LibreChat-mapping debugt:

aws bedrock get-foundation-model-availability \
  --region us-east-1 \
  --model-id us.anthropic.claude-sonnet-4-5-20250929-v1:0

Zoek naar:

  • agreementAvailability.status ingesteld op AVAILABLE
  • authorizationStatus ingesteld op AUTHORIZED
  • entitlementAvailability ingesteld op AVAILABLE
  • regionAvailability ingesteld op AVAILABLE

Als de overeenkomst ontbreekt, accepteer dan de modelovereenkomst in de Bedrock console of met een AWS principal die Bedrock-modelovereenkomsten en Marketplace-abonnementen kan beheren. Nadat de status is gewijzigd naar AVAILABLE, wacht je een paar minuten en probeer je opnieuw het application inference profile aan te roepen.

Debug-checklist

  1. Model ID staat in de models array
  2. Model ID in inferenceProfiles komt exact overeen (hoofdlettergevoelig)
  3. Omgevingsvariabele is ingesteld (indien de ${VAR} syntaxis wordt gebruikt)
  4. AWS-referenties hebben toestemming om het inference profile aan te roepen
  5. De onderliggende basismodelovereenkomst is AVAILABLE in Bedrock
  6. LibreChat is opnieuw opgestart na configuratiewijzigingen

Controleer het laden van de configuratie

Controleer of je configuratie correct wordt gelezen door de serverlogs te bekijken wanneer LibreChat opstart.

Volledig voorbeeld

librechat.yaml

version: 1.3.5

endpoints:
  bedrock:
    models:
      - 'us.anthropic.claude-3-7-sonnet-20250219-v1:0'
      - 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
      - 'global.anthropic.claude-opus-4-5-20251101-v1:0'
      - 'us.amazon.nova-pro-v1:0'
    inferenceProfiles:
      'us.anthropic.claude-3-7-sonnet-20250219-v1:0': '${BEDROCK_CLAUDE_37_PROFILE}'
      'us.anthropic.claude-sonnet-4-5-20250929-v1:0': '${BEDROCK_SONNET_45_PROFILE}'
      'global.anthropic.claude-opus-4-5-20251101-v1:0': '${BEDROCK_OPUS_45_PROFILE}'
    availableRegions:
      - 'us-east-1'
      - 'us-west-2'

.env

# AWS Bedrock
BEDROCK_AWS_DEFAULT_REGION=us-east-1
BEDROCK_AWS_PROFILE=your-profile-name
# Or use a Bedrock API key instead:
# BEDROCK_AWS_BEARER_TOKEN=your-bedrock-api-key

# Inference Profiles
BEDROCK_CLAUDE_37_PROFILE=arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123
BEDROCK_SONNET_45_PROFILE=arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/def456
BEDROCK_OPUS_45_PROFILE=arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/ghi789

Snelle installatiescript

#!/bin/bash

REGION="us-east-1"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)

# Create inference profiles
for MODEL in "us.anthropic.claude-3-7-sonnet-20250219-v1:0" "us.anthropic.claude-sonnet-4-5-20250929-v1:0"; do
  PROFILE_NAME="LibreChat-${MODEL//[.:]/-}"
  SOURCE_ARN=$(aws bedrock list-inference-profiles --region $REGION \
    --query "inferenceProfileSummaries[?inferenceProfileId=='$MODEL'].inferenceProfileArn" \
    --output text)
  if [ -n "$SOURCE_ARN" ]; then
    echo "Creating profile for $MODEL..."
    aws bedrock create-inference-profile \
      --inference-profile-name "$PROFILE_NAME" \
      --model-source copyFrom="$SOURCE_ARN" \
      --region $REGION
  fi
done

# List created profiles
echo ""
echo "Your custom inference profiles:"
aws bedrock list-inference-profiles --type-equals APPLICATION --region $REGION \
  --query "inferenceProfileSummaries[].{Name:inferenceProfileName,ARN:inferenceProfileArn}" \
  --output table

Hoe is deze gids?