Skip to content

swanlab api

bash
swanlab api [OPTIONS] COMMAND ARGS [ARGS]

swanlab api is the CLI implementation of the OpenAPI, allowing direct manipulation of cloud workspace / project / experiment / user / self-hosted resources from the command line.

Authentication follows the same logic as the Python API: pass --api-key / --host explicitly, or use the swanlab login local session. See Authentication.

Subcommand Overview

workspace — Workspace

SubcommandDescription
swanlab api workspace info <username>Get workspace info

project — Project

SubcommandDescription
swanlab api project info <path>Get project info
swanlab api project listList projects under a workspace
swanlab api project createCreate a project

run — Experiment

SubcommandDescription
swanlab api run info <path>Get experiment info
swanlab api run listList experiments under a project
swanlab api run filterFilter experiments by query
swanlab api run metricsGet experiment scalar metrics
swanlab api run summaryGet experiment metric summaries
swanlab api run columnGet a single experiment column
swanlab api run columnsList experiment columns
swanlab api run mediasGet experiment media metrics
swanlab api run logsGet experiment console logs
swanlab api run export-logsExport experiment logs as a file

user — User

SubcommandDescription
swanlab api user infoGet current user info

self-hosted — Self-Hosted Management

Requires super admin privileges.

SubcommandDescription
swanlab api self-hosted infoGet instance info
swanlab api self-hosted create-userCreate a user
swanlab api self-hosted list-usersList all users
swanlab api self-hosted list-projectsList all projects
swanlab api self-hosted summarySystem usage summary
swanlab api self-hosted list-workspacesList all workspaces

Common Options

All swanlab api subcommands support:

OptionDescription
-h, --hostSwanLab server host address
-k, --api-keyAPI key; takes precedence over local login
--saveSave output as JSON file; pass a filename or omit for auto-generated name

Subcommand Reference

workspace info

Get detailed information about a workspace.

bash
swanlab api workspace info <username> [OPTIONS]
Argument/OptionTypeDescription
usernamePositionalWorkspace username (unique ID)
--saveOptionSave output as JSON file; pass a filename or omit for auto-generated name
bash
# View workspace info
swanlab api workspace info my-team

# Save to file
swanlab api workspace info my-team --save workspace.json

project info

Get detailed information about a project.

bash
swanlab api project info <path> [OPTIONS]
Argument/OptionTypeDescription
pathPositionalProject path, format: username/project-name
--saveOptionSave output as JSON file
bash
swanlab api project info my-team/image-classification

project list

List all projects under a workspace.

bash
swanlab api project list [OPTIONS]
OptionTypeDefaultDescription
--workspacestrCurrent logged-in userWorkspace username
--page_num / -nint1Page number
--page_size / -sstr"20"Page size; valid values: "10", "20", "50", "100"
--allFlagFalseAuto-paginate, fetch all projects
--saveOptionSave output as JSON file
bash
# List projects for current workspace
swanlab api project list

# List projects for a specific workspace, 50 per page
swanlab api project list --workspace my-team --page_size 50

# Fetch all projects
swanlab api project list --workspace my-team --all

project create

Create a new project in a workspace.

bash
swanlab api project create [OPTIONS]
OptionTypeDefaultDescription
-n / --namestrRequiredProject name (1–100 chars, 0-9a-zA-Z-_.+ only)
-v / --visibilitystr"PRIVATE"Visibility: PUBLIC or PRIVATE
-d / --descriptionstrNoneProject description
-w / --workspacestrCurrent logged-in userWorkspace username
--saveOptionSave output as JSON file
bash
# Create a private project
swanlab api project create -n my-project -v PRIVATE

# Create a public project in a specific workspace
swanlab api project create -n my-project -v PUBLIC -w my-team -d "Image classification experiments"

run info

Get detailed information about an experiment.

bash
swanlab api run info <path> [OPTIONS]
Argument/OptionTypeDescription
pathPositionalExperiment path, format: username/project-name/experiment-id
--saveOptionSave output as JSON file
bash
swanlab api run info my-team/image-classification/abc123

run list

List all experiments under a project.

bash
swanlab api run list [OPTIONS]
OptionTypeDefaultDescription
--project_path / -pstrRequiredProject path, format: username/project-name
--page_num / -nint1Page number
--page_size / -sstr"20"Page size
--allFlagFalseAuto-paginate, fetch all experiments
--saveOptionSave output as JSON file
bash
# List experiments in a project
swanlab api run list -p my-team/image-classification

