Proxy Integration
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.
Set HELICONE_API_KEY as an environment variable
HELICONE_API_KEY=<your API key>
Run the Bedrock command with the Helicone Proxy
import boto3
import json
import os
client = boto3.client("bedrock-runtime", region_name="ap-south-1",
endpoint_url="https://bedrock.helicone.ai/v1/ap-south-1")
model_id = "meta.llama3-8b-instruct-v1:0"
event_system = client.meta.events
def process_custom_arguments(params, context, **kwargs):
if (custom_headers := params.pop("custom_headers", None)):
context["custom_headers"] = custom_headers
def add_custom_header_before_call(model, params, request_signer, **kwargs):
params['headers']['Helicone-Auth'] = f'Bearer {os.getenv("HELICONE_API_KEY")}'
params['headers']['aws-access-key'] = '<AWS ACCESS KEY>'
params['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
params['headers']['aws-session-token'] = '<AWS SESSION TOKEN>'
if (custom_headers := params.pop("custom_headers", None)):
params['headers'].update(custom_headers)
headers = params['headers']
print(f'param headers: {headers}')
event_system.register("before-parameter-build.bedrock-runtime.InvokeModel",
process_custom_arguments)
event_system.register('before-call.bedrock-runtime.InvokeModel',
add_custom_header_before_call)
body = {
"prompt": "Hello, world!",
"max_gen_len": 512,
"temperature": 0.5,
"top_p": 0.9
}
response = client.invoke_model(
body=json.dumps(body),
modelId=model_id,
accept="application/json",
contentType="application/json",
)
model_response = json.loads(response["body"].read())
print(model_response)
Async Integration
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.
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>
Install necessary packages
Ensure you have the necessary packages installed in your JavaScript project:
pip install helicone-async boto3
Import required modules and initialize Helicone Logger
from helicone_async import HeliconeAsyncLogger
import boto3
import json
import os
logger = HeliconeAsyncLogger(api_key=os.getenv("HELICONE_API_KEY"))
logger.init()
Configure AWS Bedrock client
client = boto3.client("bedrock-runtime", region_name=os.getenv("AWS_REGION"))
Send the request and handle the response
response = client.invoke_model(
body=json.dumps(body),
modelId=model_id,
accept="application/json",
contentType="application/json",
)
model_response = json.loads(response["body"].read())
print(model_response)
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.