Maxim Logo
How toLog your application

Track token usage and costs

Learn how to efficiently track token usage and associated costs in your LLM application using Maxim's logging capabilities.

Code examples by language

Log token usage by including the usage object in your generation result:

generation.result({
    id: "chatcmpl-123",
    object: "chat.completion",
    created: Date.now(),
    model: "gpt-4o",
    choices: [{
        index: 0,
        message: {
            role: "assistant",
            content: "Apologies for the inconvenience. Can you please share your customer id?"
        },
        finish_reason: "stop"
    }],
    usage: {
        prompt_tokens: 100,
        completion_tokens: 50,
        total_tokens: 150
    }
});

Learn more about tracking generation results.

Custom pricing

Need different pricing for your models? Read more on custom pricing.

On this page