BetaServer tools are currently in beta. The API and behavior may change.
Streaming behaviorOnly OpenAI models stream apply patch results incrementally via
response.apply_patch_call_operation_diff.delta events. All other models return the complete patch as a single tool output.openrouter: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, OpenRouter validates the diff syntax, and your application applies it.
How It Works
- You include
{ "type": "openrouter: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.
- OpenRouter 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.
Quick Start
Patch Operations
The tool supports three operation types, each carried as theoperation field on the apply_patch_call output item:
create_file
Creates a new file. Every content line in the diff must start with +:
update_file
Updates an existing file using a V4A diff with context lines ( prefix), additions (+), and deletions (-):
delete_file
Deletes a file. No diff is needed — only the file path:
Echoing Results
After your application applies (or rejects) the patch, send the result back on the next turn as anapply_patch_call_output input item:
Configuration
The apply patch tool accepts an optionalengine parameter:
Engine behavior
- 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