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

# Bedrock

## 1. Installation

Install the traceAI and Bedrock packages.

<CodeGroup>
  ```bash Python theme={null}
  pip install traceAI-bedrock
  pip install boto3
  ```

  ```bash JS/TS theme={null}
  npm install @traceai/bedrock @traceai/fi-core @opentelemetry/instrumentation
  ```
</CodeGroup>

***

## 2. Environment Configuration

Set up your environment variables to authenticate with both FutureAGI and AWS services.

<CodeGroup>
  ```python Python theme={null}
  import os

  os.environ["AWS_ACCESS_KEY_ID"] = "your-aws-access-key-id"
  os.environ["AWS_SECRET_ACCESS_KEY"] = "your-aws-secret-access-key"
  os.environ["FI_API_KEY"] = "your-futureagi-api-key"
  os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
  ```

  ```typescript JS/TS theme={null}
  process.env.AWS_ACCESS_KEY_ID = "your-aws-access-key-id";
  process.env.AWS_SECRET_ACCESS_KEY = "your-aws-secret-access-key";
  process.env.FI_API_KEY = "your-futureagi-api-key";
  process.env.FI_SECRET_KEY = "your-futureagi-secret-key";
  ```
</CodeGroup>

***

## 3. Initialize Trace Provider

Set up the trace provider to create a new project in FutureAGI, establish telemetry data pipelines .

<CodeGroup>
  ```python Python theme={null}
  from fi_instrumentation import register
  from fi_instrumentation.fi_types import ProjectType

  trace_provider = register(
      project_type=ProjectType.OBSERVE,
      project_name="bedrock_project",
  )
  ```

  ```typescript JS/TS theme={null}
  import { register, ProjectType } from "@traceai/fi-core";

  const tracerProvider = register({
      project_type: ProjectType.OBSERVE,
      project_name: "bedrock_project",
  });
  ```
</CodeGroup>

***

## 4. Configure Bedrock Instrumentation

Instrument your Project with Bedrock Instrumentor. This step ensures that all interactions with the Bedrock are tracked and monitored.

<CodeGroup>
  ```python Python theme={null}
  from traceai_bedrock import BedrockInstrumentor

  BedrockInstrumentor().instrument(tracer_provider=trace_provider)
  ```

  ```typescript JS/TS theme={null}
  import { BedrockInstrumentation } from "@traceai/bedrock";
  import { registerInstrumentations } from "@opentelemetry/instrumentation";

  const bedrockInstrumentation = new BedrockInstrumentation({});

  registerInstrumentations({
      instrumentations: [bedrockInstrumentation],
      tracerProvider: tracerProvider,
  });
  ```
</CodeGroup>

***

## 5. Create Bedrock Components

Set up your Bedrock client and use your application as you normally would. Our Instrumentor will automatically trace and send the telemetry data to our platform.

<CodeGroup>
  ```python Python theme={null}
  import boto3

  client = boto3.client(
      service_name="bedrock",
      region_name="your-region",
      aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
      aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
  )
  ```

  ```typescript JS/TS theme={null}
  import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";

  const client = new BedrockRuntimeClient({
      region: "your-region",
  });
  ```
</CodeGroup>

***

## 6. Execute

Run your Bedrock application.

<CodeGroup>
  ```python Python theme={null}
  def converse_with_claude():
      system_prompt = [{"text": "You are an expert at creating music playlists"}]
      messages = [
          {
              "role": "user",
              "content": [{"text": "Hello, how are you?"}, {"text": "What's your name?"}],
          }
      ]
      inference_config = {"maxTokens": 1024, "temperature": 0.0}

      try:
          response = client.converse(
              modelId="model_id",
              system=system_prompt,
              messages=messages,
              inferenceConfig=inference_config,
          )
          out = response["output"]["message"]
          messages.append(out)
          print(out)
      except Exception as e:
          print(f"Error: {str(e)}")

  if __name__ == "__main__":
      converse_with_claude()
  ```

  ```typescript JS/TS theme={null}
  import { ConverseCommand } from "@aws-sdk/client-bedrock-runtime";

  async function converseWithClaude() {
      const system = [{ text: "You are an expert at creating music playlists" }];
      const messages = [
          {
              role: "user",
              content: [{ text: "Hello, how are you?" }, { text: "What's your name?" }],
          },
      ];
      const inferenceConfig = { maxTokens: 1024, temperature: 0.0 };

      try {
          const response = await client.send(
              new ConverseCommand({
                  modelId: "model_id",
                  system,
                  messages,
                  inferenceConfig,
              })
          );
          const out = response.output?.message;
          if (out) {
              console.log(out);
          }
      } catch (e) {
          console.error("Error:", e);
      }
  }

  converseWithClaude();
  ```
</CodeGroup>
