At the time of this test, Kimi K3 ranked first on Arena's Frontend Code leaderboard. I wanted to see how it handled backend work, so I ran Kimi K3 through Kimi Code against the backend that powers my production AI learning product.

The stack and scale:

  • FastAPI and PostgreSQL
  • 68K lines of backend code across more than 400 files
  • 307 API endpoints

All results and costs below came from this project and this run.

The Prompt

Frontier models have changed the way we write prompts. Extra instructions can narrow the model's search to the problems you already expect.

This four-part structure has worked well in real tests:

  • Goal
  • Context
  • Constraints
  • Required output

I used this prompt for the audit:

Audit and optimize this production FastAPI backend for database and API performance.

Context:
- FastAPI, async SQLAlchemy, PostgreSQL
- 307 API endpoints
- About 68K LOC
- Full repository and local database are available

Goal:
Find the highest-impact bottlenecks, implement the smallest safe fixes, and measure each result before and after.

Investigate:
- N+1 queries and per-item database calls
- Missing, duplicate, or dropped indexes
- Over-fetching, inefficient query shapes, and Python-side aggregation
- Unbounded list endpoints and pagination
- Per-item commits or refreshes
- Connection and session usage

Workflow:
1. Trace each relevant path from router to service to repository to generated SQL.
2. Inspect ORM models, Alembic history, and the local PostgreSQL schema before proposing indexes.
3. Rank the findings before changing code.
4. Implement the five highest-impact, low-risk fixes.
5. Run the relevant tests and measure again.

Rules:
- Cite the exact file and line for each finding.
- Use query counts, benchmarks, or EXPLAIN evidence.
- Do not invent traffic, row counts, latency, or impact.
- Mark anything you cannot prove as "unverified."
- Preserve API behavior and compatibility.
- Avoid new infrastructure, schema rewrites, and broad refactors.

Return:
1. Findings ranked by impact and confidence
2. The five fixes selected and why
3. The patch for each fix
4. Before/after evidence
5. Correctness bugs in a separate section

The Results

Kimi K3 found 17 performance issues across the backend.

One API request was hitting the database 412 times. After the fix, it needed 3. Loading the full curriculum tree dropped from 437 queries to 6.

A function named "_batch" was querying IDs one by one. Sending it 50 IDs caused 50 database queries. The fix reduced that to 2.

The surprise was a migration bug. A later Alembic migration had removed composite indexes created by an earlier migration. Kimi K3 found the mismatch by checking the query, ORM model, migration history, and PostgreSQL schema together.

The Cost

The full task took 10 API calls and cost $0.8231.

The useful number was the cache rate: 94.5% of the input tokens hit the cache. Large coding tasks reuse the same codebase across many calls, so caching cuts a large part of the input cost.

Based on current official API prices, GPT-5.6 Sol would cost about twice as much for this usage. Claude Fable 5 would cost about 3.3 times as much.

Based on this test, Kimi K3 can handle serious backend work. It found useful optimizations, caught a migration bug I had missed, and cost less than $1 for the full run. I would use it again at that price.

Sources