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

# Delete Attachment from Knowledge Folder

> Remove a file from a knowledge folder

<Info>
  **Using our API via a dedicated deployment?** Just replace `api.langdock.com` with your deployment's base URL: **`<deployment-url>/api/public`**
</Info>

Deletes a file (attachment) from a knowledge folder. This removes the file and all associated embeddings, making the content no longer searchable.

<Info>
  Requires an API key with the `KNOWLEDGE_FOLDER_API` scope. The knowledge folder must be shared with the API key. See [Share Knowledge Folders with the API](/en/developer/knowledge-folder-api/sharing) for setup instructions.
</Info>

## Request Format

### Path Parameters

| Parameter      | Type   | Required | Description                        |
| -------------- | ------ | -------- | ---------------------------------- |
| `folderId`     | string | Yes      | The ID of the knowledge folder     |
| `attachmentId` | string | Yes      | The ID of the attachment to delete |

## Examples

### Delete with cURL

```bash theme={null}
curl -X DELETE "https://api.langdock.com/knowledge/{folderId}/{attachmentId}" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Delete with JavaScript

```javascript theme={null}
const axios = require("axios");

async function deleteAttachment(folderId, attachmentId) {
  const response = await axios.delete(
    `https://api.langdock.com/knowledge/${folderId}/${attachmentId}`,
    {
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
      },
    }
  );

  return response.data;
}

// Example usage
try {
  const result = await deleteAttachment("folder_abc123", "att_xyz789");
  console.log("Attachment deleted:", result.message);
} catch (error) {
  console.error("Failed to delete:", error.response?.data?.message);
}
```

### Bulk Delete Example

```javascript theme={null}
async function deleteMultipleAttachments(folderId, attachmentIds) {
  const results = await Promise.allSettled(
    attachmentIds.map((id) => deleteAttachment(folderId, id))
  );

  const succeeded = results.filter((r) => r.status === "fulfilled").length;
  const failed = results.filter((r) => r.status === "rejected").length;

  console.log(`Deleted ${succeeded} files, ${failed} failed`);
  return results;
}
```

## Response Format

### Success Response (200 OK)

```typescript theme={null}
{
  status: "success";
  message: "Attachment deleted";
}
```

### Example Response

```json theme={null}
{
  "status": "success",
  "message": "Attachment deleted"
}
```

## Error Handling

```typescript theme={null}
try {
  const response = await deleteAttachment(folderId, attachmentId);
} catch (error) {
  if (error.response) {
    switch (error.response.status) {
      case 400:
        console.error("Invalid request:", error.response.data.message);
        break;
      case 401:
        console.error("Invalid or missing API key");
        break;
      case 403:
        console.error("API key does not have access to this knowledge folder");
        break;
      case 404:
        console.error("Knowledge folder or attachment not found");
        break;
      case 429:
        console.error("Rate limit exceeded");
        break;
      case 500:
        console.error("Server error");
        break;
    }
  }
}
```

## Important Notes

<Warning>
  Deletion is permanent. The file and all associated embeddings will be removed and cannot be recovered.
</Warning>

* The attachment must belong to the specified knowledge folder
* The knowledge folder must be shared with your API key
* Deleting an attachment removes it from search results immediately
* Embeddings associated with the attachment are also deleted

<Info>
  Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on [API Key Best Practices](/en/admin/ai-adoption-and-rollout/best-practices/api-key-best-practices).
</Info>


## OpenAPI

````yaml delete /knowledge/{folderId}/{attachmentId}
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
security:
  - bearerAuth: []
paths:
  /knowledge/{folderId}/{attachmentId}:
    delete:
      summary: Delete a file from a knowledge folder
      parameters:
        - name: folderId
          in: path
          required: true
          description: The ID of the knowledge folder
          schema:
            type: string
        - name: attachmentId
          in: path
          required: true
          description: The ID of the attachment to delete
          schema:
            type: string
      responses:
        '200':
          description: Attachment deleted successfully
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````