AI for fixing code: how to hand over an error and get a working fix
Fix quality depends on what you show the model. The data to include about the error, a prompt template, asking for a minimal diff, and verifying with a test.
5 min · · development · API keys
An AI for fixing code does well when it is shown the whole error, not the phrase "it does not work". The difference between "the model guessed" and "the model found the cause" almost always comes down to context: the full stack trace, the relevant code, versions, expected and actual behavior. Below is the data to attach to a request, a prompt template, a way to get a minimal diff, and a procedure for verifying the fix with a test.
AI for fixing code: what to show the model
The minimum without which the answer turns into guessing:
- The full error text and stack trace. A copy, not a retelling. The top lines of a trace often point to a library while the cause sits in your call below.
- The code the trace points to. The function that failed and what calls it. Not the whole repository, but 30-100 lines around it.
- Versions. Language, framework, key libraries, OS. The same error is fixed differently across major versions.
- Expected and actual behavior. One sentence: "should return a list of 3 items, returns an empty one".
- What you already tried. It saves a round of "try restarting".
- Input that reproduces it. A minimal example beats a description.
What not to attach: keys, passwords, tokens, personal data from logs. Before sending, go through the trace and replace values with placeholders. How to avoid leaks when logging is covered in the article on logging LLM requests without leaking data.
A prompt template
Structure matters more than pretty words. A working version:
Role: you help fix a bug in a Python 3.12 (Django 5.1) project.
Error (full stack trace):
<paste the trace>
Code where it happens (app/orders.py, lines 40-95):
<paste the code>
Expected: <what should happen>
Actual: <what happens>
Already tried: <what did not help>
Task:
1. Explain the cause in 2-3 sentences.
2. Propose a minimal fix as a unified diff.
3. Do not rewrite the whole function or change code unrelated to the error.
4. If data is missing, ask clarifying questions first.
5. Suggest a test that fails before the fix and passes after.Three items here do more work than the rest. "Minimal diff" protects against rewriting the whole file. "If data is missing, ask" lowers the chance of a confident invention. "A test that fails before the fix" turns a hypothesis into a checkable fact.
A script: send the trace and the file in one call
If you do not use an agent and paste errors by hand, it is handy to wrap the template in a small script. It works through the Zukko OpenAI-compatible format (chat completions):
import sys
from pathlib import Path
from openai import OpenAI
client = OpenAI(base_url="https://api.zukko.pro/v1", api_key="fetch_your_key")
trace = Path(sys.argv[1]).read_text() # file with the trace
source = Path(sys.argv[2]).read_text() # file with the code
versions = sys.argv[3] if len(sys.argv) > 3 else "versions not given"
prompt = f"""Versions: {versions}
Stack trace:
{trace}Run it with python fix.py trace.txt app/orders.py "Python 3.12, Django 5.1". To compare, put another catalog model into model, for example gpt-6.1-sol, deepseek-v4.1-flash or claude-opus-5-5. List and prices: GET https://api.zukko.pro/v1/models.
An agent instead of manual pasting
In a large project pasting pieces by hand is inconvenient. An agent such as Claude Code opens files by the trace itself, runs tests and shows a diff. Setup is described in the Claude Code guide: the variables ANTHROPIC_BASE_URL=https://api.zukko.pro (without /v1) and ANTHROPIC_AUTH_TOKEN=fetch_....
A typical request to an agent: "test test_order_total fails with this trace, find the cause and fix it minimally, then run the test". The key condition is that the agent has a command to verify the result. Without one it stops at "looks right".
Verifying the fix
You cannot accept a proposed diff blindly, even if the explanation sounds convincing. The order:
- Reproduce the error before the fix. Run the test or command and confirm it fails exactly as described. If you cannot reproduce it, the model is fixing a hypothetical problem.
- Apply the diff and read it in full. Extra edits in neighboring places are a reason to reject it.
- Run the failing test, then the whole suite. A fix for one test that breaks two others is not a fix.
- Check unfamiliar calls. The model may suggest a function or parameter that does not exist in your library version. Compare with the library documentation.
- Commit separately. The fix and the test in one commit, so rollback is easy.
If the first attempt did not help, do not ask "try again". Send the new result: what changed in the trace after applying the diff. That is a new fact, and the model works with it better than with a repeated task.
What a fix costs
A typical error with 6,000 input tokens of context (trace, code, versions, prompt) and a 1,500-token answer (explanation, diff, test). Input is 0.006M, output 0.0015M. Zukko prices as of October 18, 2026, $ per 1M tokens.
| Model | Calculation | Total |
|---|---|---|
claude-sonnet-5-5 (0.4 / 2) | 0.006 × 0.4 + 0.0015 × 2 = 0.0024 + 0.003 | $0.0054 |
gpt-6.1-sol (0.27 / 1.32) | 0.006 × 0.27 + 0.0015 × 1.32 = 0.00162 + 0.00198 | $0.0036 |
deepseek-v4.1-flash (0.013 / 0.038) | 0.006 × 0.013 + 0.0015 × 0.038 = 0.000078 + 0.000057 | $0.000135 |
The cost of one attempt is negligible next to a developer's time, so saving on the model only matters in bulk scenarios. For hard bugs with race conditions and multi-file dependencies it is reasonable to try a stronger model, for example claude-opus-5-5 (strength index 58 versus 48 for claude-sonnet-5-5), and check it on your case. For automatic checking in CI see the article on code review via API.
FAQ
Which AI for checking code and fixing errors is best?
We do not claim that one model writes better than another. Go by price, context and the strength index in the catalog, and run 5-10 of your real bugs through two or three models.
Can I just paste the whole project into the request?
Model windows are large (1M tokens for Claude, GPT and DeepSeek), but extra code adds noise and costs money. It is better to give the trace, the function and its callers, and let the agent fetch the rest.
What if the model suggests a function that does not exist?
Tell it the library version and ask it to rely only on the documented API of that version. Then verify by running: code that does not run is not accepted.
How do I pay for the API from Russia?
The Zukko balance is topped up in dollars from $1: via SBP in rubles, a MasterCard card or crypto. Per the calculation above one fixed bug costs fractions of a cent, so a minimal top-up is enough to try it.
To try this approach, create a key in the dashboard and run the script above on your own error.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- Your Own Neural Network Proxy on Node.js: Keep the API Key Off the FrontendA small Express server between your frontend and the model API: the key stays on the server, and models, request size and rate are capped.
- DeepSeek API in Python: Requests, Streaming, JSON and Error HandlingReady code for DeepSeek V4.1 Flash and V4 Pro on the OpenAI SDK: a request, streaming, JSON parsing and careful error handling.
- Gemini API in Python: requests via the OpenAI SDK and OpenAI formatA working Gemini API example in Python with no extra library: change base_url in the OpenAI SDK, add streaming and JSON, and compare with google-genai.
- Anthropic SDK for Python: base_url, key and a first request via a gatewayThe official anthropic package for Python just needs a different address. We cover base_url, the key, streaming, token counting, caching and errors.