> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moda.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Bedrock

> Using Moda with AWS Bedrock

## 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](/ingestion/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:

<CodeGroup>
  ```python Python theme={"dark"}
  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")
              }
          ]
      }
  )
  ```

  ```typescript Node.js theme={"dark"}
  import { BedrockRuntimeClient, InvokeModelCommand } from '@aws-sdk/client-bedrock-runtime';

  const client = new BedrockRuntimeClient({ region: 'us-east-1' });

  // 1. Make the Bedrock call
  const response = await client.send(new InvokeModelCommand({
    modelId: 'anthropic.claude-3-sonnet-20240229-v1:0',
    body: JSON.stringify({
      anthropic_version: 'bedrock-2023-05-31',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'Hello!' }]
    })
  }));

  const result = JSON.parse(new TextDecoder().decode(response.body));
  const assistantMessage = result.content[0].text;

  // 2. Send to Moda
  await fetch('https://moda-ingest.modas.workers.dev/v1/ingest', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_MODA_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      events: [
        {
          conversation_id: 'session-123',
          role: 'user',
          message: 'Hello!',
        },
        {
          conversation_id: 'session-123',
          role: 'assistant',
          message: assistantMessage,
          model: 'anthropic.claude-3-sonnet-20240229-v1:0',
          provider: 'bedrock',
          input_tokens: result.usage?.input_tokens,
          output_tokens: result.usage?.output_tokens,
        }
      ]
    })
  });
  ```
</CodeGroup>

## AWS Credentials

Bedrock uses standard AWS authentication. Configure credentials via:

| Method                | Description                                                |
| --------------------- | ---------------------------------------------------------- |
| Environment variables | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` |
| AWS credentials file  | `~/.aws/credentials`                                       |
| IAM roles             | Recommended for production (EC2, ECS, Lambda)              |
| AWS SSO               | For development environments                               |

## Supported Models

Bedrock provides access to models from multiple providers. Common models include:

| Provider  | Model ID                                  |
| --------- | ----------------------------------------- |
| Anthropic | `anthropic.claude-3-sonnet-20240229-v1:0` |
| Anthropic | `anthropic.claude-3-haiku-20240307-v1:0`  |
| Meta      | `meta.llama3-70b-instruct-v1:0`           |
| Mistral   | `mistral.mistral-large-2402-v1:0`         |

<Tip>
  See the [AWS Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html) for a full list of available models.
</Tip>

## Supported Features

| Feature                | Captured                         |
| ---------------------- | -------------------------------- |
| Invoke model           | Yes                              |
| Token usage            | Yes (when returned by the model) |
| Model name             | Yes                              |
| Conversation threading | Yes (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.

<Info>
  For full Direct API documentation, see the [Direct API guide](/ingestion/direct-api).
</Info>
