Files

Functions to support your AI Agents.


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

Upload Files

Searches the web for search terms

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
files=[
    ('files',('file1.pdf',open('/path/to/file1.pdf','rb'),'application/pdf')),
    ('files',('files2.pdf',open('/path/to/file2.pdf','rb'),'application/pdf'))
]

response = requests.request("POST", url, headers=headers, files=files)

Response

[
    {
        "url": "https://ailib-public.s3-us-west-2.amazonaws.com/corbett/arani@ailibrary.ai/file1.pdf",
        "id": 2345
    }
]

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

List Files

Retrieves a list of all files.

Request parameters

  • Name
    page
    Type
    string
    Required
    optional
    Description

    Page number

  • Name
    limit
    Type
    string
    Required
    optional
    Description

    Number of items per page

Request

GET
/v1/files
import requests

url = "https://api.ailibrary.ai/v1/files?page=1"
headers = {
    'X-Library-Key': '••••••'
}

response = requests.request("GET", url, headers=headers)

Response

{
  "files": [
      {
          "bytes": 9505,
          "created_timestamp": "2024-12-10 05:18:49",
          "id": 2573,
          "name": "file_1.csv",
          "url": "https://ailib-public.s3-us-west-2.amazonaws.com/you@domain.ai/file_1.csv"
      },
      {
          "bytes": 9505,
          "created_timestamp": "2024-12-10 05:18:49",
          "id": 2573,
          "name": "file_2.csv",
          "url": "https://ailib-public.s3-us-west-2.amazonaws.com/you@domain.ai/file_2.csv"
      },
      /// ...
  ],
  "meta": {
      "limit": 10,
      "next_page": 3,
      "prev_page": 1,
      "total_items": 1037
  }
}

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

Retrieve a file

Retrieves a file by ID.

Request parameters

  • Name
    fileId
    Type
    string
    Required
    required
    Description

    ID of the file

Request

GET
/v1/files/{fileId}
import requests

url = "https://api.ailibrary.ai/v1/files/{fileId}"
headers = {
    'X-Library-Key': '••••••'
}

response = requests.request("GET", url, headers=headers)

Response

{
    "bytes": 9505,
    "created_timestamp": "2024-12-10 05:18:49",
    "id": 2573,
    "name": "file_1.csv",
    "url": "https://ailib-public.s3-us-west-2.amazonaws.com/you@domain.ai/file_1.csv"
}

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

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
    fileId
    Type
    string
    Required
    required
    Description

    ID of the file

Request

DELETE
/v1/files/{fileId}
import requests

url = "https://api.ailibrary.ai/v1/files/{fileId}"
headers = {
    'X-Library-Key': '••••••'
}

response = requests.request("DELETE", url, headers=headers)

Response

{
    "response": "Record successfully deleted"
}

Was this page helpful?