Skip to main content
Training guide chapters All documentation

Python SDK reference and commands

TrainingClient session methods, TrainingProject methods, constructor options, datasets and runnable examples.

Commands and code stay in English in every language. Replace uppercase placeholders with values from your own account and paid job; do not paste real keys into shared notebooks or logs.

Python SDK interfaces

TrainingClient remains available; TrainingProject manages local project runs.
  1. TrainingClient HTTPS and scoped API key
  2. Session methods Open, prepare and inspect
  3. TrainingProject Plan and train locally
  4. Result Local artifact and reports

TrainingClient: HTTPS and scoped API key. Session methods: Open, prepare and inspect. TrainingProject: Plan and train locally. Result: Local artifact and reports

Create a client securely

TrainingClient accepts an API key, an HTTPS base_url, a finite positive timeout and max_get_retries from 0 to 5. The default timeout is 60 seconds and the default GET retry count is 2. Redirects are rejected. allow_loopback is for explicit local testing only, never a reason to send a real key over an insecure remote connection.

  • Keep code and environment variable names in English across locales.
  • TrainingClient remains available for existing session integrations.
  • Use TrainingProject and fpai-training for schema-based local project runs.
Example · bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
# Install the GPU-compatible PyTorch build for your runtime first.
python -m pip install 'fusionpointai-training[train] @ https://fusionpointai.com/downloads/fusionpointai-training.zip'
# API-only use without local training dependencies:
# python -m pip install 'fusionpointai-training @ https://fusionpointai.com/downloads/fusionpointai-training.zip'
Example · python
import os
from fusionpointai_training import TrainingClient

client = TrainingClient(
    api_key=os.environ["FUSIONPOINTAI_API_KEY"],
    base_url="https://fusionpointai.com/api/v1/training",
    timeout=60.0,
    max_get_retries=2,
)
# transport optionally accepts an httpx transport for controlled integrations.
# Never enable insecure remote HTTP to work around a TLS error.
Example · python
from importlib.metadata import PackageNotFoundError, version
from importlib.util import find_spec

for package in ("fusionpointai-training", "httpx", "torch", "transformers", "peft"):
    try:
        print(f"{package}=={version(package)}")
    except PackageNotFoundError:
        print(f"{package}: not installed")

for module in ("torch", "transformers", "peft", "safetensors"):
    print(f"{module} importable:", find_spec(module) is not None)
# The train extra includes optional model-training dependencies; inspect before use.

Use the public methods

open_session and create_session have the same operation. prepare_session performs bounded preparation. get_session inspects state. download_dataset verifies a DatasetManifest. post_event reports real runtime progress. train runs the session training engine. complete reports a locally produced artifact, and cancel cancels service session state. The method listing below shows the exact TrainingClient signatures retained for existing integrations.

  • reference_model_id is keyword-only and must be a positive integer, not a boolean.
  • max_requests bounds preparation calls; it is not a model-training epoch count.
  • TrainingClient.train accepts a session ID and a new output directory; TrainingProject loads its model path from project configuration.
Example · python
from fusionpointai_training.client import DatasetManifest

# Continue with an authenticated client and an owned session.
ready = client.prepare_session(session["id"])
for item in ready["datasets"]:
    manifest = DatasetManifest(
        split=item["split"], sha256=item["sha256"],
        bytes=item["bytes"], rows=item["rows"],
    )
    rows = client.download_dataset(ready["id"], manifest)
    print(manifest.split, len(rows), manifest.sha256)
    # Each row has a text field. Do not log private training content.
Example · python
# For a genuine external trainer integration, not simulated progress.
def report_progress(client, session_id, *, step, total_steps, loss):
    return client.post_event(session_id, {
        "state": "running",
        "step": step,
        "total_steps": total_steps,
        "metrics": {"loss": loss},
    })
# Supply values observed from your real trainer.
# The built-in train() already reports its progress; do not duplicate it.
Example · python
import json
from pathlib import Path

# Continue with client/session. Inspect state before retrying reporting.
report = json.loads(Path("customer-model-run-001/training-report.json").read_text())
state = client.get_session(session["id"])
if state["status"] == "evaluating":
    state = client.complete(session["id"], report["completion_report"])
