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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file_id | string | Yes | The 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.
| Status | error.type | Cause and fix |
|---|---|---|
| 400 | invalid_request_error | The 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. |
| 400 | invalid_request_error | The file was produced by a session. Download it with Download a file, or remove it from the session’s folder in Drive. |
| 403 | permission_error | The key lacks files:write. Use a key that has files:write. |
| 403 | permission_error | The key’s owner can’t edit the Drive folder that holds the file. Use a key whose owner can edit that folder. |
| 403 | permission_error | A service account key tried to delete a file it didn’t upload. Use the personal key of the user who owns the file. |
| 404 | not_found_error | No 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. |
| 500 | api_error | The 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 -sS -X DELETE "$CONTEXT_BASE_URL/v1/files/329409ba-f288-4b44-9c73-14a18150edee" -H "x-api-key: $CONTEXT_API_KEY"client.beta.files.delete("329409ba-f288-4b44-9c73-14a18150edee")await client.beta.files.delete("329409ba-f288-4b44-9c73-14a18150edee")