The Nebuly SDK enables you to monitor all the requests made to:

Cohere and Anthropic models are also supported when using stream mode.

The process is straightforward, you just need to:

  • initialize the SDK with your API key
  • include the user_id in your original AWS Bedrock method calls.

You can then use the platform to analyze the results and get insights about your LLM users.

AI21 Text Models

  • Python

import nebuly

nebuly.init(api_key="<YOUR_NEBULY_API_KEY>")

import json

import boto3

bedrock = boto3.client(
    service_name="bedrock-runtime",
    aws_access_key_id="YOUR_AWS_ACCESS_KEY_ID",
    aws_secret_access_key="YOUR_AWS_SECRET_ACCESS_KEY",
)
body = json.dumps(
    {
        "prompt": "Who is the president of the United States of America?",
        "maxTokens": 200,
        "temperature": 0.5,
        "topP": 0.5,
    }
)

modelId = "ai21.j2-mid-v1"
accept = "application/json"
contentType = "application/json"

response = bedrock.invoke_model(
    body=body,
    modelId=modelId,
    accept=accept,
    contentType=contentType,
    # ... other optional aws bedrock kwargs
    # Nebuly additional kwargs
    user_id="<YOUR_USER_ID>",
)

You can find a detailed explanation of the allowed nebuly additional keyword arguments below:

user_id
string
required

An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

nebuly_tags
dict

Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for nebuly_tags, e.g. {"version": "v1.0.0"}. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.

nebuly_api_key
string

You can use this field to temporarily override the Nebuly API key for the selected model call. The interaction will be stored in the project associated with the provided API key.

Anthropic Text Models

  • Python

import nebuly

nebuly.init(api_key="<YOUR_NEBULY_API_KEY>")

import json

import boto3

bedrock = boto3.client(
    service_name="bedrock-runtime",
    aws_access_key_id="YOUR_AWS_ACCESS_KEY_ID",
    aws_secret_access_key="YOUR_AWS_SECRET_ACCESS_KEY",
)
body = json.dumps({
    "prompt": "\n\nHuman:explain black holes to 8th graders\n\nAssistant:",
    "max_tokens_to_sample": 300,
    "temperature": 0.1,
    "top_p": 0.9,
})

modelId = 'anthropic.claude-v2'
accept = "application/json"
contentType = "application/json"

response = bedrock.invoke_model(
    body=body,
    modelId=modelId,
    accept=accept,
    contentType=contentType,
    # ... other optional aws bedrock kwargs
    # Nebuly additional kwargs
    user_id="<YOUR_USER_ID>",
)

You can find a detailed explanation of the allowed nebuly additional keyword arguments below:

user_id
string
required

An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

nebuly_tags
dict

Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for nebuly_tags, e.g. {"version": "v1.0.0"}. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.

nebuly_api_key
string

You can use this field to temporarily override the Nebuly API key for the selected model call. The interaction will be stored in the project associated with the provided API key.

Cohere Text Models

  • Python

import nebuly

nebuly.init(api_key="<YOUR_NEBULY_API_KEY>")

import json

import boto3

bedrock = boto3.client(
    service_name="bedrock-runtime",
    aws_access_key_id="YOUR_AWS_ACCESS_KEY_ID",
    aws_secret_access_key="YOUR_AWS_SECRET_ACCESS_KEY",
)
body = json.dumps(
    {
        "prompt": "Say 'HI'",
    }
)

modelId = "cohere.command-text-v14"
accept = "application/json"
contentType = "application/json"

response = bedrock.invoke_model(
    body=body,
    modelId=modelId,
    accept=accept,
    contentType=contentType,
    # ... other optional aws bedrock kwargs
    # Nebuly additional kwargs
    user_id="<YOUR_USER_ID>",
)

You can find a detailed explanation of the allowed nebuly additional keyword arguments below:

user_id
string
required

An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

nebuly_tags
dict

Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for nebuly_tags, e.g. {"version": "v1.0.0"}. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.

nebuly_api_key
string

You can use this field to temporarily override the Nebuly API key for the selected model call. The interaction will be stored in the project associated with the provided API key.