Why pass rates lie and cost-per-solved-task doesn't
Every public comparison of DeepSeek V4 and GPT-4o mini reports a pass rate on someone else's problem set, with a single attempt and a generous token budget. Your repo is not that set. And you don't pay per problem — you pay per token, including the tokens burned on the attempts that failed.
The metric that survives contact with an invoice is tokens spent per task your own tests accept. Multiply that number by the per-token rate on your provider's pricing page and you get the real cost of a solved task. Everything else — leaderboard rank, vendor write-ups, a screenshot of a chat window — is a proxy that can rank the two models in the opposite order once your workload, retry policy and prompt length are taken into account.
So this post does something more useful than quoting a score: it gives you a harness you can run in a few minutes, and a way to read it.
The contenders, described without hype
GPT-4o mini — dependable instruction following, mature tooling and documentation, function calling that behaves consistently across the OpenAI ecosystem, and strong multilingual output. If your stack is already OpenAI-shaped, it is the path of least resistance.
deepseek-v4-flash — the code-first default. Terse output, complete runnable functions, and the model to use for nearly all generation, refactoring and review calls.
deepseek-v4-pro — the escalation tier. Better at multi-step reasoning and tangled refactors, and it costs more per token than flash, so reserve it for the tasks flash actually fails.
No number quoted in any article will tell you which of these wins on your codebase. That is precisely what the harness is for.
Build a harness that grades itself
Three small but realistic tasks — a duration parser, a chunker, an interval merge — graded by executing assertions rather than asking a second model to judge the output. Set AICREDITS_API_KEY and optionally OPENAI_API_KEY; any target without a key is skipped, so the script runs exactly as written below.
import os, re, json
from openai import OpenAI
TASKS = [
{
"id": "parse_duration",
"prompt": ("Write a Python function parse_duration(s: str) -> int that turns "
"'1h30m', '45s', '2h' into total seconds. Return only the code."),
"tests": [
"assert parse_duration('1h30m') == 5400",
"assert parse_duration('45s') == 45",
"assert parse_duration('2h') == 7200",
"assert parse_duration('0s') == 0",
],
},
{
"id": "chunk_list",
"prompt": ("Write a Python function chunk(xs, n) that returns consecutive "
"sublists of length n, with a shorter final chunk. Return only the code."),
"tests": [
"assert list(chunk([1, 2, 3, 4, 5], 2)) == [[1, 2], [3, 4], [5]]",
"assert list(chunk([], 3)) == []",
],
},
{
"id": "merge_intervals",
"prompt": ("Write a Python function merge(intervals) that merges overlapping "
"intervals and returns them sorted. Return only the code."),
"tests": [
"assert merge([[1, 3], [2, 6], [8, 10]]) == [[1, 6], [8, 10]]",
"assert merge([]) == []",
],
},
]
SYSTEM = "You are a terse Python reference. Output raw Python only, no prose, no markdown fences."
FENCE = "`" * 3
PROVIDERS = {
"aicredits": ("https://api.aicreditsapi.com/v1", "AICREDITS_API_KEY"),
"openai": ("https://api.openai.com/v1", "OPENAI_API_KEY"),
}
TARGETS = [
("deepseek-v4-flash", "aicredits"),
("deepseek-v4-pro", "aicredits"),
("gpt-4o-mini", "openai"), # skipped automatically when the key is absent
]
clients = {}
for _, prov in TARGETS:
if prov in clients:
continue
base_url, env = PROVIDERS[prov]
key = os.getenv(env)
if key:
clients[prov] = OpenAI(base_url=base_url, api_key=key)
def extract_code(text):
"""Strip markdown fences and stray prose fences defensively."""
lines = [ln for ln in text.strip().splitlines() if not ln.strip().startswith(FENCE)]
return "\n".join(lines).strip()
def check(code, tests):
ns = {}
try:
exec(code, ns)
except Exception as e:
return False, f"load error: {e}"
for assertion in tests:
try:
exec(assertion, ns)
except Exception as e:
return False, f"{assertion} -> {e}"
return True, "ok"
def ask(client, model, prompt, max_tokens=600):
r = client.chat.completions.create(
model=model,
messages=[{"role": "system", "content": SYSTEM},
{"role": "user", "content": prompt}],
temperature=0,
max_tokens=max_tokens,
)
u = r.usage
return r.choices[0].message.content, u.prompt_tokens, u.completion_tokens
def run(model, prov):
client = clients[prov]
solved = tin = tout = 0
for t in TASKS:
code, i, o = ask(client, model, t["prompt"])
tin, tout = tin + i, tout + o
ok, detail = check(extract_code(code), t["tests"])
solved += ok
print(f"{model:18} {t['id']:16} {'PASS' if ok else 'FAIL'} {str(detail)[:60]}")
per_solved = (tin + tout) / solved if solved else float("nan")
print(f"{model}: {solved}/{len(TASKS)} solved | tokens per solved task "
f"{per_solved:,.0f} | in {tin:,} out {tout:,}")
return {"model": model, "solved": solved, "tokens": tin + tout,
"tokens_per_solved": per_solved}
if __name__ == "__main__":
results = [run(m, p) for m, p in TARGETS if p in clients]
json.dump(results, open("bench.json", "w"), indent=2)
Reading the numbers: tokens per solved task is the denominator
Notice what the script does not print: prices. It prints tokens per solved task, which is price-agnostic by design. Take the current per-token rate for your provider — aicreditsapi.com/pricing for DeepSeek V4, OpenAI's own page for 4o mini — multiply, and you have the cost of one solved task on your workload. The input/output split matters as well, because the two are priced differently and output usually dominates on code generation.
Because rates move, commit the harness to your repo and re-run it when they do, rather than trusting arithmetic from a blog post written months ago.
| Metric | What it tells you | How the harness gets it |
|---|---|---|
| Solve rate (pass@1) | Whether the model is correct on your tasks, not a public set | Executed assertions per task |
| Tokens per solved task | The unit your invoice is actually priced in | prompt_tokens + completion_tokens ÷ tasks solved |
| Repair overhead | Whether a retry is worth its extra tokens | Spend with repair ÷ spend without |
| Input/output split | Output generally costs more than input on coding prompts | usage.prompt_tokens vs usage.completion_tokens |
| Cache-hit potential | How much reused context you pay full rate for | Stable system prompt, task placed last |
The second attempt is where cheap models separate
Most failures are near misses: a missing import, an off-by-one, a return where a yield was needed. One retry that includes the failing assertion repairs a good share of them — but it also doubles the tokens on every task that failed first time. Measure both numbers, because a model that solves less often but repairs reliably can end up cheaper per solved task than one with a higher first-try rate and wordier answers.
def ask_with_repair(client, model, prompt, tests, rounds=1, max_tokens=600):
"""One retry with the assertion text rescues near-misses; count the extra tokens."""
code, i, o = ask(client, model, prompt, max_tokens)
spent = i + o
ok, detail = check(extract_code(code), tests)
for _ in range(rounds):
if ok:
break
retry_prompt = (f"Your code failed this check:\n{detail}\n\nTask:\n{prompt}\n"
"Return the corrected full code only.")
code, i, o = ask(client, model, retry_prompt, max_tokens)
spent += i + o
ok, detail = check(extract_code(code), tests)
return ok, spent
This usually settles into a simple routing rule: send everything to deepseek-v4-flash, and escalate only the tasks whose assertions still fail to deepseek-v4-pro. Skip escalation entirely when a test is flaky — nondeterministic assertions inflate every model's numbers and make the whole comparison meaningless.
Settings that move the bill more than the model choice
Cap output. A
max_tokensof 400–600 is plenty for function-sized answers; unbounded preambles are pure cost.Use temperature 0. A failure should be a real failure, not a reroll.
Stable prefix first, task last. Prompt caching rewards identical leading context, and cache hits are billed below fresh input.
Batch the non-urgent work off-peak, where rates are lower.
Log usage tokens on every production call and feed a sample of real prompts back into the harness monthly — synthetic tasks drift away from real traffic fast.
Lint before you test. Malformed output is cheaper to reject locally than to pay for and then discard.
Where AiCredits fits
If flash wins on tokens per solved task for your workload, wiring it up is a two-line change: point the client at https://api.aicreditsapi.com/v1, keep model="deepseek-v4-flash", and the harness above works untouched. AiCredits sells DeepSeek V4 credits to developers outside China who would rather not deal with a Chinese phone number or bank card — pay by card or PayPal, no regional hoops. Current rates live at aicreditsapi.com/pricing, and the same account includes linting tools you can drop into the pre-flight step above.
FAQ
Both sit in the low-cost tier of their respective providers, with deepseek-v4-pro costing more than flash. Which is cheaper for you depends on tokens per solved task on your own prompts, which is exactly what the harness measures. Check both pricing pages rather than trusting a comparison table written last quarter.
deepseek-v4-flash for nearly everything, with deepseek-v4-pro as the escalation path for tasks whose assertions still fail. Keep gpt-4o-mini in the comparison if you already run OpenAI infrastructure, but let your own numbers decide.
Not through AiCredits. Accounts are paid with a card or PayPal, and the endpoint is OpenAI-compatible, so the OpenAI SDK works unchanged.
Yes. Add an entry to PROVIDERS with the base URL and the environment variable holding the key, add a matching tuple to TARGETS, and it joins the comparison automatically.