Skip to main content

Zooming Into Each Step of Demo Run with LatticaAI flow

Installation & Setup​

Before you begin, ensure you have the following:

  • Python 3.11+ installed on your client machine.
  • Install the current Lattica query package for your SDK.
pip install lattica-query

Authentication & Model ID​

You need a query token to interact with our cloud infrastructure. The token authorizes access to one deployed model and must be kept secure.

Each public model we run on the cloud has its own unique modelID. The specific modelID for each demo is provided in its corresponding tutorial.

For Python, obtain a provider-issued query token for the demo model and store it in the LATTICA_QUERY_TOKEN environment variable. For TypeScript demo applications, getDemoToken requests a short-lived token for the selected public model.

import os

from lattica_query import QueryToken

token = QueryToken(os.environ["LATTICA_QUERY_TOKEN"])

In our web demo version, the client logic is initialized automatically in your browserβ€”no separate install or setup is required. The web page manages your authentication and sets the appropriate Model ID behind the scenes.


Generating & Registering Keys​

The query client handles local cryptographic operations and communication with the LatticaAI server. Initialize it with the token you obtained.

from lattica_query import QueryClient

Our encryption scheme relies on a secret key (which stays on your machine) and an evaluation key (EVK) (sent to LatticaAI cloud server).

One key pair can be reused for multiple demo sessions.

with QueryClient(token) as client:
key = client.keys.ensure()

Process the requested query​

You can now encrypt the input, send the ciphertext to the cloud for processing, and decrypt the encrypted response.

with QueryClient(token) as client:
key = client.keys.ensure()
result = client.query.encrypted(pt, key=key)

The current SDK flow performs four steps:

  1. Prepares your input using the model's preprocessing rules
  2. Takes your secret key to encrypt the data into a secure format
  3. Sends your encrypted data to LatticaAI server and waits for the response
  4. Decrypts what comes back and turns it into a ready-to-use SDK tensor

In Python, client.query.encrypted(...) performs these steps in one call. The TypeScript SDK exposes the same flow as encrypt, apply_query, and decrypt, which is useful when a web interface displays each stage separately.