# Fetch all experiments
swanlab api run list -p my-team/image-classification --all

run filter

Query experiments by filter conditions. Use a JSON array to specify one or more filter rules.

bash
swanlab api run filter --project_path <path> --filter_query <json> [OPTIONS]
OptionTypeDescription
--project_path / -pstrRequired, project path
--filter_query / -fstrRequired, filter conditions (JSON array or path to JSON file)
--saveOptionSave output as JSON file

Each filter rule is a JSON object:

json
{
  "key": "<field name>",
  "type": "STABLE | CONFIG | SCALAR",
  "op": "EQ | NEQ | GT | LT | GTE | LTE | CONTAIN | NOT_CONTAIN",
  "value": ["<value>"]
}

type value reference:

typekey valuesvalue description
STABLEstate, name, description, show, pin, labels, createdAt, updatedAt, finishedAt, etc.The corresponding field value
CONFIGConfig parameter name (e.g. param_2, no config. prefix)Config parameter value
SCALARScalar metric name (e.g. loss)Metric value
bash
# Query finished experiments
swanlab api run filter \
  -p my-team/image-classification \
  -f '[{"key": "state", "type": "STABLE", "op": "EQ", "value": ["FINISHED"]}]'

# Read filter conditions from file
swanlab api run filter -p my-team/image-classification -f ./filter.json

run metrics

Get scalar metrics for an experiment, returned as JSON.

bash
swanlab api run metrics <path> --keys <keys> [OPTIONS]
OptionTypeDefaultDescription
pathPositionalRequiredExperiment path
--keysstrRequiredComma-separated metric keys, e.g. "loss,acc"
--sample / -sint1500Sample size; auto-capped if exceeded
--ignore-timestampFlagFalseRemove timestamp field from metric data
--allFlagFalseFetch full data (CSV export for scalars)
--range-typestrNoneRange query type: step or timestamp
--range-startintNoneRange start (inclusive), step number or unix timestamp in ms
--range-endintNoneRange end (inclusive), step number or unix timestamp in ms
--range-headintNoneReturn first N data points
--range-tailintNoneReturn last N data points
--saveOptionSave output as JSON file

RangeQuery

--range-head and --range-tail are mutually exclusive. --range-start and --range-end work with --range-type (step or timestamp); timestamps are in milliseconds.

bash
# Get loss metric (default 1500 samples)
swanlab api run metrics my-team/image-classification/abc123 --keys loss

# Get multiple metrics, 500 samples
swanlab api run metrics my-team/image-classification/abc123 --keys loss,acc -s 500

# Range query by step
swanlab api run metrics my-team/image-classification/abc123 \
  --keys loss --range-type step --range-start 100 --range-end 500

# Get last 200 data points
swanlab api run metrics my-team/image-classification/abc123 \
  --keys loss --range-tail 200

run summary

Get scalar metric summaries for an experiment (final value, min, max, etc.).

bash
swanlab api run summary <path> [OPTIONS]
OptionTypeDescription
pathPositionalExperiment path
--keysstrComma-separated metric keys; omit for all keys
--saveOptionSave output as JSON file
bash
# Get summary for all metrics
swanlab api run summary my-team/image-classification/abc123

# Get summary for specific metrics
swanlab api run summary my-team/image-classification/abc123 --keys loss,acc

run column

Get a single metric column for an experiment.

bash
swanlab api run column <path> --key <key> [OPTIONS]
OptionTypeDefaultDescription
pathPositionalRequiredExperiment path
--keystrRequiredColumn key name
--classstr"CUSTOM"Column class: CUSTOM or SYSTEM
--typestrNoneColumn data type: FLOAT, STRING, IMAGE, etc.
--saveOptionSave output as JSON file
bash
swanlab api run column my-team/image-classification/abc123 --key loss

run columns

List all metric columns for an experiment.

bash
swanlab api run columns <path> [OPTIONS]
OptionTypeDefaultDescription
pathPositionalRequiredExperiment path
--page_num / -nint1Page number
--page_size / -sstr"20"Page size
--classstr"CUSTOM"Column class filter
--typestrNoneColumn data type filter
--allFlagFalseAuto-paginate, fetch all columns
--saveOptionSave output as JSON file
bash
# List all columns
swanlab api run columns my-team/image-classification/abc123

