Get Upload Sessions Details

Files are uploaded in an upload session. You can list all upload sessions or get a single session to check its status, creation time, and files uploaded.

About This Task

Sessions

Asynchronous upload uses the mechanism of sessions to upload your files to deepset Cloud. A session stores the ingestion status of the files: the number of failed and finished files. Each session has an ID so you can check its details anytime.

A session starts when you initiate the upload. For SDK, it opens when you call the upload method or command and closes when the upload is finished. A session expires after 24 hours. You can have a maximum of 10 open sessions.

When using the SDK, you don't have to worry about the sessions as the SDK takes care of opening and closing them for you. They're just there if you want to check the status of your past and current uploads.

Prerequisites

Upload Files with Python. This creates a session.

List All Sessions Script Examples

Here's an example code you can use to list all active sessions:


from deepset_cloud_sdk.workflows.sync_client.files import list_upload_sessions

for session_batch in list_upload_sessions(
  api_key="<deepset Cloud API key>",
  workspace_name="<your_workspace>",
  is_expired=False,  # Set to True if you want to list expired sessions
  batch_size=100,  # Adjust the batch size as needed
):
  for session in session_batch:  # List of length 100
    print(session.session_id)

from deepset_cloud_sdk.workflows.async_client.files import list_upload_sessions


async def my_async_context() -> None:
    async for session_batch in list_upload_sessions(
        api_key="<deepset Cloud API key>",
        workspace_name="<your_workspace>",
        is_expired=False,  # Set to True if you want to list expired sessions
        batch_size=100,  # Adjust the batch size as needed
    ):
        for session in session_batch:  # List of length 100
            print(session.session_id)

Get Details of a Single Session Script Examples

Here's the code you can use to view a single upload session. (You can get session IDs from the list_upload_sessions() method.)


from deepset_cloud_sdk.workflows.async_client.files import get_upload_session
from uuid import UUID

session_id = UUID(
    "enter-your-session-id-here"
)  # Replace with your actual upload session ID returned by `list_upload_sessions`


session_details = get_upload_session(
  api_key="<deepset Cloud API key>",
  workspace_name="<your_workspace>",
  session_id=session_id,
)
print(session_details)


from deepset_cloud_sdk.workflows.async_client.files import get_upload_session
from uuid import UUID

session_id = UUID(
    "enter-your-session-id-here"
)  # Replace with your actual upload session ID returned by `list_upload_sessions`


async def my_async_context() -> None:
    session_details = await get_upload_session(
        api_key="<deepset Cloud API key>",
        workspace_name="<your_workspace>",
        session_id=session_id,
    )
    print(session_details)

Close a Session

You may need to close a session manually, for example, because you reached the limit of 10 open sessions to trigger file ingestion. You can do so using the Close Session REST API endpoint. You'll need the upload session ID, deepset Cloud API key, and the name of the workspace where you're uploading the files.

Follow the walkthrough of the request code:

or copy this code replacing the variables:

curl --request PUT \
     --url https://api.cloud.deepset.ai/api/v1/workspaces/<WORKSPACE_NAME>/upload_sessions/<SESSION_ID> \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <deepset Cloud API key' \
     --header 'content-type: application/json' \
     --data '{"status":"CLOSED"}'