[Python] How to estimate output usage tokens across different AI modalities (text, voice,...

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    I’m building a multi-modal AI platform that integrates various AI APIs for text (LLMs), voice, image, and video generation. Each service provider has different billing units — some charge per token, others by audio length, image resolution, or video duration.

    I want to create a unified credit system that maps all these different usage types (text tokens, seconds of audio, image count/resolution, video length) to a single currency for billing users.

    I know input token count can be approximated by assuming 1 token ≈ 4 characters / 0.75 words (based on OpenAI’s tokenizer), and I’m okay using that as a standard even though other providers tokenize differently.

    But how do I estimate output token count before making the request?

    My main challenge is estimating the output usage before sending the request to these APIs so I can:

    • Pre-authorize users based on their balance
    • Avoid running up costs when users don’t have enough tokens
    • Provide transparent cost estimates.

    Continue reading...

Compartilhe esta Página