Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

LLM Prompt Costs: Build a Token and Cost Calculator in Colab

Estimate LLM API request costs in Colab by combining provider-specific input and output token counts with dated model rates—and understand what the calculation leaves out.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To estimate an LLM API request, count the input and output tokens for the specific provider and model, multiply each count by its matching price, and add the results. A small Google Colab calculator makes that arithmetic easy—but its result is an estimate, not a guaranteed invoice total. The count, billing categories, and rates all need to match the API request you actually send.

What am I billed for?

For a basic estimate using prices listed per million tokens, calculate:

As an Amazon Associate I earn from qualifying purchases.

((input_tokens × input_price_per_million) + (output_tokens × output_price_per_million)) / 1,000,000

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Input and output are separate billing dimensions, and their rates can differ. Some models also have distinct prices for cached input or other categories. Include those only when the provider’s current rate card and your request’s usage support them.

For a dated example, Google lists Gemini 3.8 Flash standard paid rates of $0.75 per million input tokens and $3.75 per million output tokens through December 31, 2026. The listed rates become $1.50 and $7.50, respectively, beginning January 1, 2027. Using the rates through December 31, 2026, a hypothetical request with 1,000 input tokens and 500 output tokens comes to $0.002625. This is an arithmetic illustration, not a measured request or promised invoice total. Check Google’s Gemini Developer API pricing page for the applicable rates and pricing mode before using the example.

Provider, model, endpoint, billing category, currency, pricing mode, and effective date matter. OpenAI’s API pricing, for example, separates input, cached-input, cache-write, and output rates. Google’s Gemini billing FAQ identifies input, output, cached-token count, and cached storage duration as billing factors. Do not treat one rate as a universal “LLM token price.”

How do I count tokens?

Tokens are the units models process, not words. A word, punctuation mark, long word, or character may split into a different number of tokens depending on the tokenizer. Google says, “For Gemini models, a token is equivalent to about 4 characters.” That is a rough Gemini text heuristic, not an exact conversion and not a rule for other providers.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A local count of prompt text can also miss parts of the request. Roles, message boundaries, tools, schemas, files, images, and provider-specific formatting may affect the count. For a more relevant count, use the provider’s counting method for the model and endpoint where available: Google’s Gemini API offers count_tokens, while OpenAI documents an input-token counting API for complete Responses API input. See Google’s token guide and OpenAI’s token-counting documentation.

After sending a request, use actual response usage metadata to check the estimate. OpenAI responses can report input, output, and total usage, with cached-input and reasoning details where applicable. Google’s interaction usage can report input, output, thinking, cached, tool-use, and total counts. These fields help explain differences between a plain-text estimate and a request’s reported usage; billing may still depend on the provider’s rate card and categories. See OpenAI’s usage and costs guidance.

Build the calculator in Colab

Create a notebook, then add a code cell with the following calculator. It accepts token counts and per-million rates, reports a per-request estimate, and optionally multiplies that estimate by a usage scenario. The sample rate fields are intentionally blank: enter rates for the exact provider, model, billing mode, and effective date you intend to estimate.

# Enter rates for the provider, model, and pricing mode you are estimating.
provider = ""
model = ""
pricing_mode = ""
rates_checked = ""

input_tokens = 1000
output_tokens = 500
input_price_per_million = 0.0
output_price_per_million = 0.0

estimated_cost = (
    input_tokens * input_price_per_million
    + output_tokens * output_price_per_million
) / 1_000_000

print(f"Provider: {provider}")
print(f"Model: {model}")
print(f"Pricing mode: {pricing_mode}")
print(f"Rates checked: {rates_checked}")
print(f"Estimated cost per request: ${estimated_cost:.8f}")

# Optional usage scenario; set either value to None to skip the projection.
requests_per_day = 100
 days_per_period = 30

if requests_per_day is not None and days_per_period is not None:
    projected_requests = requests_per_day * days_per_period
    projected_cost = estimated_cost * projected_requests
    print(f"Requests in scenario: {projected_requests:,}")
    print(f"Estimated scenario cost: ${projected_cost:.6f}")

There is an accidental leading space before days_per_period in that block? Python indentation must match the top level. Use this corrected line in the cell:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
days_per_period = 30

Replace the sample counts and zero rates with your own values. If you use a provider’s rate per token rather than per million, convert it to a per-million rate before entering it, or adapt the formula consistently. Record the rate-check date so a saved notebook does not silently look current after prices change.

How much will this prompt cost?

Suppose your provider-specific count is 1,000 input tokens and you expect 500 output tokens. With Google’s cited Gemini 3.8 Flash standard paid rates in effect through December 31, 2026, the calculation is:

(1,000 × $0.75 + 500 × $3.75) / 1,000,000 = $0.002625

That result assumes those token counts, those rates, and only the input and output categories shown. It is not a forecast of a provider’s invoice. If you expect 100 such requests per day for 30 days, the simple scenario projection is $7.875, assuming every request has the same usage and no additional billed categories. Change requests per day, period length, counts, and rates to model a different scenario.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why can the estimate differ from the bill?

  • Tokenizer or request mismatch: a character-based estimate or plain-text count may not match the model’s count for the full structured or multimodal request.
  • Output and reasoning usage: generated output is billed separately from input where the rate card specifies it; reasoning or thinking usage may also be reported or billed under applicable model rules.
  • Cached input and storage: cached tokens or cache storage can have separate billing treatment. The basic calculator above omits these categories.
  • Tools and other request components: tool use, schemas, files, images, and message formatting may change usage or introduce applicable charges beyond the two-category calculation.
  • Rates and pricing modes change: list rates can vary by model, mode, and effective date. Google’s Gemini pricing page gives different dated rates for Gemini 3.8 Flash, illustrating why the rate-check date belongs beside the estimate.

A lower price per million tokens does not necessarily make a model cheaper for a task. Tokenization, output length, reasoning use, and the workload itself affect total usage. OpenAI’s token guidance explains why a lower per-token rate may not yield a lower total task cost. Compare representative requests and end-to-end estimates, not input rates alone.

Compare models on the same workload

For a useful comparison, run the same representative task through each candidate model and keep the assumptions visible. Fill each row with that provider/model’s own count and current rate card; there is no universal token count for the prompt across providers.

Provider/model Pricing mode and date checked Input rate per million Output rate per million Cached-input treatment Input tokens Output tokens Estimated task cost
Candidate A Enter applicable mode and date Enter current rate Enter current rate Enter applicable rate or state not applicable Provider-specific count Provider-specific count Calculate using applicable categories
Candidate B Enter applicable mode and date Enter current rate Enter current rate Enter applicable rate or state not applicable Provider-specific count Provider-specific count Calculate using applicable categories

Keep count method alongside the comparison: a local text estimate, a provider count-before-send, or actual response usage answer different questions. For actual spend, review provider usage records as well as the per-request estimate.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.