> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pdf.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Temporary File

> Deletes temporary file (that was uploaded by you or generated by API).

## `POST /v1/file/delete`

<Note>All temporary files are auto removed after 1 hour. You may use [File Upload](/api-reference/file-upload/overview#temporary-files-upload) methods to explicitly force remove temp files once you don't need them.</Note>

## Attributes

<Note>Attributes are case-sensitive and should be inside JSON for POST request. for example: `{ "url": "https://example.com/file1.pdf" }`</Note>

| Attribute | Type   | Required | Default | Description                                                                                        |
| --------- | ------ | -------- | ------- | -------------------------------------------------------------------------------------------------- |
| `url`     | string | *Yes*    | -       | URL of the previously uploaded temporary file or output file that was generated by the API method. |

## Query parameters

*No query parameters accepted.*

## Responses

| Parameter          | Type    | Description                                                                                                                  |
| ------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `error`            | boolean | Indicates whether an error occurred (`false` means success)                                                                  |
| `status`           | string  | Status code of the request (200, 404, 500, etc.). For more information, see [Response Codes](/api-reference/response-codes). |
| `message`          | string  | Message of the request                                                                                                       |
| `credits`          | integer | Number of credits consumed by the request                                                                                    |
| `duration`         | integer | Time taken for the operation in milliseconds                                                                                 |
| `errorCode`        | integer | Error code of the request (400, 401, 402, 403, 404, 500, etc.)                                                               |
| `remainingCredits` | integer | Number of credits remaining in the account                                                                                   |

## `Example` Payload

<Note>To see the request size limits, please refer to the [Request Size Limits](/api-reference/url-input-and-request-limits#pdf-co-request-size).</Note>

```json theme={null}
{
  "url": "https://pdf-temp-files.s3.amazonaws.com/b5c1e67d98ab438292ff1fea0c7cdc9d/sample.pdf"
}
```

## `Example` Response

<Note>To see the main response codes, please refer to the [Response Codes](/api-reference/response-codes) page.</Note>

```json theme={null}
{
  "error": false,
  "status": 200,
  "remainingCredits": 9999986
}
```

<Note>
  **Inconsistent URL Encoding in cURL Output:** When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (`&`) may appear as `\u0026` in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you're parsing the response programmatically, your JSON parser will handle this conversion automatically.
</Note>

## Code Samples

<Tabs>
  <Tab title="CURL">
    ```bash theme={null}
    curl --location --request POST 'https://api.pdf.co/v1/file/delete'
    --header 'x-api-key: *******************'
    --data-raw '{
        "url": "https://pdf-temp-files.s3.amazonaws.com/b5c1e67d98ab438292ff1fea0c7cdc9d/sample.pdf"
    }'
    ```
  </Tab>

  <Tab title="JavaScript/Node.js">
    ```javascript theme={null}
    var https = require("https");
    var path = require("path");

    const API_KEY = "*************************************";


    function deleteFile(apiKey, fileName) {
      return new Promise(resolve => {
          // Prepare request to `file/delete` API endpoint
          let queryPath = `/v1/file/delete?url=${fileName}`;
          let reqOptions = {
              host: "api.pdf.co",
              path: encodeURI(queryPath),
              headers: { "x-api-key": apiKey }
          };
          // Send request
          https.get(reqOptions, (response) => {
              response.on("data", (d) => {
                  let data = JSON.parse(d);
                  if (data.status == 200) {
                      console.log("remainingCredits: " + data.remainingCredits);
                      resolve([data.remainingCredits]);
                  }
                  else {
                      // Service reported error
                      console.log("Error");
                  }
              });
           })
           .on("error", (e) => {
                // Request error
                console.log("error: " + e);
           });
      });
    }

    let result = deleteFile(API_KEY, "https://pdf-temp-files.s3.amazonaws.com/b5c1e67d98ab438292ff1fea0c7cdc9d/sample.pdf");
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # The authentication key (API Key).
    # Get your own by registering at https://app.pdf.co
    API_KEY = "*************************************"

    # Base URL for PDF.co Web API requests
    BASE_URL = "https://api.pdf.co/v1"

    fileName = "https://pdf-temp-files.s3.amazonaws.com/b5c1e67d98ab438292ff1fea0c7cdc9d/sample.pdf"

    url = "{}/file/delete?url={}".format(BASE_URL, fileName)

    # Execute request and get response as JSON
    response = requests.get(url, headers={"x-api-key": API_KEY})
    if (response.status_code == 200):
        json = response.json()

        if json["status"] == 200:
            remainingCredits = json["remainingCredits"]
    ```
  </Tab>

  <Tab title="PHP">
    ```php theme={null}
    <?php
      $apiKey = "***************";
      $fileName = "https://pdf-temp-files.s3.amazonaws.com/b5c1e67d98ab438292ff1fea0c7cdc9d/sample.pdf";
      $url = "https://api.pdf.co/v1/file/delete?url=" . $fileName;

      // Create request
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey));
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      // Execute request
      $result = curl_exec($curl);
    ?>
    ```
  </Tab>
</Tabs>
