Edit/create a file via the code agent
Send exactly one of two forms — a whole-file write (content) or one exact replacement (old_string and new_string, both required together). The choice is enforced by a cross-field rule the schema below cannot express: sending neither, or both, is 400 invalid_request. An old_string that matches zero or more than one location in the file is also rejected, so make it long enough to be unique. Flow JSON is rejected — use the flow endpoints. Platform-critical / injected / auto-generated files (e.g. routes/whatsapp_webhook.js, app.js, config/db.js, services/messages.js, config/mediaAssets.js, matched across both flat and src/ layouts) are rejected with 403 protected_file; the file is left unchanged. Reads (GET /v1/files, GET /v1/files/{path}) are NOT restricted.
Required scope: code:write
Authorizations
Project API key issued in Settings → API keys. Send it as Authorization: Bearer pk_live_….
Headers
Target project id, for an MCP OAuth bearer (mcp_at_…) attached to more than one project — get ids from GET /v1/projects. Matched case-insensitively.
Omit it and a READ falls back to the connection's default project; a mutation (any non-GET) on a connection with 2+ projects is rejected with 400 project_required — a write is never defaulted to a guessed project. A connection with exactly one project never needs the header.
Scopes are checked against the SELECTED project only, never a union across the connection.
For a pk_ API key the header selects nothing — one key is one project's context — but it IS validated: omit it and the key's own project is used, send it and it must name that project, otherwise the call is rejected with 403 project_not_attached (a blank value is 400 invalid_project_header, as above).
