Metadata and Custom Properties

How to add custom properties / metadata to usage tracking

Sometimes you want to track extra custom properties or metadata that you'll need. For example, you might want to store tracking IDs or you want to track more context.

To do this, you'll send a customProperties field in the POST body to the trackUsage API.

Then, when you're in the dashboard, you can filter by any of these custom properties!

Here's an example in Javascript with the manual tracking SDK:

const trackUsageResponse = await spryngtimeanalyticssdk.usageTracking.trackUsage({
    key: "companytest1",
    query: query,
    openAiResponse: chatCompletion,
    customProperties:{conversationId: "customer3", trackingId:"track-123"},
});

Here's an example in Python with the OpenAI wrapper:

completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "user", "content": "What is 1 + 1"}
    ],
    user="user_123456",
    conversation_id='testing1',
    custom_properties={"test": "test"}
)

Last updated