Delete a source file
Updated at:
Delete an Agent API source file in the current workspace.
Endpoint
Returns 200 and a delete envelope. Repeated deletion returns 404, and writing this source file to an environment fails.
DELETE
/agents/file/{file_id}Path parameters
file_idstringRequiredSource file ID
This endpoint has no request body or query parameters.
Deleting a source file does not delete copies already written to an environment or published artifacts.
If an environment template references the deleted source file, creating an environment from that template fails with 404 File not found.
Request example
curl -sS -X DELETE "$BASE_URL/agents/file/file_xxx" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "OpenAI-Beta: agents=v1"
import os
import requests
resp = requests.delete(
f"{os.environ['BASE_URL']}/agents/file/file_xxx",
headers={"Authorization": f"Bearer {os.environ['DASHSCOPE_API_KEY']}"},
)
print(resp.status_code, resp.json())
Response fields
idstringDeleted source file ID
objectstringSource file deletion result object type, fixed as file.deleted
deletedbooleanWhether deletion succeeded, true when deletion succeeds
Response example
{
"id": "file_xxx",
"object": "file.deleted",
"deleted": true
}
Error codes
| HTTP status | Error type / code | Solution |
|---|---|---|
401 | authentication_error / invalid_api_key | Send a valid Authorization: Bearer $DASHSCOPE_API_KEY header |
404 | not_found_error / not_found_error | Use a source file ID that exists in the current workspace |
500 | server_error / server_error | Retry later. If it keeps failing, submit a ticket with x-request-id |
Is this page helpful?