The cold start problem is a billing problem
Every side project has a cold start: the stretch where nobody uses the thing but you. Traffic is zero, the README is a lie, and the only person hitting your endpoint is the one person who forgot to add a --dry-run flag.
What doesn't start cold is the meter. Your API bill is warm on day one, because it isn't driven by users — it's driven by you. You rerun the same prompt a few dozen times while tweaking a regex. You leave a test suite pointed at the live endpoint. You have three abandoned branches, each with its own key. You build an agent loop that almost converges, forever.
That's the real cold start problem, and it has nothing to do with per-token rates. The price per token is the least interesting variable on your dashboard. The number of calls you make is the variable you actually control, and at cold start that number is almost entirely accidental.
Budget in tokens, not dollars
The first move is to stop thinking in currency. Prices change, promos end, and a guardrail hardcoded to a rate is a guardrail that silently stops guarding. Tokens are what the API actually meters, they're provider-agnostic, and a token cap catches the failure mode that matters most at cold start: the runaway loop.
Put a hard daily ceiling in front of every call, and log usage per feature so you can see which part of the project is eating the budget.
import os, sqlite3
from datetime import date
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AICREDITS_API_KEY"],
base_url="https://api.aicreditsapi.com/v1",
)
ledger = sqlite3.connect("spend.sqlite3")
ledger.execute("CREATE TABLE IF NOT EXISTS spend (day TEXT, feature TEXT, tokens INTEGER)")
ledger.commit()
DAILY_TOKEN_CAP = 150_000 # tokens, not dollars: survives every price change
class BudgetExceeded(RuntimeError):
pass
def tokens_used_today(day: str) -> int:
row = ledger.execute(
"SELECT COALESCE(SUM(tokens), 0) FROM spend WHERE day = ?", (day,)
).fetchone()
return row[0]
def chat(messages, feature="default", model="deepseek-v4-flash", max_tokens=512):
day = date.today().isoformat()
if tokens_used_today(day) >= DAILY_TOKEN_CAP:
raise BudgetExceeded(f"daily token cap reached for {day}")
resp = client.chat.completions.create(
model=model, messages=messages, max_tokens=max_tokens
)
usage = resp.usage
used = (usage.prompt_tokens + usage.completion_tokens) if usage else 0
ledger.execute("INSERT INTO spend VALUES (?, ?, ?)", (day, feature, used))
ledger.commit()
return resp.choices[0].message.content
Two things fall out of this immediately. First, a while True: that calls the API will now stop in minutes instead of at the end of the month. Second, the feature column gives you a spend breakdown for free — and it will usually be lopsided. In most side projects one feature accounts for the overwhelming majority of calls, and it's rarely the one you'd guess.
Cache twice: your disk, then their prefix
There are two caches worth caring about and they solve different problems.
The first is yours. During development you send the same prompt over and over while you fiddle with the parsing layer, the UI, the retry logic. None of that needs a fresh model response. A tiny SQLite table keyed by a hash of the request payload turns every re-run into a free lookup.
The second is on the provider side. Prompt caching works at the prefix level: when the beginning of your prompt repeats exactly, those input tokens are billed less than fresh ones and come back faster. The practical rule is boring and easy to violate — put everything stable first (system instructions, style rules, few-shot examples) and everything variable last (the user's diff, the document, the question). One byte of drift at the top of the prompt and the whole prefix misses.
import hashlib, json, sqlite3
cache = sqlite3.connect("llm_cache.sqlite3")
cache.execute("CREATE TABLE IF NOT EXISTS cache (key TEXT PRIMARY KEY, payload TEXT)")
cache.commit()
def cached_chat(messages, model="deepseek-v4-flash", max_tokens=512):
key = hashlib.sha256(json.dumps(
{"model": model, "messages": messages, "max_tokens": max_tokens},
sort_keys=True,
).encode()).hexdigest()
hit = cache.execute("SELECT payload FROM cache WHERE key = ?", (key,)).fetchone()
if hit:
return json.loads(hit[0])
text = chat(messages, feature="cached", model=model, max_tokens=max_tokens)
cache.execute("INSERT OR REPLACE INTO cache VALUES (?, ?)", (key, json.dumps(text)))
cache.commit()
return text
# Cache-friendly prompt layout: stable prefix first, variable content last.
SYSTEM = """You are a terse code reviewer. Report only real defects.
Output format: one bullet per issue, file:line, no preamble.
Rules:
- Ignore formatting and naming preferences.
- Flag unhandled exceptions, off-by-one errors, and blocking I/O.
- If nothing is wrong, output exactly: OK
"""
def review(diff: str, style_guide: str) -> str:
messages = [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": f"Style guide:\n{style_guide}\n\nDiff:\n{diff[:6000]}"},
]
return cached_chat(messages, max_tokens=400)
Truncating the diff to a fixed window does two useful things at once: it bounds the worst-case input size, and it makes the variable part of the prompt small enough that the stable prefix dominates. If your whole prompt is dynamic, prefix caching can't help you, no matter how good your intent.
Flash by default, pro only on failure
Most side-project traffic is unglamorous: classify this, extract that, summarize the other thing, rewrite this paragraph. deepseek-v4-flash handles that tier well and is the cheapest way to run it. deepseek-v4-pro is the stronger model and costs more, which is exactly the right shape — you want the expensive model to be a rare, deliberate escalation rather than a default you forgot to change.
The trick is to make escalation automatic instead of manual. Include a cheap validator in your code — a schema check, a JSON parse, a regex, a length bound — and only pay for the bigger model when the small one produced something you can't use.
import json
def chat_with_escalation(messages, validate, max_tokens=512):
"""Try flash first; only pay for pro when the output fails validation."""
text, used_model = "", "deepseek-v4-flash"
for model in ("deepseek-v4-flash", "deepseek-v4-pro"):
text = chat(messages, feature="escalation", model=model, max_tokens=max_tokens)
used_model = model
if validate(text):
break
return text, used_model
def parses_as_json(text: str) -> bool:
try:
json.loads(text)
return True
except json.JSONDecodeError:
return False
expected, model = chat_with_escalation(
[{"role": "user", "content": "Return a JSON object with keys title and tags for: ..."}],
validate=parses_as_json,
)
print(model, expected)
Log which model produced each answer. If pro is answering most of your calls, your prompt is the problem, not the model — tighten the format instructions before you widen the budget.
Cap the blast radius
Set
max_tokensper task. A classifier needs a few tokens. If you don't set a ceiling, a confused model will happily write an essay.Truncate or summarize context. Dumping a whole repository into a prompt is the single fastest way to turn a quiet project into a loud bill. Send the relevant function, not the file.
Don't retry deterministic failures. Retrying a
400for a malformed request just pays for the failure twice. Retry timeouts and rate limits with backoff; let everything else surface.Stream and close on cancel. If the user navigates away, stop reading the stream so you aren't paying for tokens nobody will see.
Sample your evals. Run the full fixture set nightly; run a small smoke set on every push. Full suites on every commit is the most common self-inflicted cost at cold start.
| Where it leaks | Symptom | Fix |
|---|---|---|
| Dev iteration | Same prompt re-sent while you fix parsing | Disk cache keyed by request hash |
| Prefix drift | Prompt caching never hits | Stable system prompt first, variable content last |
| Model default | Pro answering routine calls | Flash first, escalate on validation failure |
| Context dumps | Input tokens dwarf output tokens | Truncate, chunk, or summarize before sending |
| Retry storms | Bills spike with no new features | Retry only timeouts and rate limits |
| CI evals | Spend tracks commits, not usage | Smoke set on push, full set nightly |
Buying credits without a cold start of your own
The code above is plain OpenAI SDK, so the only thing that ties it to a provider is base_url. If you're DeepSeek-first, AiCredits sells DeepSeek API credits to international developers with a card or PayPal — no Chinese phone number, no Chinese bank account, no account-review limbo in the middle of a weekend build. Swap the key and the base_url and every snippet in this post runs unchanged. Current rates live at aicreditsapi.com/deepseek-prices, and it's worth a look before you size your token cap.
To be fair to the alternative: if your side project genuinely routes across several model families, OpenRouter's single-key, many-models approach is excellent for that, and its model catalog is a real convenience. The tradeoff is that you're abstracting over providers you could otherwise bill directly. If DeepSeek is the only model you actually call, one direct relationship and one bill is simpler than a router sitting between you and the thing you're paying for.
One more cold-start cost that isn't tokens: the code your LLM writes. AiCredits also ships linting tools, which is a cheaper place to catch a bug than a retry loop that burns budget rediscovering it.
The one-week version
If you only do three things this week: put a token ledger with a hard daily cap in front of every call, add the SQLite response cache so development stops costing anything, and make flash the default with validation-gated escalation to pro. That combination makes the cold start boring — which is exactly what a side project's finances should be until real users show up and start paying for the thing.
FAQ
No, it's provider-side and automatic, but it only helps if the start of your prompt is byte-identical across calls. Keep system instructions and examples static and at the top, put the variable content at the end, and never interpolate a timestamp or request ID into the prefix.
Not while you're pre-users. Pro costs more than flash, and the routine work in a side project — classification, extraction, short rewrites — rarely needs it. Route by difficulty and escalate on validation failure; you keep the quality where it matters and pay the premium only there.
Check cumulative tokens against a daily cap before every call, not after the loop finishes. The ledger in this post raises on the first call past the ceiling, which turns an overnight disaster into a stack trace you read in thirty seconds.
Not through AiCredits — international cards and PayPal work. That matters at cold start because account setup friction is the kind of thing that quietly kills a weekend project.