Skip to main content

Delete a source file

Delete an Agent API source file in the current workspace.

Endpoint

DELETE /agents/file/{file_id} Returns 200 and a delete envelope. Repeated deletion returns 404, and writing this source file to an environment fails.

Path parameters

file_id string (required)Source file IDThis 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"

Response fields

id stringDeleted source file IDobject stringSource file deletion result object type, fixed as file.deleteddeleted booleanWhether deletion succeeded, true when deletion succeeds

Response example

{
  "id": "file_xxx",
  "object": "file.deleted",
  "deleted": true
}

Error codes

HTTP statusError type / codeSolution
401authentication_error / invalid_api_keySend a valid Authorization: Bearer $DASHSCOPE_API_KEY header
404not_found_error / not_found_errorUse a source file ID that exists in the current workspace
500server_error / server_errorRetry later. If it keeps failing, submit a ticket with x-request-id