Files

The Files API allows you to upload and manage files that can be processed by knowledge bases.


POSThttps://api.ailibrary.ai/v1/files

Upload Files

Upload files so they can be accessed later.

form-data

  • Name
    files
    Type
    file
    Required
    required
    Description

    List of files

  • Name
    knowledgeId
    Type
    string
    Required
    optional
    Description

    Knowledge base ID to add the files to a knowledge base. The file is uploaded to 'home' folder.

Request

POST
/v1/files
file_paths=[
    "path/to/file1.txt",
    # ... other file paths
]

uploaded_files = client.files.upload(
    files=file_paths,
    knowledgeId="kb_abc123"  # Optional
)

Response

[
    {
        "url": "https://domain/corbett/email/file1.txt",
        "id": 1232,
        "bytes": 17,
        "name": "file1.txt",
        "meta": {"type": "document"}
    },
    // ... info objects on other files
]

GEThttps://api.ailibrary.ai/v1/files

List Files

Retrieves a list of all files.

Request parameters

  • Name
    page
    Type
    integer
    Required
    optional
    Description

    Page number

  • Name
    limit
    Type
    integer
    Required
    optional
    Description

    Number of items per page

Request

GET
/v1/files
client.files.list_files(
    page=1,
    limit=10
)

Response

{
    "files": [
        {
            "bytes": 17,
            "created_timestamp": "YYYY-MM-DD hh:mm:ss",
            "id": 1232,
            "name": "file1.txt",
            "url": "https://domain/corbett/email/file1.txt"
        }
    ],
    "meta": {"prev_page": "", "next_page": "2"}
}

GEThttps://api.ailibrary.ai/v1/files/{file_id}

Retrieve a file

Retrieves a file by ID.

Request parameters

  • Name
    file_id
    Type
    integer
    Required
    required
    Description

    ID of the file

Request

GET
/v1/files/{file_id}
file = client.files.get(file_id="file_abc123")

Response

{
    "bytes": 17,
    "created_timestamp": "YYYY-MM-DD hh:mm:ss",
    "id": 1232,
    "name": "file1.txt",
    "url": "https://domain/corbett/email/file1.txt"
}

DELETEhttps://api.ailibrary.ai/v1/files/{file_id}

Delete a file

Delete a file by ID.

Note: Deleting a file does not remove it from knowledge bases. If you want to remove a file from a knowledge base, use the Delete Sources endpoint.

Request parameters

  • Name
    file_id
    Type
    integer
    Required
    required
    Description

    ID of the file

Request

DELETE
/v1/files/{file_id}
client.files.delete(file_id="file_abc123")

Response

{
    "response": "Record successfully deleted"
}

Was this page helpful?