opendunes
Helpers · 3 min
Copy page ▾

Apply patch

Let a model propose changes to your files as diffs, checked before they reach your code.

  1. What it does.
  2. Name it in tools.
  3. Apply the patch and report back.
  4. Read what it bills on.

This page is one helperHelperA tool run for you when a model reaches for it mid-answer: a web search, a page read, a sandbox. Named opendunes:‹name›.More on Helpers →. The list of helpers, and how the charge adds up, sit in Helpers.

1. What it does

The model decides that a file must be created, changed or deleted, and writes a diff. OpenDunes checks the diff's syntax: a malformed diff goes back to the model to correct, before you see it. A valid diff reaches you, and your code applies it. Nothing is written to any file on OpenDunes' side.

Typeopendunes:apply_patch
Route/v1/responses
A stepone proposed diff
Stepsat most 30 a request
Bills ontokens only

The helper works on /v1/responses and nowhere else. On /v1/chat/completions and /v1/messages, a request that names it is refused with a 400 and nothing runs.

2. Name it in tools

Souk Bot renames a function in a shop's code. The sample sends the request, then prints the patch the model proposes and the charge. The patch is yours to apply.

import json
import os
import urllib.request

API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/responses"
MODEL = "anthropic/claude-sonnet-4.5"
PROMPT = "Rename the function calcTotal to computeTotal in src/cart.js."

body = {
    "model": MODEL,
    "input": PROMPT,
    "tools": [{"type": "opendunes:apply_patch"}],
}
request = urllib.request.Request(
    ADDRESS,
    data=json.dumps(body).encode(),
    headers={
        "Authorization": "Bearer " + API_KEY,
        "Content-Type": "application/json",
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)

for item in answer["output"]:
    if item["type"] == "apply_patch_call":
        print(item["call_id"])
        print(item["operation"])
print(answer["usage"]["cost"])

The answer is a 200. Name the helper by its type, opendunes:apply_patch; any other spelling of the type is a 400.

3. Apply the patch and report back

A valid diff arrives as an apply_patch_call item in output. Its operation is one of create_file, update_file or delete_file, and it carries the diff.

  1. Your code reads each apply_patch_call item.
  2. Your code applies the change to your files, or refuses it.
  3. Your code sends the outcome back on the next turn as an apply_patch_call_output item in input.
JSON
{
  "type": "apply_patch_call_output",
  "call_id": "call_abc123",
  "status": "completed",
  "output": "src/cart.js updated"
}
FieldHolds
call_idthe call_id of the apply_patch_call it answers
statuscompleted or failed
outputoptional: what happened, in words

The model reads the outcome and goes on: another file, a correction after a failed, or its answer.

Put this in the helper's parameters to change how the diff is checked.

ParameterDoes
engineauto, the default, streams the diff as the model writes it where the model's provider does so and checks it whole otherwise; native asks for the streamed diff

4. Read what it bills on

No charge beyond the model's tokens. The diff the model writes is output, and the file text it reads is input. usage.cost carries the whole of it.

Before the model starts, OpenDunes holds money from your wallet for the words and the answer. A proposed diff costs no money of its own, so the hold sets no step limit lower than yours: a request runs at most 30 steps, or the max_tool_calls you name. The helper runs no other model and no sandbox, so it has no spend cap.

Don't

Don't apply a diff without reading its path. The model proposes, and your code decides what is written.

Do

Send back a failed outcome with a reason when you refuse a change, so the model corrects itself instead of repeating it.