Skip to content

devlog/token-math/the-token-bill-behind-a-30-turn-terminal-chat-71.md

The Token Bill Behind a 30-Turn Terminal Chat

A cheap prompt becomes expensive when you replay it

You ask an assistant to inspect a function, explain a failure, and patch a test. Each message feels small. But a typical chat client sends earlier messages again so the model can understand your next request. Your newest sentence might contain twenty tokens while the request carries thousands.

The same pattern appears in editor agents and terminal sessions. Repository instructions, tool results, pasted logs, and previous answers become future input. Let’s reproduce that behavior with curl and inspect the usage ourselves.

Point your terminal at Fluxo and select a model

These commands require Bash, curl, and Python 3. Fluxo provides one key and one base URL, https://api.fluxorelay.com, across its model catalog. Start by reading your key without putting its value in shell history.

read -r -s -p 'Fluxo API key: ' FLUXO_API_KEY; printf '\n'; export FLUXO_API_KEY; export FLUXO_BASE_URL='https://api.fluxorelay.com'

Fetch the available model IDs before building a request. Display names and API identifiers can differ, so copy the identifier returned by the endpoint.

curl --fail-with-body --silent --show-error "$FLUXO_BASE_URL/v1/models" -H "Authorization: Bearer $FLUXO_API_KEY" -o models.json

python3 -c 'import json; d=json.load(open("models.json")); print("\n".join(str(m["id"])+" | "+str(m.get("name", "")) for m in d["data"]))'

For this experiment, choose the returned ID corresponding to Claude Haiku 4.5. You can repeat it with DeepSeek V4 Flash afterward.

read -r -p 'Model ID from the list: ' FLUXO_MODEL; export FLUXO_MODEL

Replay three turns and print each usage record

Initialize a local conversation file. Run this experiment in an empty directory because the commands write messages.json, request.json, and response.json.

python3 -c 'import json; json.dump([], open("messages.json", "w"))'

The following command makes three sequential requests. Each request includes the accumulated conversation; each successful answer gets appended before the next request. It also prints the complete usage object, preserving any cache details the endpoint returns.

for turn in 1 2 3; do python3 -c 'import json,os; m=json.load(open("messages.json")); m.append({"role":"user","content":"Explain one practical way to reduce repeated context in an API chat. Keep your answer under 80 words."}); json.dump({"model":os.environ["FLUXO_MODEL"],"messages":m},open("request.json","w"))' || break; curl --fail-with-body --silent --show-error "$FLUXO_BASE_URL/v1/chat/completions" -H "Authorization: Bearer $FLUXO_API_KEY" -H 'Content-Type: application/json' --data-binary @request.json -o response.json || break; python3 -c 'import json; r=json.load(open("response.json")); q=json.load(open("request.json")); print(json.dumps(r.get("usage",{}),indent=2)); q["messages"].append(r["choices"][0]["message"]); json.dump(q["messages"],open("messages.json","w"))' || break; done

Look for prompt_tokens or the equivalent input count. Later requests should contain more input because they include previous answers too. Exact counts depend on tokenization and response length. Cache reporting varies by model and route; an absent field does not prove a cache hit or miss.

Turn growing context into a session budget

Suppose your first request contains 2,000 input tokens and every completed turn adds 500 tokens to the next request. Across thirty requests, input totals 30 × 2,000 + 500 × (0 + 1 + … + 29) = 277,500 tokens. The final request alone contains 16,500.

At a hypothetical uncached input price of $0.20 per million tokens, that session costs $0.0555 for input. One session looks cheap; a thousand comparable sessions cost $55.50 before output and any other applicable charges. This is illustrative arithmetic, not a quoted model price.

Fluxo bills real tokens, including cache reads and writes, without a monthly fee. Use the selected model’s current rates for each billing category. Cached input may already be included in the reported input total, so avoid counting those tokens twice. Caching can reduce the price of repeated context without making it free.

Keep useful history and trim repeated baggage

  • Start a fresh conversation when the repository task changes substantially.
  • Replace long debugging transcripts with verified findings and remaining questions.
  • Inspect tool output before retaining thousands of irrelevant log lines.
  • Track input, output, and cache charges across complete sessions.

Fluxo also works with Claude Code, Codex, Gemini CLI, and any OpenAI SDK; inspect what each client retains because compaction and caching behavior differ. If you want to run this experiment, create a Fluxo account. Users also earn a referral share when people they invite pay. For help interpreting usage, 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 →