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

# AWS Bedrock JavaScript SDK Integration

> Learn how to integrate AWS Bedrock with Helicone using JavaScript.

<Warning>
  This integration method is maintained but no longer actively developed. For the best experience and latest features, use our new [AI Gateway](/gateway/overview) with unified API access to 100+ models.
</Warning>

# Proxy Integration

<Steps>
  <Step title="Create an account + Generate an API Key">
    Log into [helicone](https://www.helicone.ai) or create an account. Once you have an account, you
    can generate an [API key](https://us.helicone.ai/settings/api-keys).
  </Step>

  <Step title="Set HELICONE_API_KEY as an environment variable">
    ```javascript theme={null}
    HELICONE_API_KEY=<your API key>
    ```
  </Step>

  <Step title="Run the Bedrock command with the Helicone Proxy">
    ```javascript theme={null}
    import {
      BedrockRuntimeClient,
      InvokeModelCommand,
    } from "@aws-sdk/client-bedrock-runtime";

    const REGION = "ap-south-1"; // or any other region
    const client = new BedrockRuntimeClient({
      region: REGION,
      endpoint: `https://bedrock.helicone.ai/v1/${REGION}`,
    });

    // Add middleware to inject custom headers
    client.middlewareStack.add(
      (next, context) => async (args: any) => {
        if (!args.request.headers) {
          args.request.headers = {};
        }

        // Add your custom headers here
        args.request.headers["Helicone-Auth"] = `Bearer ${process.env.HELICONE_API_KEY}`;
        args.request.headers["aws-access-key"] = "<AWS ACCESS KEY>";
        args.request.headers["aws-secret-key"] = "<AWS SECRET KEY>";
        // optionally, you can pass the aws-session-token instead of access and secret key if you are using temporary credentials
        args.request.headers["aws-session-token"] = "<AWS SESSION TOKEN>";

        return next(args);
      },
      {
        step: "build",
        name: "addCustomHeaders",
      }
    );

    const model_id = "meta.llama3-8b-instruct-v1:0";

    export const main = async () => {
      const command = new InvokeModelCommand({
        modelId: model_id,
        body: JSON.stringify({
          prompt: "Hello, world!",
          max_gen_len: 512,
          temperature: 0.5,
          top_p: 0.9,
        }),
        accept: "application/json",
        contentType: "application/json",
      });

      const response = await client.send(command);
      console.log(response.body?.transformToString());
    };

    main();
    ```
  </Step>
</Steps>

# Async Integration

<Steps>
  <Step title="Create an account + Generate an API Key">
    Log into [Helicone](https://www.helicone.ai) or create an account. Once you have an account, you
    can generate an [API key](https://us.helicone.ai/settings/api-keys).
  </Step>

  <Step title="Set API keys as environment variables">
    ```bash theme={null}
    export HELICONE_API_KEY=<your Helicone API key>
    export AWS_ACCESS_KEY_ID=<your AWS access key ID>
    export AWS_SECRET_ACCESS_KEY=<your AWS secret access key>
    export AWS_REGION=<your AWS region>
    ```
  </Step>

  <Step title="Install necessary packages">
    Ensure you have the necessary packages installed in your JavaScript project:

    ```bash theme={null}
    npm install @helicone/async @aws-sdk/client-bedrock-runtime
    ```
  </Step>

  <Step title="Import required modules and initialize Helicone Logger">
    ```javascript theme={null}
    import { HeliconeAsyncLogger } from "@helicone/async";
    import * as bedrock from "@aws-sdk/client-bedrock-runtime";
    import util from "util";

    const logger = new HeliconeAsyncLogger({
      apiKey: process.env.HELICONE_API_KEY,
      providers: {
        bedrock: bedrock,
      },
      baseUrl: "https://api.helicone.ai/v1/trace/log",
    });
    logger.init();
    ```
  </Step>

  <Step title="Configure AWS Bedrock client">
    ```javascript theme={null}
    const client = new bedrock.BedrockRuntimeClient({
      region: process.env.AWS_REGION,
      credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      },
    });
    ```
  </Step>

  <Step title="Create a command for the Bedrock model">
    ```javascript theme={null}
    const command = new bedrock.ConverseCommand({
      messages: [
        {
          role: "user",
          content: [{ text: "Why is the unix epoch measured from 1970?" }],
        },
      ],
      modelId: "meta.llama2-13b-chat-v1",
    });
    ```
  </Step>

  <Step title="Send the request and handle the response">
    ```javascript theme={null}
    async function sendRequest() {
      try {
        const data = await client.send(command);
        console.log(
          "Response:\n",
          util.inspect(data, { showHidden: false, depth: null, colors: true })
        );
      } catch (error) {
        console.error("Error:", error);
      }
    }

    sendRequest();
    ```
  </Step>
</Steps>

### Complete Async Example

Here's a complete example that puts all the steps together:

```javascript theme={null}
import { HeliconeAsyncLogger } from "@helicone/async";
import * as bedrock from "@aws-sdk/client-bedrock-runtime";
import util from "util";

// Initialize Helicone Logger
const logger = new HeliconeAsyncLogger({
  apiKey: process.env.HELICONE_API_KEY,
  providers: {
    bedrock: bedrock,
  },
  baseUrl: "https://api.helicone.ai/v1/trace/log",
});
logger.init();

// Configure AWS Bedrock client
const client = new bedrock.BedrockRuntimeClient({
  region: process.env.AWS_REGION,
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  },
});

// Create a command for the Bedrock model
const command = new bedrock.ConverseCommand({
  messages: [
    {
      role: "user",
      content: [{ text: "Why is the unix epoch measured from 1970?" }],
    },
  ],
  modelId: "meta.llama2-13b-chat-v1",
});

// Send the request and handle the response
async function sendRequest() {
  try {
    const data = await client.send(command);
    console.log(
      "Response:\n",
      util.inspect(data, { showHidden: false, depth: null, colors: true })
    );
  } catch (error) {
    console.error("Error:", error);
  }
}

sendRequest();
```

This integration allows you to use AWS Bedrock with Helicone's async logging. The Helicone logger will automatically capture traces of your AWS Bedrock API calls, providing you with valuable insights and analytics through the Helicone dashboard.

For more information on using async logging, visit the [Async Logging documentation](/getting-started/integration-method/).
