What is a custom property?

A custom property is a key-value pair that you can add to an LLM log when sending an LLM log to Keywords AI. It can help you tag and filter LLM logs.

Why use custom properties?

  • Tag and filter LLM logs in your way.
  • Add any additional information to your logs.

How to pass custom properties

You can pass custom properties to Keyworeds AI by adding a metadata field to the request body.

Here is an example of how to send 2 custom metadata to Keywords AI in the OpenAI Python SDK.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.keywordsai.co/api/",
    api_key="YOUR_KEYWORDSAI_API_KEY",
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Tell me a long story"}
    ],
    extra_body={
        "metadata": {
            "sample_key": "sample_value",
            "session_id": "abc789"
        }
    }
)

Filter dashboard metrics

To use custom properties for filtering in the dashboard, you need to index the custom properties in the platform, otherwise the custom properties will not be available for filtering.

Filtering by custom properties in the dashboard is only available for Team plan and Enterprise plan users.

Index custom properties for filtering

Go to Customer Properties page and click on the Create index button to index custom properties you want to filter by.

Filters in dashboard

After indexing the custom properties, you can filter the dashboard metrics by the custom properties.

Filter Logs

You can also filter logs by custom properties on the Logs page. Just click on the Filter button to filter the logs by the Custom properties.

Update custom properties

You can also update the custom properties of a log through the API.

Here are the steps to update the custom properties of a log:

1

Get unique_id of the log

You need first to get the unique_id of the log you want to update. You can get the unique_id from the Logs list endpoint. OR you can get the unique_id from Logs page’s Log ID column.

2

Send the API request

Pass the unique_id to the /api/request-logs/batch-update/ endpoint with the metadata and notes you want to update.

import requests

url = "https://api.keywordsai.co/api/request-logs/batch-update/"
api_key = "YOUR_KEY" # Replace with your actual Keywords AI API key
data = {
    "logs": [
        {   "unique_id": "xxxxxx",
            "metadata": {
                "metadata_key": "updated_value"
            },
            "note": "updated note"
        }
        # other logs to update
    ]
}
headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())