LC now supports a Slurm REST API on Matrix. This means users and their applications can interact with Matrix's scheduler from other systems on the CZ, allowing for automated and remote job submission and monitoring. The Slurm REST API comes online as part of a larger effort to enable Slurm MCP servers that will expose cluster functionality to AI coding agents at a TBD date. 

Getting Started

Authentication

Any host on the CZ that can reach Matrix can act as a client and submit jobs through Matrix’s REST API endpoint. 

To authenticate, generate a time-limited JSON web token (JWT) on Matrix, then set it as an environment variable on each client host you use.

Token creation

Log in to Matrix. To generate a JWT, you can use the syntax scontrol token lifespan=<time in seconds>. You'll then need to export the token as SLURM_JWT on another CZ system. For security, we recommend you write the token and export command directly to a private file:

(umask 077; echo "export $(scontrol token lifespan=7200)" > ~/.slurm_jwt)

For reference, the output of scontrol token lifespan=… looks like

user@matrix1:~$ scontrol token lifespan=7200
SLURM_JWT=eyJhbGciOiJIUzI1NiIs….

Token declaration

Log in to another CZ system and load your token. If you've created ~/.slurm_jwt, simply run

user@dane2:~$ source ~/.slurm_jwt

This sets the variable SLURM_JWT.

Example commands

Common ways to issue requests to Matrix's Slurm REST API include curl and python commands, all of which will include the base url, https://matrix.llnl.gov:4443/slurm/v<version> and authentication information.

All of the commands below can be issued on CZ machines.

Determine versioning

First, determine the versions of the REST API available:

curl -fsSL \
  -H "X-SLURM-USER-TOKEN: $SLURM_JWT" \
  "https://matrix.llnl.gov:4443/openapi/v3" |
  jq -r '.paths | keys[]' |
  grep '/ping'

This will produce a list of available versions that you can use to update your base url. Alternatively, you can run the following command to set the variable VERSION, which will be used throughout the following instructions.

export VERSION=$(
  curl -fsSL \
    -H "X-SLURM-USER-TOKEN: $SLURM_JWT" \
    "https://matrix.llnl.gov:4443/openapi/v3" |
    jq -r '.paths | keys[]' |
    grep '/ping' |
    sed -E 's#^.*/(v[0-9]+\.[0-9]+\.[0-9]+)/ping/$#\1#' |
    sort -V |
    tail -n 1
)

Ping the REST API

You can use the following curl command to check if the Slurm REST API is up:

curl -L -H "Content-Type: application/json" -H "X-SLURM-USER-TOKEN:$SLURM_JWT" -X GET "https://matrix.llnl.gov:4443/slurm/${VERSION}/ping"

Example output:

user@dane2:~$ curl -L -H "Content-Type: application/json" \
>         -H "X-SLURM-USER-TOKEN:$SLURM_JWT" \
>         -X GET "https://matrix.llnl.gov:4443/slurm/${VERSION}/ping"
{
   "pings": [
     {
       "hostname": "matrix3",
       "pinged": "UP",
       "responding": true,
       "latency": 1468,
       "mode": "primary",
       "primary": true
     }
   ],
   "meta": {
     "plugin": {
       "type": "openapi\/slurmctld",
       "name": "Slurm OpenAPI slurmctld",
       "data_parser": "data_parser\/v0.0.44",
       "accounting_storage": "accounting_storage\/slurmdbd"
     },
     "client": {
       "source": "localhost:6820(fd:10)",
       "user": "root",
       "group": "root"
     },
     "command": [
     ],
     "slurm": {
       "version": {
         "major": "25",
         "micro": "8",
         "minor": "11"
       },
       "release": "25.11.8",
       "cluster": "matrix"
     }
   },
   "errors": [
   ],
   "warnings": [
   ]
 }

Submit and monitor a job using Python

First, define the token and endpoint. Run this once per Python session; the examples below depend on it:

import os
import requests
slurm_token = os.environ["SLURM_JWT"]
version = os.environ["VERSION"] base_url = f"https://matrix.llnl.gov:4443/slurm/{version}"
my_bank = "<Add your bank here!>"
working_dir = "<add the working directory>" headers = {
"X-SLURM-USER-TOKEN": slurm_token,
"Content-Type": "application/json",
}

Specify job details (including working directory, bank, resources required, and the script to be run):

job_spec = {
    "job": {
        "name": "api-test",
        "account": my_bank,
        "partition": "pdebug",
        "nodes": "1",
        "tasks": 2,
        "time_limit": 5,
        "current_working_directory": working_dir,
        "environment": [
           "PATH=/usr/local/bin:/usr/bin:/bin"
        ]
    },
    "script": "#!/bin/bash\nsrun hostname\nsleep 60\n"
}

Try submitting this job:

submit = requests.post(f"{base_url}/job/submit", headers=headers, json=job_spec)
submit.raise_for_status()
job_id = submit.json()["job_id"]
print(job_id)

If you let this job run, slurm-<job_id>.out will be written to the current_working_directory defined in job_spec.

Check the status of the job:

response = requests.get(f"{base_url}/job/{job_id}", headers=headers)
job = response.json()["jobs"][0]
print(f"Job {job['job_id']} | {job['name']} | {job['user_name']} | {','.join(job['job_state'])}")

Cancel the job:

cancel = requests.delete(f"{base_url}/job/{job_id}", headers=headers)
cancel.raise_for_status()

Multi-node jobs

To request multiple nodes on Matrix, you will have to explicitly request at least as many GPUs because Matrix is GPU-allocated. (Matrix has 4 GPUs/node so for N nodes, request between N and 4N GPUs per job.)

You can request GPUs in the JSON job spec using either the "tres_per_node": "gres:gpu:<number of GPUs per node>" parameter or "tres_per_job": "gres:gpu:<number of GPUs per job>". 

Note: You cannot run multi-node jobs in `pdebug` so move to `pbatch`.

Here's a job_spec for 2 nodes and 2 GPUs per node:

job_spec = {
    "job": {
        "name": "api-test",
        "account": my_bank,
        "partition": "pbatch",
        "nodes": "2",
        "tres_per_node": "gres:gpu:2",
        "tasks": 4,
        "time_limit": 5,
        "current_working_directory": working_dir,
        "environment": [
           "PATH=/usr/local/bin:/usr/bin:/bin"
        ]
    },
    "script": "#!/bin/bash\nsrun -N2 -n4 hostname \nsleep 60\n"
}

Resources

Please see the following GitLab repo for additional examples and scripts: https://lc.llnl.gov/gitlab/weg/examples/slurm-rest-api#.

Please see Slurm's documentation on their REST API for more info: https://slurm.schedmd.com/rest.html