User Tracking

User tracking allows you to identify your users, track their cost, conversations and more.

User tracking

The strict minimum to enable user tracking is to report a userId, however you can report any property you'd like such as an email or name using an userProps object.

Tracking users with the SDK

2

Simplest: Identify OpenAI calls

The easiest way to get started tracking users is to send user data with every OpenAI API call.

const res = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "Hello" }],
user: "user123",
userProps: { name: "John" },
})
chat_completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello"}],
user_id="user123",
user_props={ "name": "John" }
)

If you're using LangChain, you can similarly pass user data as metadata.

const chat = new ChatOpenAI({
callbacks: [new LLMonitorHandler()],
});
const res = await chat.call([new HumanMessage("Hello!")], {
metadata: {
userId: "123",
userProps: { name: "John" },
},
});
handler = LLMonitorCallbackHandler()
chat = ChatOpenAI(
callbacks=[handler],
metadata={
"user_id": "user123"
}, # Assigning user ids to models in the metadata
)
3

Advanced: Inject user into context

When tracking traces, you can inject user data into the context using the identify methods. This will cascade down to all the child runs.

async function TranslatorAgent(input) {
// Some AI queries
// Everything done in this context will be tracked with the user
}
// Wrap the agent with the monitor
const translate = monitor.wrapAgent(TranslatorAgent)
// Using identify to inject the user into the context
const res = await translate(`Hello, what's your name?`)
.identify("user123", { email: "email@example.org" })
from llmonitor import users
def my_agent():
# Some AI queries
# Everything done in this context will be tracked with the user
def main():
# Using identify to inject the user into the context
with users.identify('user123', user_props={"email": "email@example.org"}):
my_agent()

Tracking users on the frontend

If you are tracking chat messages on the frontend, you can use the identify method of the monitor to identify the user there.

monitor.identify("user123", {
email: 'test@example.org'
})

User Properties

While you can track any property you'd like, we recommend using the following ones:

PropertyDescription
nameName of the user
emailEmail of the user
avatarURL to an avatar
groupGroup or company ID the user belongs to

Questions? We're here to help.