> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Apply patch server tool

> Let a model propose validated file changes while the application keeps control of filesystem writes.

The `orq:apply_patch` tool lets a model propose file changes. **Toqan Router** validates the operation, path, and diff. The application receives each valid patch as a pending function call and decides whether to apply it.

This is a human-in-the-loop tool. **Toqan Router** never writes to the application filesystem.

## Quick start

The examples use the client configuration from the [Server tools overview](/docs/ai-gateway/features/server-tools.md). The Responses API is used here because it exposes the pending call and follow-up output directly.

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST https://router.toqan.ai/eu/v3/router/responses \
  -H "Authorization: Bearer $TOQAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.4-mini",
    "input": "Create hello.txt containing the line Hello from Toqan Router",
    "tools": [
      { "type": "orq:apply_patch" }
    ]
  }'
```

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const response = await client.responses.create({
  model: 'openai/gpt-5.4-mini',
  input: 'Create hello.txt containing the line Hello from Toqan Router',
  tools: [{ type: 'orq:apply_patch' }] as any,
});

console.log(response.output);
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
response = client.responses.create(
    model="openai/gpt-5.4-mini",
    input="Create hello.txt containing the line Hello from Toqan Router",
    tools=[{"type": "orq:apply_patch"}],
)

print(response.output)
```

## Patch operations

The model supplies three arguments in the pending call:

| Argument | Type | Description |
| - | - | - |
| `operation` | string | `create_file`, `update_file`, or `delete_file`. |
| `path` | string | File path. Paths containing `..` are rejected. |
| `diff` | string | V4A-style diff. Use an empty string for `delete_file`. |

Validation depends on the operation:

* `create_file`: every non-empty diff line must start with `+`.
* `update_file`: lines may start with a space, `+`, `-`, or `@@`, and the diff must contain an addition or deletion.
* `delete_file`: the diff must be empty.

Malformed patches are returned to the model for correction inside the tool loop. Only a valid patch reaches the application.

## Apply the patch

Read the pending `orq_apply_patch` function call, review and apply it in the application, then submit a standard function-call output. See [Tool calling and function execution](/docs/ai-gateway/features/tool-calling.md) for the response loop.

Apply patch has no additional charge beyond model tokens. Calls are not included in `usage.server_tool_use`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.