# List SYSTEM FLOAT columns only
swanlab api run columns my-team/image-classification/abc123 \
  --class SYSTEM --type FLOAT --all

run medias

Get media metrics (images, audio, etc.) for an experiment. Returns presigned URLs.

bash
swanlab api run medias <path> --keys <keys> [OPTIONS]
OptionTypeDefaultDescription
pathPositionalRequiredExperiment path
--keysstrRequiredComma-separated media keys, e.g. "image,audio"
--step / -sint0Step number
--allFlagFalseFetch all steps
--saveOptionSave output as JSON file
bash
# Get image metric at step 0
swanlab api run medias my-team/image-classification/abc123 --keys generated_image

# Get all audio steps
swanlab api run medias my-team/image-classification/abc123 --keys audio --all

run logs

Get console logs for an experiment.

bash
swanlab api run logs <path> [OPTIONS]
OptionTypeDefaultDescription
pathPositionalRequiredExperiment path
--offset / -oint0Log shard index
--level / -lstr"INFO"Log level: DEBUG, INFO, WARN, ERROR
--ignore-timestampFlagFalseRemove timestamp field
--saveOptionSave output as JSON file
bash
# Get INFO level logs
swanlab api run logs my-team/image-classification/abc123

# Get WARN and above
swanlab api run logs my-team/image-classification/abc123 --level WARN

# Get specific shard
swanlab api run logs my-team/image-classification/abc123 --offset 1

run export-logs

Export experiment logs as a downloadable .log file.

bash
swanlab api run export-logs <path> [OPTIONS]
OptionTypeDefaultDescription
pathPositionalRequiredExperiment path
--startint0Start row index (0-based)
--rows / -rint500000Number of rows to export, max 500000
--saveOptionSave output as JSON file (includes download URL)
bash
# Export first 10000 rows
swanlab api run export-logs my-team/image-classification/abc123 --rows 10000

user info

Get current logged-in user information.

bash
swanlab api user info [OPTIONS]
OptionDescription
--saveSave output as JSON file
bash
swanlab api user info

self-hosted info

Get self-hosted instance information.

bash
swanlab api self-hosted info [OPTIONS]
OptionDescription
--saveSave output as JSON file
bash
swanlab api self-hosted info

self-hosted create-user

Create a new user in the self-hosted instance (super admin only).

bash
swanlab api self-hosted create-user [OPTIONS]
OptionTypeDescription
-u / --usernamestrRequired, new username
-p / --passwordstrRequired, new user password
--saveOptionSave output as JSON file
bash
swanlab api self-hosted create-user -u testuser -p test123456

self-hosted list-users

List all users in the self-hosted instance (super admin only).

bash
swanlab api self-hosted list-users [OPTIONS]
OptionTypeDefaultDescription
--page_num / -nint1Page number
--page_size / -sint20Page size
--allFlagFalseAuto-paginate, fetch all users
--saveOptionSave output as JSON file
bash
# List all users
swanlab api self-hosted list-users --all

self-hosted list-projects

List all projects in the self-hosted instance (super admin only).

bash
swanlab api self-hosted list-projects [OPTIONS]
OptionTypeDefaultDescription
--page_num / -nint1Page number
--page_size / -sint20Page size
--allFlagFalseAuto-paginate, fetch all projects
--searchstrNoneSearch keyword
--creatorstrNoneFilter by creator username
--workspacestrNoneFilter by workspace username
--saveOptionSave output as JSON file
bash
# List all projects
swanlab api self-hosted list-projects --all

# Search for projects
swanlab api self-hosted list-projects --search image --all

self-hosted summary

Get system usage summary for the self-hosted instance (super admin only).

bash
swanlab api self-hosted summary [OPTIONS]
OptionDescription
--saveSave output as JSON file
bash
swanlab api self-hosted summary

self-hosted list-workspaces

List all workspaces in the self-hosted instance (super admin only).

bash
swanlab api self-hosted list-workspaces [OPTIONS]
OptionTypeDefaultDescription
--page_num / -nint1Page number
--page_size / -sint20Page size
--allFlagFalseAuto-paginate, fetch all workspaces
--searchstrNoneSearch keyword
--saveOptionSave output as JSON file
bash
# List all workspaces
swanlab api self-hosted list-workspaces --all