You can send custom metadata along with your requests in Portkey, which can later be used for auditing or filtering logs. You can pass any number of keys, all values should be of type string with max-length as 128 characters.

Adding Metadata to Requests

The metadata object accepts a JSON - Portkey will then parse it and let you filter on your metadata.

    "_user": "userid123",
    "environment": "production",
    "organisation": "orgid123",
    "prompt": "summarisationPrompt",
    "foo": "abc",
    "bar": "def"

_user is a special key

This key is used to provide user analytics in the analytics section of Portkey app.

If you pass the user key in the OpenAI request body, we will automatically also store it in Portkey's _user key. If both the OpenAI request body user key and the Portkey metadata _user key are passed, then only the metadata _user key will be stored.

Send metadata along with your requests as shown below:

import {Portkey} from 'portkey-ai'

const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",
    virtualKey: "OPENAI_VIRTUAL_KEY"

const requestOptions = { 
    metadata: {
        "_user": "USER_ID",
        "organisation": "ORG_ID",
        "request_id": "1729"

const chatCompletion = await{
    messages: [{ role: 'user', content: 'Who was ariadne?' }],
    model: 'gpt-4',
}, requestOptions);


Using Metadata

See metadata summary on the Analytics page:

Just head over to the metadata tab and you should see all of your keys in the filter.

Filter requests according to your custom metadata on the Logs page

Select the "Meta" filter and choose the key:value pairs you want to filter the requests on. All the custom keys you have sent with any of your requests should show up here.

Last updated