Skip to main content

API Reference

The methods you call across the four stages. Grouped by client: Lattica Studio for deploy, tokens, and workers, and query for running encrypted inference. Click any method to expand it.

Lattica Studio

Deploy a pipeline and manage tokens and workers. Create it with your License: studio = LatticaStudio(license_key). Models, workers, and tokens are on the same client: studio.models, studio.workers, studio.tokens.

Creates the Lattica Studio client. Pass your License. This client deploys pipelines and reaches models, workers, and tokens.

Signature
def __init__(self, account_license: str)
Parameters
account_licensestr · your License, taken from the console. In snippets this is license_key or LATTICA_LICENSE_KEY.

The deploy envelope. Registers a model or reuses one with the same model_name, uploads the pipeline, and waits for compilation. Returns the model_id. Does not create an access token, start a worker, or generate keys.

Signature
def deploy_pipeline(self, hom_pipeline, hom_params,
                    model_name: str,
                    instance_type=InstanceType.G6E_2XLARGE,
                    num_devices=1,
                    display_graph=False) -> str
Parameters
hom_pipelineThe pipeline you built. A HomomorphicPipeline.
hom_paramsThe encryption parameters, e.g. HomParams.
model_namestr · name for the model. Re-running with the same name redeploys into that model instead of failing.
instance_typeoptionalInstanceType · hardware the worker runs on. Defaults to G6E_2XLARGE. On redeploy, a different value updates the existing model after workers are stopped.
num_devicesoptionalint · number of GPUs to shard the model across. Defaults to 1; anything higher requires an instance type with at least that many GPUs. Cannot be changed on redeploy.
display_graphoptionalbool · print the compiled graph locally after build. Defaults to False.

Creates an access token for a deployed model and optionally writes it to disk under save_as. This is a Key generation step, not part of deploy_pipeline.

Signature
def create(self, model_id: str, *,
            name: str | None = None,
            save_as: str | None = None) -> str
Parameters
model_idstr · the deployed model.
nameoptionalstr · a label for the token on the platform. Generated if omitted.
save_asoptionalstr · local name used later with tokens.load. Use the same string as model_name.

Starts a worker if needed and yields while it is up. Credits begin when the worker comes up. Set stop_on_exit=True to stop it when the block ends.

Signature
def running(self, model_id: str, *,
            stop_on_exit: bool = False)
Parameters
model_idstr · the model to run. Must have compiled successfully.
stop_on_exitoptionalbool · stop the worker when leaving the with block. Defaults to False.

Query client

Run encrypted queries against a deployed pipeline. Load the token from Key generation, then create the client: query_client = QueryClient(studio.tokens.load(model_name)).

Reads the query token saved earlier with tokens.create(..., save_as=name). Pass the string to QueryClient.

Signature
def load(self, name: str) -> str
Parameters
namestr · the same name you passed as save_as when creating the token.

Creates a query client for the given access token. Pass the string from studio.tokens.create or studio.tokens.load.

Signature
def __init__(self, query_token: str)
Parameters
query_tokenstr · the access token for the deployment.

Generates or loads key material after the worker is up. Keeps the secret key on your side and uploads the evaluation key on first generation. Call with load_if_exists=False during Key generation. Call with load_if_exists=True on later query runs to reuse that key.

Signature
def generate_key(self, load_if_exists: bool = False)
Parameters
load_if_existsoptionalbool · if True, load a previously saved key instead of generating a new one. Defaults to False.

Runs one encrypted query. Encrypts your input, sends it to the worker, decrypts the result, and returns it. Run it as many times as you need while the worker is up.

Signature
def run_query(self, sk, pt: torch.Tensor) -> torch.Tensor
Parameters
skThe secret key returned by generate_key.
pttorch.Tensor · your plaintext input, in the shape the pipeline declares.

Workers and models

Worker start and stop are on studio.workers. The documented session pattern is studio.workers.running. Model lookup is on studio.models.

Starts a worker and waits until it is ready. Prefer workers.running in the documented flow. Credits begin when the worker comes up.

Signature
def start(self, model_id: str, *,
            poll_interval: float = 5,
            timeout: float = 600) -> dict
Parameters
model_idstr · the compiled model to run.

Stops a running worker. Credits stop the moment it goes down. Pass model_id to stop workers for that model. Prefer workers.running(..., stop_on_exit=True) in the documented flow.

Signature
def stop(self, model_id: Optional[str] = None,
            session_id: Optional[str] = None) -> dict
Parameters
model_idoptionalstr · stop workers for this model. The documented call is stop(model_id=model_id).
session_idoptionalstr · optional session id, to stop one session.

Returns the current status of a worker session.

Signature
def get(self, model_id: str,
        session_id: str) -> dict
Parameters
model_idstr · the model.
session_idstr · the session to check.

Lists worker sessions, with optional filters by model and date range.

Signature
def list_sessions(self, *, model_id: Optional[str] = None,
                    from_date: Optional[str] = None,
                    to_date: Optional[str] = None) -> list
Parameters
model_idoptionalstr · filter to one model.
from_dateoptionalstr · only sessions started on or after this date.
to_dateoptionalstr · only sessions started on or before this date.

Returns information about a model, including whether it compiled and the compilation error if it did not.

Signature
def get(self, model_id: str) -> dict
Parameters
model_idstr · the model to look up.

The management surface has more methods for account, tokens, and models than the worker controls shown here. Those are admin tasks outside the build, deploy, key generation, and query path. For the full set, see the platform documentation.