How to send custom properties in the code

We want to provide our users with the most flexibility to add any additional information to your logs, so we support sending custom properties in the code. You can add any key-value pair to the properties field for your reference.

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

Custom properties on the dashboard

After you send custom properties in the code, you can view them in the dashboard. Just click on the Filter button to filter the logs by the Custom properties.

Custom properties on the Logs page

On the Logs page, you can see the custom properties of each log in the side panel.

Filter logs by custom properties

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.