Async Integration

Helicone uses OpenLLMetry to capture traces when using async logging. Currently OpenLLMetry doesn’t support reporting message bodies for AWS Bedrock, we’re currently working with them to add proper support for reporting Bedrock traces.them to add proper support for reporting Bedrock traces.

1

Create an account + Generate an API Key

Log into Helicone or create an account. Once you have an account, you can generate an API key.

2

Set API keys as environment variables

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>
3

Install necessary packages

Ensure you have the necessary packages installed in your JavaScript project:

npm install @helicone/async @aws-sdk/client-bedrock-runtime
4

Import required modules and initialize Helicone Logger

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();
5

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,
  },
});
6

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",
});
7

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();

Complete Example

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

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.