Skip to content

devlog/token-math/from-terminal-tokens-to-a-per-million-api-bill-67.md

From Terminal Tokens to a Per-Million API Bill

From Terminal Tokens to a Per-Million API Bill

A price per million tokens is a unit rate. You do not have to buy a million tokens before making a request. If a request consumes 2,000 tokens in a category priced at $0.50 per million, that category costs 2,000 ÷ 1,000,000 × $0.50, or $0.001.

The useful debugging question is which categories your request actually consumed. Input, output, cache reads, and cache writes can have different rates. Here is a terminal walkthrough that turns those categories into a number you can check.

1. Find the model identifier before sending a request

Fluxo provides one key and one base URL, https://api.fluxorelay.com, for Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok and more. It works with Claude Code, Codex, Gemini CLI, and any OpenAI SDK. This walkthrough uses curl and jq to keep the request and response visible.

If you want to run these commands yourself, create a Fluxo account and generate an API key.

In Bash, read the key without echoing it or putting its value in shell history:

read -rsp 'Fluxo API key: ' FLUXO_API_KEY; export FLUXO_API_KEY; printf '\n'

Fetch the model identifiers through the OpenAI-compatible endpoint:

curl --fail-with-body --silent --show-error https://api.fluxorelay.com/v1/models -H "Authorization: Bearer $FLUXO_API_KEY" | jq -r '.data[].id'

For this example, choose the identifier corresponding to DeepSeek V4 Flash. Copy the returned identifier exactly; a display name is not necessarily a valid API identifier.

read -rp 'Model identifier: ' FLUXO_MODEL; export FLUXO_MODEL

2. Save one response and inspect its usage

Build the request with jq so the model identifier is escaped correctly:

jq -n --arg model "$FLUXO_MODEL" '{model:$model,messages:[{role:"user",content:"Explain a database index in three short sentences."}],max_tokens:300,stream:false}' > request.json

Send it and save the response: — curl --fail-with-body --silent --show-error https://api.fluxorelay.com/v1/chat/completions -H "Authorization: Bearer $FLUXO_API_KEY" -H 'Content-Type: application/json' --data-binary @request.json -o response.json

Inspect the usage object before doing any arithmetic:

jq '.usage' response.json

The returned counts describe this request. The output limit is a ceiling, not a prepaid quantity. Usage fields and cache details can vary by model, so retain the complete object instead of extracting only total_tokens.

3. Calculate a bill with four separate token buckets

The following rates are illustrative arithmetic inputs, not current Fluxo prices or a quote for DeepSeek V4 Flash. Replace them with the applicable rates shown in Fluxo before estimating actual spending.

  • Ordinary input costs $0.50 per million tokens in this example.
  • Generated output costs $2.00 per million tokens in this example.
  • Cache reads cost $0.05 per million tokens in this example.
  • Cache writes cost $0.625 per million tokens in this example.

Suppose a request has 12,000 ordinary input tokens, 8,000 cache-read tokens, 2,000 cache-write tokens, and 1,500 output tokens. These are four disjoint billing buckets. Run this calculation with Python 3:

python3 -c 'from decimal import Decimal as D; buckets=[("input",12000,"0.50"),("cache_read",8000,"0.05"),("cache_write",2000,"0.625"),("output",1500,"2.00")]; costs=[D(n)*D(rate)/D(1000000) for _,n,rate in buckets]; [print(f"{b[0]}: ${c:.6f}") for b,c in zip(buckets,costs)]; print(f"total: ${sum(costs):.6f}")'

The result is $0.006000 for ordinary input, $0.000400 for reads, $0.001250 for writes, and $0.003000 for output: $0.010650 total. One thousand requests with those exact counts and rates would cost $10.65.

4. Reconcile cache accounting before multiplying traffic

Check whether reported input already includes cached tokens. If 22,000 reported input tokens include the 8,000 reads and 2,000 writes above, ordinary input is 12,000. Charging all 22,000 at the ordinary rate and then adding cache charges would double-count tokens. Follow the model's usage definitions rather than assuming every provider reports identical fields.

Fluxo bills actual tokens, including cache reads and writes, with no monthly fee. For a useful budget, sample real editor sessions: repository context, repeated prompts, and long answers change the mix. Keep referral earnings separate from usage calculations; users earn a referral share when people they invite pay. For help reconciling a request, leave a note on the contact page after signing in.

Next in the buffer

Sign up in a minute and get credit to try every model mentioned here. Sign up →