Skip to content

Delete a file

DELETE /v1/files/{file_id}

Permanently deletes an uploaded file.

The file doesn’t go to the Drive trash, and it can’t be restored through this API or the app. A later request for it returns 404. If the server can’t delete the stored copy, the request returns 500 and the copy stays in the owner’s Drive. See the errors below.

A service account key can delete only the files it uploaded. This endpoint can’t delete files that a session produced, or a file that a session or run still uses. See the errors below.

The key must have the files:write capability. For what each capability allows, see Keys.

Path parameters

NameTypeRequiredDefaultDescription
file_idstringYesThe ID of the file to delete.

Response

Returns 200 with an object that holds the file’s id and a type of file_deleted.

{
"id": "329409ba-f288-4b44-9c73-14a18150edee",
"type": "file_deleted"
}

Errors

This endpoint can return these errors as well as the common errors.

Statuserror.typeCause and fix
400invalid_request_errorThe file is attached to a session that isn’t archived, or is used by a run that hasn’t finished. Archive the session, or wait for the run to finish, then retry.
400invalid_request_errorThe file was produced by a session. Download it with Download a file, or remove it from the session’s folder in Drive.
403permission_errorThe key lacks files:write. Use a key that has files:write.
403permission_errorThe key’s owner can’t edit the Drive folder that holds the file. Use a key whose owner can edit that folder.
403permission_errorA service account key tried to delete a file it didn’t upload. Use the personal key of the user who owns the file.
404not_found_errorNo file with this ID exists, or this key can’t read it. Check the ID against List files. If the ID is correct, check that the key can read the file.
500api_errorThe API no longer returns the file, but its stored copy couldn’t be deleted. The message says where the copy remains in the owner’s Drive. Delete it there, or quote request_id when you contact support.

Example

cURL
curl -sS -X DELETE "$CONTEXT_BASE_URL/v1/files/329409ba-f288-4b44-9c73-14a18150edee" -H "x-api-key: $CONTEXT_API_KEY"
Python
client.beta.files.delete("329409ba-f288-4b44-9c73-14a18150edee")
TypeScript
await client.beta.files.delete("329409ba-f288-4b44-9c73-14a18150edee")