Count characters in the exact text to be sent, including comments and whitespace. Pick a divisor from the rules-of-thumb ranges and state it.
Do not send secrets, or proprietary IP to an unapproved outside service, just to measure them. Least privilege applies: send the smallest slice that answers the question.
Step | Action | Example |
|---|---|---|
1. Measure | Count characters in the payload | 8000 characters |
2. Divide | Divide by a stated approximate rate | 8000 / 4 = 2000 |
3. Margin | Round up for safety | Budget above 2000 |
The program below estimates with ceiling division at a stated divisor. It checks exact small cases plus one 8000-character case.
import sys
SAMPLE = "module counter(input logic clk, output logic [7:0] q);"
DIVISOR = 4
def estimate(n_chars, divisor):
return (n_chars + divisor - 1) // divisor
bad = 0
if estimate(8000, 4) != 2000:
bad += 1
if estimate(0, 4) != 0:
bad += 1
if estimate(1, 4) != 1:
bad += 1
if estimate(5, 4) != 2:
bad += 1
if estimate(12000, 3) != 4000:
bad += 1
if not (estimate(len(SAMPLE), DIVISOR) * DIVISOR >= len(SAMPLE)):
bad += 1
if bad != 0:
print("FAIL: " + str(bad) + " checks wrong")
sys.exit(1)
print("PASS: sample " + str(len(SAMPLE)) + " chars gives " + str(estimate(len(SAMPLE), DIVISOR)) + " tokens at 4 each")Compare the estimate against room and cost with stated example numbers. Long inputs are less reliable than short ones, with a reported tendency to use the start and end better than the middle.
Treat files and logs as untrusted input: they can carry injected instructions. Keep human approval on risky actions the model proposes.
payload = 8000 characters, stated rate 4 chars per token (approximate)
estimate = 8000 / 4 = 2000 tokens
EXAMPLE price: assume 1 million input tokens cost 3 units (stated example parameter)
cost = 2000 x 3 / 1000000 = 6000 / 1000000 = 0.006 units
check: 0.006 x 1000000 / 3 = 6000 / 3 = 2000 tokens
decision: budget above 2000 tokens and trim before resending past the limitA remainder still needs a piece. Ceiling maps 5 characters at 4 each to 2 tokens, never 1.
The payload changes, not the arithmetic. Strip secrets first and send the smallest slice; never trade IP for a better count.