Skip to main content

Overview

AWS Bedrock provides access to foundation models from multiple providers (Anthropic Claude, Meta Llama, Mistral, etc.) through AWS infrastructure. Since the Moda SDK does not yet have automatic Bedrock support, use the Direct API to send your Bedrock conversation data to Moda.

Setup with Direct API

Make a Bedrock call as normal, then send the conversation data to Moda via the Direct API:
import boto3
import json
import requests

# 1. Make the Bedrock call
client = boto3.client("bedrock-runtime", region_name="us-east-1")

response = client.invoke_model(
    modelId="anthropic.claude-3-sonnet-20240229-v1:0",
    body=json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "max_tokens": 1024,
        "messages": [{"role": "user", "content": "Hello!"}]
    })
)

result = json.loads(response["body"].read())
assistant_message = result["content"][0]["text"]

# 2. Send to Moda
requests.post(
    "https://moda-ingest.modas.workers.dev/v1/ingest",
    headers={
        "Authorization": "Bearer YOUR_MODA_API_KEY",
        "Content-Type": "application/json"
    },
    json={
        "events": [
            {
                "conversation_id": "session-123",
                "role": "user",
                "message": "Hello!"
            },
            {
                "conversation_id": "session-123",
                "role": "assistant",
                "message": assistant_message,
                "model": "anthropic.claude-3-sonnet-20240229-v1:0",
                "provider": "bedrock",
                "input_tokens": result.get("usage", {}).get("input_tokens"),
                "output_tokens": result.get("usage", {}).get("output_tokens")
            }
        ]
    }
)

AWS Credentials

Bedrock uses standard AWS authentication. Configure credentials via:
MethodDescription
Environment variablesAWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
AWS credentials file~/.aws/credentials
IAM rolesRecommended for production (EC2, ECS, Lambda)
AWS SSOFor development environments

Supported Models

Bedrock provides access to models from multiple providers. Common models include:
ProviderModel ID
Anthropicanthropic.claude-3-sonnet-20240229-v1:0
Anthropicanthropic.claude-3-haiku-20240307-v1:0
Metameta.llama3-70b-instruct-v1:0
Mistralmistral.mistral-large-2402-v1:0
See the AWS Bedrock documentation for a full list of available models.

Supported Features

FeatureCaptured
Invoke modelYes
Token usageYes (when returned by the model)
Model nameYes
Conversation threadingYes (via conversation_id)

Troubleshooting

Data not appearing?
  • Verify your Moda API key is correct
  • Check that your AWS credentials are valid
  • Ensure you’re sending events to https://moda-ingest.modas.workers.dev/v1/ingest
Token usage missing?
  • Not all Bedrock models return token usage data. Check the model’s response format.
For full Direct API documentation, see the Direct API guide.