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

    Upload File to Knowledge Folder

    Upload a new file to a knowledge folder

    Upload File to Knowledge Folder

    Upload a new file to 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

    Uploads a new file to a specified knowledge folder. The file will be processed, embedded, and made available for semantic search.

    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

    This endpoint accepts multipart/form-data requests with the file attached.

    Path Parameters

    ParameterTypeRequiredDescription
    folderIdstringYesThe ID of the knowledge folder

    Form Fields

    FieldTypeRequiredDescription
    filefileYesThe file to upload (max 256MB)
    urlstringNoOptional source URL to associate with the file

    Supported File Types

    Knowledge folders support the following document types:

    • PDF (.pdf)
    • Word documents (.doc, .docx)
    • Text files (.txt)
    • Markdown (.md)
    • HTML (.html)
    • PowerPoint (.pptx, .ppt)

    Executable files and other potentially dangerous file types are blocked for security reasons.

    Examples

    Upload a File with cURL

    curl -X POST "https://api.odeus.ai/knowledge/{folderId}" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -F "file=@/path/to/document.pdf"
    

    Upload a File with JavaScript

    const FormData = require("form-data");
    const fs = require("fs");
    const axios = require("axios");
    
    async function uploadFile(folderId, filePath) {
      const form = new FormData();
      form.append("file", fs.createReadStream(filePath));
    
      const response = await axios.post(
        `https://api.odeus.ai/knowledge/${folderId}`,
        form,
        {
          headers: {
            Authorization: "Bearer YOUR_API_KEY",
            ...form.getHeaders(),
          },
        }
      );
    
      return response.data;
    }
    

    Upload with Source URL

    const FormData = require("form-data");
    const fs = require("fs");
    const axios = require("axios");
    
    async function uploadFileWithUrl(folderId, filePath, sourceUrl) {
      const form = new FormData();
      form.append("file", fs.createReadStream(filePath));
      form.append("url", sourceUrl);
    
      const response = await axios.post(
        `https://api.odeus.ai/knowledge/${folderId}`,
        form,
        {
          headers: {
            Authorization: "Bearer YOUR_API_KEY",
            ...form.getHeaders(),
          },
        }
      );
    
      return response.data;
    }
    

    Response Format

    Success Response (200 OK)

    {
      status: "success";
      result: {
        id: string;          // Unique attachment ID
        name: string;        // Original filename
        mimeType: string;    // MIME type of the file
        createdAt: string;   // ISO 8601 timestamp
        updatedAt: string;   // ISO 8601 timestamp
        url: string | null;  // Source URL if provided
      };
    }
    

    Example Response

    {
      "status": "success",
      "result": {
        "id": "att_abc123def456",
        "name": "quarterly-report.pdf",
        "mimeType": "application/pdf",
        "createdAt": "2025-01-15T10:30:00.000Z",
        "updatedAt": "2025-01-15T10:30:00.000Z",
        "url": null
      }
    }
    

    Error Handling

    try {
      const response = await uploadFile(folderId, filePath);
    } catch (error) {
      if (error.response) {
        switch (error.response.status) {
          case 400:
            console.error("Invalid request:", error.response.data.message);
            // Possible causes: missing file, unsupported file type, invalid folder ID
            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 not found");
            break;
          case 408:
            console.error("Upload request timed out");
            break;
          case 413:
            console.error("File size exceeds 256MB limit");
            break;
          case 429:
            console.error("Rate limit exceeded");
            break;
          case 500:
            console.error("Server error");
            break;
        }
      }
    }
    

    Processing Status

    After upload, the file is processed asynchronously. Use the Retrieve Files endpoint to check processing status. The syncStatus field indicates the current state:

    • UPLOADING - File is being uploaded
    • UPLOADED - File is uploaded and queued for processing
    • EXTRACTING - Text is being extracted from the file
    • EMBEDDING - Embeddings are being generated
    • SYNCED - File is ready for search
    • ACTION_FAILED, EXTRACTION_FAILED, EMBEDDING_FAILED, TIMEOUT - Processing failed

    Async Upload Variant

    For large files or when you don't need to wait for the upload response, you can use the async upload endpoint:

    POST /knowledge/{folderId}/upload-async
    

    This endpoint accepts the same multipart/form-data fields and returns 202 Accepted after the file is received. Processing continues in the background.

    {
      "status": "processing",
      "result": {
        "id": "att_abc123def456",
        "name": "quarterly-report.pdf",
        "mimeType": "application/pdf",
        "createdAt": "2025-01-15T10:30:00.000Z",
        "updatedAt": "2025-01-15T10:30:00.000Z",
        "url": null,
        "processingStatus": "UPLOADED",
        "statusUrl": "/api/public/knowledge/{folderId}/{attachmentId}"
      },
      "message": "File uploaded successfully and is being processed in the background. Poll the statusUrl to check when processing completes (syncStatus: SYNCED)."
    }
    

    Use GET {statusUrl} to poll processing status. The response returns the current status in result.syncStatus.

    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}:
        post:
          summary: Upload a file to a knowledge folder
          parameters:
            - name: folderId
              in: path
              required: true
              description: The ID of the knowledge folder
              schema:
                type: string
          requestBody:
            required: true
            content:
              multipart/form-data:
                schema:
                  type: object
                  properties:
                    file:
                      type: string
                      format: binary
                      description: The file to upload
                    url:
                      type: string
                      description: The associated URL
          responses:
            '200':
              description: File uploaded successfully
          security:
            - bearerAuth: []
    components:
      securitySchemes:
        bearerAuth:
          type: http
          scheme: bearer
          bearerFormat: API Key
          description: API key as Bearer token. Format "Bearer YOUR_API_KEY"