For the complete documentation index, see llms.txt. This page is also available as Markdown.

Example script: Starting a data generation job

Kicking off a data generation using Python. Note the version that this script was tested against.

tonic_generation.py
# Note that our API does not guarantee backward compatibility.
# For the endpoints and parameters for your exact version, view the 
# Swagger API documentation that comes with your instance.
# If you use Structural Cloud, the API documentation is at:
# https://app.tonic.ai/apidocs/index.html

# Tested 2026.07.08 with Tonic API v2024.01.0

import json
import requests

TONIC_API_KEY = "<<STRUCTURAL API TOKEN>>"
TONIC_URL = "https://<<STRUCTURAL HOSTNAME>>"
WORKSPACE_NAME = "<<STRUCTURAL WORKSPACE>>"


class TonicSession:
    def __init__(self, base_url, api_key):
        self._base_url = base_url
        self._session = requests.Session()
        self._session.headers.update({"Authorization": "Apikey {}".format(api_key)})

    def _get_url(self, api_snippet):
        return "{}{}".format(self._base_url, api_snippet)

    def generate_data(self, workspace_id):
        generate_data_url = self._get_url("/api/generateData/start")
        params = {"workspaceId": workspace_id}
        r = self._session.post(generate_data_url, params=params)
        if r.ok:
            print("Data generation started")
            print(json.dumps(r.json(), indent=2))
        else:
            r.raise_for_status()

    def generate_data_status(self, workspace_id):
        generate_data_status_url = self._get_url("/api/generateData")
        params = {"workspaceId": workspace_id}
        r = self._session.get(generate_data_status_url, params=params)
        if r.ok:
            print(json.dumps(r.json(), indent=2))
        else:
            r.raise_for_status()

    def find_workspace_by_name(self, workspace_name):
        search_url = self._get_url("/api/Workspace/search")
        params = {"filters[name]": workspace_name}
        r = self._session.get(search_url, params=params)
        if r.ok:
            records = r.json().get("records", [])
            matches = [w for w in records if w["workspaceName"] == workspace_name]
            if len(matches) == 1:
                return matches[0]["id"]
            elif len(matches) == 0:
                raise RuntimeError("No workspace found with name: {}".format(workspace_name))
            else:
                raise RuntimeError("Multiple workspaces found with name: {}".format(workspace_name))
        else:
            r.raise_for_status()


def main():
    session = TonicSession(TONIC_URL, TONIC_API_KEY)

    print("=== GET /api/Workspace/search ===")
    workspace_id = session.find_workspace_by_name(WORKSPACE_NAME)
    print("Found workspace: {} ({})".format(WORKSPACE_NAME, workspace_id))

    print("\n=== GET /api/generateData (status) ===")
    session.generate_data_status(workspace_id)

    print("\n=== POST /api/generateData/start ===")
    session.generate_data(workspace_id)


if __name__ == "__main__":
    main()

Last updated

Was this helpful?