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.
- π§ Python SDK
- π¦ TypeScript SDK
pip install lattica-query
npm install @lattica-ai/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.
- π§ Python SDK
- π¦ TypeScript SDK
import os
from lattica_query import QueryToken
token = QueryToken(os.environ["LATTICA_QUERY_TOKEN"])
import { getDemoToken } from '@lattica-ai/query';
// Use the model ID from the specific demo tutorial.
const modelId = 'demoModelId';
const token = await getDemoToken(modelId);
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.
- π§ Python SDK
- π¦ TypeScript SDK
from lattica_query import QueryClient
import { initWasm, LatticaQueryClient } from '@lattica-ai/query';
initWasm();
const client = new LatticaQueryClient(token);
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.
- π§ Python SDK
- π¦ TypeScript SDK
with QueryClient(token) as client:
key = client.keys.ensure()
await client.init();
Process the requested queryβ
You can now encrypt the input, send the ciphertext to the cloud for processing, and decrypt the encrypted response.
- π§ Python SDK
- π¦ TypeScript SDK
with QueryClient(token) as client:
key = client.keys.ensure()
result = client.query.encrypted(pt, key=key)
const encryptedInput = await client.encrypt(pt);
const encryptedResult = await client.apply_query(encryptedInput);
const result = await client.decrypt(encryptedResult);
The current SDK flow performs four steps:
- Prepares your input using the model's preprocessing rules
- Takes your secret key to encrypt the data into a secure format
- Sends your encrypted data to LatticaAI server and waits for the response
- 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.