> ## 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 API

> Delete an uploaded attachment by ID

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

Delete an attachment by its ID. The attachment must belong to the same workspace as the API key and must either be created by the API key's creator or belong to a Knowledge base shared with the API key.

<Info>
  Requires an API key with the `KNOWLEDGE_FOLDER_API` scope. You can create API Keys in your [Workspace
  settings](https://app.langdock.com/settings/workspace/products/api).
</Info>

## Request Format

Send the attachment ID in the request body as JSON.

| Parameter      | Type   | Required | Description                          |
| -------------- | ------ | -------- | ------------------------------------ |
| `attachmentId` | string | Yes      | The UUID of the attachment to delete |

## Response Format

```typescript theme={null}
{
  success: true;
  message: string;
  attachmentId: string;
}
```

## Example

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

async function deleteAttachment(attachmentId) {
  const response = await axios.delete(
    "https://api.langdock.com/attachment/v1/delete",
    {
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      data: { attachmentId },
    }
  );

  console.log(response.data);
  // {
  //   success: true,
  //   message: "Attachment deleted successfully",
  //   attachmentId: "550e8400-e29b-41d4-a716-446655440000"
  // }
}
```

## Error Handling

```javascript theme={null}
try {
  await deleteAttachment("550e8400-e29b-41d4-a716-446655440000");
} catch (error) {
  if (error.response) {
    switch (error.response.status) {
      case 400:
        console.error("Invalid request body:", error.response.data.message);
        break;
      case 401:
        console.error("Invalid API key");
        break;
      case 403:
        console.error("API key does not have access to this attachment");
        break;
      case 404:
        console.error("Attachment not found");
        break;
      case 500:
        console.error("Server error");
        break;
    }
  }
}
```

<Warning>
  A deleted attachment can no longer be referenced in Agent conversations or restored via the API.
</Warning>

<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 /attachment/v1/delete
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
security:
  - bearerAuth: []
paths:
  /attachment/v1/delete:
    delete:
      tags:
        - Attachments
      summary: Delete an attachment
      description: >-
        Soft-deletes an attachment by ID. The attachment must be created by the
        API key's creator or belong to a Knowledge base shared with the API key.
      operationId: deleteAttachment
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - attachmentId
              properties:
                attachmentId:
                  type: string
                  format: uuid
                  description: The ID of the attachment to delete
      responses:
        '200':
          description: Attachment deleted successfully
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - message
                  - attachmentId
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Attachment deleted successfully
                  attachmentId:
                    type: string
                    format: uuid
                    description: The ID of the deleted attachment
        '400':
          description: Invalid request body
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  errors:
                    type: array
                    items: {}
        '401':
          description: Invalid API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
        '403':
          description: API key does not have access to this attachment
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '404':
          description: Attachment not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````