SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
2.7 KB

# Apply patch (type: "apply_patch")

Status: DOCUMENTED · LIVE_VERIFIED (2026-09-18, gpt-5.4-nano; streaming revealed undocumented events) Sources: https://developers.openai.com/api/docs/guides/tools-apply-patch · openapi-master.yaml ApplyPatchToolParam, ApplyPatchToolCall, ApplyPatchCreateFileOperation|UpdateFileOperation|DeleteFileOperation, ApplyPatchToolCallOutputItemParam, SpecificApplyPatchParam Last verified: 2026-09-18

# Definition

{"type":"apply_patch"} (+ optional allowed_callers). No input schema: the model knows the operation format. tool_choice: {"type":"apply_patch"} forces a patch (verified).

# Items

Output apply_patch_call:

json
{"id":"apc_…","type":"apply_patch_call","status":"completed","call_id":"call_…","operation":{"type":"create_file","path":"hello.txt","diff":"+OK\n"}}

operation.type ∈ create_file {path, diff} · update_file {path, diff} · delete_file {path}; status ∈ in_progress|completed. Input apply_patch_call_output: {"type":"apply_patch_call_output","call_id":"call_…","status":"completed"|"failed","output":"<message>"} — on failure (file not found, path rejected) return failed + a helpful message so the model can re-plan.

# Streaming — LIVE_DISCOVERED events

response.output_item.added → response.apply_patch_call_operation_diff.delta (delta, item_id, output_index, obfuscation, sequence_number) → response.apply_patch_call_operation_diff.done (diff) → response.output_item.done. These two event types are absent from the OpenAPI ResponseStreamEvent union and from the streaming-events reference page at retrieval time; recorded in generated/fragments/streaming-events/openai-tools.json with status LIVE_DISCOVERED.

# Models / availability

Guide table: Responses API only (not Chat Completions/Assistants); GPT-5.5, GPT-5.4, GPT-5.2, GPT-5.1. Model pages additionally list apply_patch for gpt-5.4-mini, gpt-5.4-nano (verified), gpt-5.4-pro, gpt-5.6-, gpt-6-astra, daybreak-.

# Guidance (docs)

Give the model file context (inline snapshot or the shell tool for discovery); keep tools=[{"type":"apply_patch"}] in follow-ups; validate paths (no traversal, allowed dirs only); run tests/linters and feed failures back; nudge toward minimal edits.

# Live evidence

Probe Status Result
forced apply_patch, "create hello.txt containing OK" 200 create_file hello.txt diff +OK\n (nothing applied by us)
stream 200 9 events incl. the two undocumented apply_patch_call_operation_diff.*

Examples: examples/openai/tools/apply-patch/ (dry-run validation). Test: test_shell_local_and_apply_patch_proposals.