We use cookies to enhance your experience and measure how the site performs. Choose "Essential Only" to disable analytics. Read our Privacy Policy.

    Odeus Docs

    Delete Attachment from Knowledge Folder

    Remove a file from a knowledge folder

    Delete Attachment from Knowledge Folder

    Remove a file from a knowledge folder

    Using our API via a dedicated deployment? Just replace api.odeus.ai with your deployment's base URL: <deployment-url>/api/public

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

    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 for setup instructions.

    Request Format

    Path Parameters

    ParameterTypeRequiredDescription
    folderIdstringYesThe ID of the knowledge folder
    attachmentIdstringYesThe ID of the attachment to delete

    Examples

    Delete with cURL

    curl -X DELETE "https://api.odeus.ai/knowledge/{folderId}/{attachmentId}" \
      -H "Authorization: Bearer YOUR_API_KEY"
    

    Delete with JavaScript

    const axios = require("axios");
    
    async function deleteAttachment(folderId, attachmentId) {
      const response = await axios.delete(
        `https://api.odeus.ai/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

    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)

    {
      status: "success";
      message: "Attachment deleted";
    }
    

    Example Response

    {
      "status": "success",
      "message": "Attachment deleted"
    }
    

    Error Handling

    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

    Deletion is permanent. The file and all associated embeddings will be removed and cannot be recovered.

    • 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

    Odeus 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.

    OpenAPI

    openapi: 3.0.0
    info:
      title: Odeus API
      version: 3.0.0
    servers:
      - url: https://api.odeus.ai
    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"