print(state["status"])
# Do not restart weight training just to reconcile reporting.
Example · python
import os
from fusionpointai_training import TrainingClient

client = TrainingClient(api_key=os.environ["FUSIONPOINTAI_API_KEY"])
session = client.get_session(os.environ["FUSIONPOINTAI_SESSION_ID"])
report = session.get("report")
last_event = report.get("last_event", {}) if isinstance(report, dict) else {}
print("State:", session["status"], "Step:", session["step"])
print("Last reported error code:", last_event.get("error_code"))
# A missing error_code does not prove success. Read state and your local report.
# Do not dump full provider responses, private data or authorization headers.

Exceptions and expected outputs

TrainingClient raises APIError and IntegrityError for session operations. TrainingProject exposes ConfigurationError, CompatibilityError, AuthenticationError, BudgetExceededError, EvaluationFailedError, CheckpointError, CancellationError and ExportError as TrainingError subclasses. Do not print the environment or authorization headers when debugging. The legacy client methods and new project API have separate contracts.

  • Keep package and dependency versions with each run record.
  • TrainingProject errors retain redacted diagnostics and reports where available.
  • Do not retry a state-changing operation without first reading its state.
Example · python
import os
from fusionpointai_training import TrainingClient
from fusionpointai_training.errors import APIError, IntegrityError, TrainingError

client = TrainingClient(api_key=os.environ["FUSIONPOINTAI_API_KEY"])
try:
    state = client.get_session(os.environ["FUSIONPOINTAI_SESSION_ID"])
    print("Current state:", state["status"])
except IntegrityError:
    print("Integrity check failed; preserve the report and investigate.")
except TrainingError:
    print("Training failed; inspect the local report before retrying.")
except APIError:
    print("Request failed; inspect access and session state before another write.")
except ValueError:
    print("Invalid local configuration; correct the input before retrying.")
# Never print the key or authorization headers.
Example · python
import os
from fusionpointai_training import TrainingClient
from fusionpointai_training.errors import APIError

client = TrainingClient(
    api_key=os.environ["FUSIONPOINTAI_API_KEY"],
    timeout=30.0,
    max_get_retries=2,
)
try:
    session = client.get_session(os.environ["FUSIONPOINTAI_SESSION_ID"])
except APIError:
    # GET retries are bounded. Do not blindly retry a write after an error.
    print("Session inspection failed; check access and current server state.")
else:
    print("Status:", session["status"])
# Never print the API key, authorization headers, or response secrets.

Python interface

  • TrainingClient(api_key: str, *, base_url: str = "https://fusionpointai.com/api/v1/training", allow_loopback: bool = False, timeout: float = 60.0, max_get_retries: int = 2, transport: httpx.BaseTransport | None = None)
  • create_session(job: str, runtime: str, *, reference_model_id: int | None = None) -> dict
  • open_session(job: str, runtime: str, *, reference_model_id: int | None = None) -> dict
  • get_session(session_id: str) -> dict
  • prepare_session(session_id: str, *, max_requests: int | None = None) -> dict
  • DatasetManifest(split: str, sha256: str, bytes: int, rows: int)
  • download_dataset(session_id: str, manifest: DatasetManifest) -> list[dict[str, str]]
  • post_event(session_id: str, event: dict) -> dict
  • train(session_id: str, output_dir: str | os.PathLike[str]) -> dict
  • complete(session_id: str, report: dict) -> dict
  • cancel(session_id: str) -> dict
  • TrainingProject.from_file(path: str | os.PathLike[str], *, api_key: str) -> TrainingProject
  • TrainingProject.plan(*, dry_run: bool = True) -> dict
  • TrainingProject.run() -> dict
  • TrainingProject.status() -> dict
  • TrainingProject.pause() -> dict
  • TrainingProject.resume() -> dict
  • TrainingProject.cancel() -> dict
  • TrainingProject.evaluate(*, split: str = "test") -> dict
  • TrainingProject.export(*, format: str = "safetensors") -> dict
  • register_evaluator(name: str, scorer: Callable, *, version: str) -> None