A seguirPróximo guia
Contagem de tokens e preços de API LLM
Técnico
GUIA Técnico
To estimate LLM API costs, multiply the tokens each request sends and receives by the provider's per-token prices, then scale by the number of requests you expect.
Ouça este guiaNarrado por IA · ~3 min
Doing this before launch prevents surprise bills and shows whether a feature can be priced profitably. It also shows which design choices, such as long conversation history, drive spend.
LLM APIs bill by the token. A token is a chunk of text that averages roughly four characters, or about three quarters of a word, in English. Other languages and code often need more tokens for the same meaning, and each provider's tokenizer counts a little differently. Prices are quoted per million tokens, with separate rates for input (everything you send) and output (everything the model generates). Output is usually priced several times higher than input. A reliable estimate follows five steps: 1. Define each task the feature performs. 2. Measure tokens per request using real sample prompts and the provider's tokenizer or token-counting endpoint. Count the system prompt, retrieved documents, conversation history, user input and expected output. 3. Estimate volume: active users times requests per user per day. 4. Multiply tokens by price and by volume. 5. Add overhead for retries, failed calls, evaluation runs and growth. Here is a worked example using hypothetical prices of $3 per million input tokens and $15 per million output tokens. A request with 2,000 input tokens costs $0.006 for input. Its 400 output tokens cost another $0.006, so the request costs $0.012. At 10,000 requests a day, that is $120 a day, or about $3,600 over a 30-day month, before overhead. The biggest estimating errors come from what people forget: - Most chat applications resend the conversation on every turn. Input grows with each message, so one long conversation costs far more than several short ones. - Retrieval-augmented features can add thousands of tokens of context to each call. - Reasoning models generate internal thinking tokens that are billed as output even when they are not shown. - Agents make many calls for each user action. Discounts change the math. Prompt caching lowers the price of repeated prefixes, and batch APIs discount work that can wait. Always check the provider's current pricing page, because rates change often.
A team building an email-drafting feature runs a batch of real test prompts through the tokenizer. It finds the system prompt makes up more than half of all input tokens, so it shortens the prompt before launch.
A chatbot forecast assumed one short prompt per turn and falls apart once the team notices that every turn resends the full conversation. The revised forecast caps history and summarizes older turns.
A nightly job that classifies tens of thousands of support tickets moves to a provider's discounted batch API. None of the results are needed immediately, so the delay costs nothing.
A startup budgeting for a reasoning model learns that hidden reasoning tokens are billed as output. Its estimate had counted only the visible answer, so it has to raise the per-request cost several times over.
Per-token prices have generally fallen for a given level of capability. Providers keep adding pricing options such as caching discounts, batch rates and tiered service levels. That makes LLM use cheaper but estimation more complicated, since the cheapest setup depends on latency needs and prompt structure. Reasoning and agent workloads are shifting the main cost from input length to output tokens and number of calls, so forecasts built on simple chat assumptions will go out of date quickly. Cost monitoring is likely to become a standard part of LLM tooling. Estimates will be revised continuously from logged usage rather than made once before launch.
Boletim informativo gratuito
Três histórias verificadas de IA a cada manhã de dia útil, escritas em linguagem simples. Gratuito para sempre, sem anúncios.
Um e-mail a cada dia útil. Cancele a inscrição com um clique. Nunca vendemos ou compartilhamos seu endereço.
Teste você mesmo
Feedback instantâneo sobre cada resposta e um certificado compartilhável com um ID verificável assim que você concluir um curso.
Apoie a educação gratuita em IA. O AI Understanding é uma organização sem fins lucrativos 501(c)(3) — sem anúncios, sem paywall, nunca. Faça uma doação
To estimate LLM API costs, multiply the tokens each request sends and receives by the provider's per-token prices, then scale by the number of requests you expect. Doing this before launch prevents surprise bills and shows whether a feature can be priced profitably. It also shows which design choices, such as long conversation history, drive spend.
Uma regra prática comum é cerca de quatro caracteres ou 0,75 palavras por token em inglês. Outras linguagens e códigos costumam usar mais tokens para o mesmo significado.
Os provedores cobram separadamente pela entrada e pela saída, e os tokens de saída geralmente têm preços várias vezes mais altos do que os tokens de entrada.
2.000 / 1.000.000 × US$ 3 = US$ 0,006. Dividir os tokens por um milhão antes de multiplicar pelo preço é o passo central em qualquer estimativa.
A maioria dos aplicativos de bate-papo reenvia toda a conversa a cada turno, de modo que a entrada aumenta a cada mensagem e a entrada total cresce aproximadamente com o quadrado da duração da conversa.
Os tokens de raciocínio são gerados pelo modelo, portanto, são cobrados como saída, mesmo que o usuário nunca os veja. Deixá-los de fora pode subestimar gravemente o custo.
Continue aprendendo
Mais guias escolhidos para este tópico
A seguirPróximo guia
Contagem de tokens e preços de API LLM
Técnico