Track Usage API
This is the bread and butter API that you'll use to track usage
Last updated
This is the bread and butter API that you'll use to track usage
Last updated
If you're using one of our OpenAI or Azure OpenAI wrappers from the quickstart, this API is automatically implemented for you! No need to manually implement this
Note: One API request is one "message". What does that mean? It means if you send 3 trackUsage API requests for companyA, we'll count that as 3 different messages for companyA. So if you bill "per message", you'll bill them for 3 messages
Some key concepts to know:
key
(required) - This key is what your usage will be stored under. For B2B use cases, this is usually a customer name.
As an example, if your customer, companyA
has used 10 tokens, you would call the trackUsage API with company
as the key
query
(optional) - you can track the query you input into the LLM
tags
(optional) - you can add tags to usage for easy searching/filtering. In JSON array format (["test", "test2"]
)
For example, if you have a classification prompt, you can add the classification prompt
tag. And if you have a response prompt, you can add the response prompt
tag. Then you can easily filter!
conversationId
(optional) - If your product has conversations, you can use this to relate many requests to 1 conversation
For example, if you bill "$1 per conversation", a customer can have 6 messages/requests in one conversation. You would then call trackUsage with those 6 requests and set the conversationId
to the same thing.
openAiResponse
(optional) - If you use OpenAI, you can easily just pass in the completion/chat/embedding response here. We'll automatically handle it
usage
(optional) - If you don't use OpenAI, you'll want to use this to track token usage.
The general format looks like this
Some examples in Javascript:
Some examples in Python:
Successfully tracked usage