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

Bedrock-Inferenzprofile

Konfigurieren und verwenden Sie benutzerdefinierte AWS Bedrock-Inferenzprofile mit LibreChat für regionsübergreifenden Lastausgleich, Kostenzuordnung und Compliance-Kontrollen.

Dieser Leitfaden erklärt, wie Sie AWS Bedrock Custom Inference Profiles mit LibreChat konfigurieren und verwenden. Dies ermöglicht es Ihnen, Modellanfragen über benutzerdefinierte Application Inference Profiles zu leiten, um eine bessere Kontrolle, Kostenaufteilung und regionsübergreifenden Lastausgleich zu erreichen.

Übersicht

AWS Bedrock Inference-Profile ermöglichen es Ihnen, benutzerdefinierte Routing-Konfigurationen für Foundation Models zu erstellen. Wenn Sie ein benutzerdefiniertes (Anwendungs-)Inference-Profil erstellen, generiert AWS einen eindeutigen ARN, der keine Informationen zum Modellnamen enthält:

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

Die Inference-Profile-Mapping-Funktion von LibreChat ermöglicht es Ihnen:

  1. Ordnen Sie benutzerfreundliche Modell-IDs benutzerdefinierten Inference-Profile-ARNs zu
  2. Leiten Sie Anfragen über Ihre benutzerdefinierten Profile weiter, während Sie die Erkennung der Modellfähigkeiten beibehalten
  3. Verwenden Sie Umgebungsvariablen für eine sichere ARN-Verwaltung

Warum benutzerdefinierte Inferenzprofile verwenden?

VorteilBeschreibung
Regionsübergreifender LastenausgleichVerteilen Sie Anfragen automatisch auf mehrere AWS-Regionen
KostenzuordnungMarkieren und verfolgen Sie Kosten pro Anwendung oder Team
DurchsatzverwaltungKonfigurieren Sie dedizierten Durchsatz für Ihre Anwendungen
ComplianceLeiten Sie Anfragen zur Einhaltung der Datenresidenz durch spezifische Regionen
ÜberwachungVerfolgen Sie die Nutzung pro Inferenzprofil in CloudWatch

Voraussetzungen

Bevor Sie beginnen, stellen Sie sicher, dass Sie über Folgendes verfügen:

  1. AWS-Konto mit aktiviertem Bedrock-Zugriff
  2. AWS CLI installiert und konfiguriert
  3. IAM-Berechtigungen:
    • bedrock:CreateInferenceProfile
    • bedrock:ListInferenceProfiles
    • bedrock:GetInferenceProfile
    • bedrock:InvokeModel / bedrock:InvokeModelWithResponseStream
  4. LibreChat mit konfiguriertem Bedrock endpoint (siehe AWS Bedrock Setup)

Erstellen von benutzerdefinierten Inferenzprofilen

Wichtig: Benutzerdefinierte Inferenzprofile können nur über die API (AWS CLI, SDK usw.) erstellt werden und können nicht über die AWS-Konsole erstellt werden.

Schritt 1: Verfügbare System-Inference-Profile auflisten

# 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')]"

Schritt 2: Erstellen eines benutzerdefinierten 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

Schritt 3: Erstellung überprüfen

# 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-Skript

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"
    )

Konfiguration von LibreChat

librechat.yaml Konfiguration

Fügen Sie die bedrock endpoint-Konfiguration zu Ihrer librechat.yaml hinzu. Für eine vollständige Referenz der Felder siehe AWS Bedrock Object Structure.

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'

Umgebungsvariablen

Fügen Sie Ihre Bedrock-Region, die AWS-Authentifizierungseinstellungen und die Inference Profile ARNs zu Ihrer .env Datei hinzu:

#===================================#
# 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

Einrichten der Protokollierung

Um zu überprüfen, ob Ihre Inference Profiles korrekt verwendet werden, aktivieren Sie das AWS Bedrock Model Invocation Logging.

1. CloudWatch-Loggruppe erstellen

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

2. IAM-Rolle für Bedrock-Logging erstellen

Erstellen Sie die Trust-Policy-Datei (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:*"
        }
      }
    }
  ]
}

Erstellen Sie die Rolle:

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

CloudWatch Logs-Berechtigungen anhängen:

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:*"
      }
    ]
  }'

S3-Bucket für große Daten erstellen (erforderlich):

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. Model-Aufruf-Protokollierung aktivieren

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

Überprüfen Sie, ob die Protokollierung aktiviert ist:

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

Überprüfen Ihrer Konfiguration

Logs über die CLI anzeigen

Nachdem Sie eine Anfrage über LibreChat gestellt haben, überprüfen Sie die Protokolle:

# 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

Worauf Sie achten sollten

Suchen Sie in der Protokollausgabe nach dem Feld 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"
}

