Apply Patch
Let models propose file changes via V4A diffs
Beta
response.apply_patch_call_operation_diff.delta events. All other models return the complete patch as a single tool output.The linkora:apply_patch server tool enables models to propose file changes using V4A diff patches. This is the building block for coding agents: the model generates a patch describing file creates, updates, or deletes, Linkora validates the diff syntax, and your application applies it.
How It Works
- You include
{ "type": "linkora:apply_patch" }in yourtoolsarray when calling the Responses API. - Based on the conversation, the model decides a file needs to be created, updated, or deleted, and generates a V4A diff patch.
- Linkora validates the patch syntax (correct line prefixes, valid markers, non-empty paths).
- If validation passes, the tool call is returned to your application as an
apply_patch_calloutput item. Your application applies the patch to the filesystem and echoes the result back asapply_patch_call_outputon the next turn. - If validation fails, the error is returned to the model so it can self-correct.
This is a human-in-the-loop tool: Linkora validates the diff but never applies it. Your application is responsible for executing the file operation.
Quick Start
const response = await fetch('https://link-ora.net/api/v1/responses', {
method: 'POST',
headers: {
Authorization: 'Bearer <LINKORA_API_KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/gpt-5.1-codex-mini',
input: 'Create a hello.py file that prints "Hello, world!"',
tools: [
{ type: 'linkora:apply_patch' }
]
}),
});
const data = await response.json();
// The response contains an apply_patch_call output item
// with the operation (create_file, update_file, or delete_file)
console.log(data.output);Patch Operations
The tool supports three operation types, each carried as the operation field on the apply_patch_call output item:
`create_file`
Creates a new file. Every content line in the diff must start with +:
{
"type": "apply_patch_call",
"call_id": "call_abc123",
"status": "completed",
"operation": {
"type": "create_file",
"path": "/src/hello.py",
"diff": "+print(\"Hello, world!\")\n"
}
}`update_file`
Updates an existing file using a V4A diff with context lines ( prefix), additions (+), and deletions (-):
{
"type": "apply_patch_call",
"call_id": "call_def456",
"status": "completed",
"operation": {
"type": "update_file",
"path": "/src/main.ts",
"diff": "@@ function main() {\n- console.log(\"old\");\n+ console.log(\"new\");\n }"
}
}`delete_file`
Deletes a file. No diff is needed, only the file path:
{
"type": "apply_patch_call",
"call_id": "call_ghi789",
"status": "completed",
"operation": {
"type": "delete_file",
"path": "/src/deprecated.ts"
}
}Echoing Results
After your application applies (or rejects) the patch, send the result back on the next turn as an apply_patch_call_output input item:
{
"model": "openai/gpt-5.1-codex-mini",
"input": [
{
"type": "apply_patch_call_output",
"call_id": "call_abc123",
"status": "completed",
"output": "Applied patch to /src/hello.py"
}
],
"tools": [
{ "type": "linkora:apply_patch" }
]
}| Field | Type | Description |
|---|---|---|
| `call_id` | string | Must match the `call_id` from the `apply_patch_call` |
| `status` | `"completed"` or `"failed"` | Whether the patch was applied successfully |
| `output` | string (optional) | Human-readable log of what happened |
Configuration
The apply patch tool accepts an optional engine parameter:
{
"type": "linkora:apply_patch",
"parameters": {
"engine": "auto"
}
}| Parameter | Type | Default | Description |
|---|---|---|---|
| `engine` | string | `auto` | `auto`: uses native passthrough when the endpoint supports incremental diff streaming, otherwise falls back to Linkora's HITL validator. `native`: forces native passthrough (falls back to HITL if unsupported). `linkora`: always uses the HITL validator, even on endpoints with native support. |
Engine behavior
To check whether an endpoint runs apply\_patch natively, read native_tools on the endpoint object. See Native Execution.
- Native passthrough streams the diff incrementally via
response.apply_patch_call_operation_diff.deltaevents, matching OpenAI's streaming format. Currently supported on OpenAI endpoints. - HITL (human-in-the-loop) buffers the complete diff and delivers it as a single atomic
apply_patch_calloutput item.
Pricing
The apply patch tool has no additional cost beyond standard token usage.
Next Steps
- Server Tools Overview. Learn about server tools
- Web Search. Search the web for real-time information
- Datetime. Get the current date and time
- Tool Calling. Learn about user-defined tool calling
