Log token usage in your application

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.