Erfolgsindikatoren:

  • modelId zeigt Ihr benutzerdefiniertes Inference-Profile-ARN (enthält application-inference-profile)
  • inferenceRegion kann variieren (zeigt, dass das Cross-Region-Routing funktioniert)

Falls das Mapping nicht funktioniert:

  • modelId zeigt die rohe Modell-ID anstelle des ARN an

Protokolle über die AWS-Konsole anzeigen

  1. Öffnen Sie CloudWatch in der AWS Console
  2. Navigieren Sie zu Logs > Log groups
  3. Wählen Sie /aws/bedrock/model-invocations
  4. Klicken Sie auf den neuesten Log-Stream
  5. Suchen Sie nach Ihrer Inference Profile ID

Nutzung überwachen

CloudWatch-Metriken

Bedrock-Metriken in CloudWatch anzeigen:

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

AWS-Konsole

  1. Bedrock Console > Inference profiles > Tab Application
  2. Klicken Sie auf Ihr benutzerdefiniertes Profil
  3. Aufrufmetriken und Nutzungsstatistiken anzeigen

Fehlerbehebung

Häufige Probleme

ProblemUrsacheLösung
Modell nicht erkanntFehlendes Modell im models-ArrayFügen Sie die Modell-ID zu models in der librechat.yaml hinzu
ARN wird nicht verwendetModell-ID stimmt nicht übereinStellen Sie sicher, dass die Modell-ID in inferenceProfiles exakt mit der in models übereinstimmt
Umgebungsvariable nicht aufgelöstTippfehler oder nicht gesetztÜberprüfen Sie die .env-Datei und stellen Sie sicher, dass der Variablenname mit ${VAR_NAME} übereinstimmt
Zugriff verweigertFehlende IAM-BerechtigungenFügen Sie bedrock:InvokeModel*-Berechtigungen für den ARN des Inference-Profils hinzu
Modellzugriff verweigertModellvereinbarung fehlt oder wird noch propagiertAkzeptieren Sie die Bedrock-Modellvereinbarung und warten Sie, bis die Verfügbarkeit propagiert wurde
Profil nicht gefundenFalsche RegionStellen Sie sicher, dass Sie Profile in derselben Region erstellen/verwenden

Weitergabe der Modellzugriffsvereinbarung

Das Erstellen eines Application Inference Profile aktiviert nicht automatisch das zugrunde liegende Foundation Model in Ihrem AWS-Konto. Wenn der Modellzugriff gerade erst aktiviert wurde, benötigt AWS möglicherweise auch ein kurzes Zeitfenster für die Bereitstellung, bevor Anfragen über das Inference Profile erfolgreich verarbeitet werden können.

Dies kann als AccessDeniedException erscheinen, selbst wenn das Inference-Profil existiert und Ihre IAM-Rolle über bedrock:InvokeModel-Berechtigungen verfügt. Der Fehler erwähnt möglicherweise aws-marketplace:ViewSubscriptions, aws-marketplace:Subscribe oder fordert Sie auf, es nach einigen Minuten erneut zu versuchen.

Überprüfen Sie die Verfügbarkeit des zugrunde liegenden Modells, bevor Sie das LibreChat-Mapping debuggen:

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

Suche nach:

  • agreementAvailability.status auf AVAILABLE gesetzt
  • authorizationStatus auf AUTHORIZED gesetzt
  • entitlementAvailability auf AVAILABLE gesetzt
  • regionAvailability auf AVAILABLE gesetzt

Falls die Vereinbarung fehlt, akzeptieren Sie die Modellvereinbarung in der Bedrock-Konsole oder mit einem AWS-Principal, der Bedrock-Modellvereinbarungen und Marketplace-Abonnements verwalten kann. Nachdem sich der Status auf AVAILABLE geändert hat, warten Sie ein paar Minuten und versuchen Sie erneut, das Application Inference Profile aufzurufen.

Debug-Checkliste

  1. Die Model ID befindet sich im models Array
  2. Die Model ID in inferenceProfiles stimmt exakt überein (Groß-/Kleinschreibung wird beachtet)
  3. Umgebungsvariable ist gesetzt (bei Verwendung der ${VAR}-Syntax)
  4. AWS-Anmeldeinformationen verfügen über die Berechtigung, das Inferenzprofil aufzurufen
  5. Die zugrunde liegende Basismodell-Vereinbarung ist in Bedrock AVAILABLE.
  6. LibreChat wurde nach Konfigurationsänderungen neu gestartet

Konfigurationsladung überprüfen

Überprüfen Sie, ob Ihre Konfiguration korrekt gelesen wird, indem Sie die Server-Logs beim Start von LibreChat untersuchen.

Vollständiges Beispiel

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

Schnelleinrichtungsskript

#!/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

Wie finden Sie diese Anleitung?