Skip to content

First job

Run nvidia-smi on one spot H100, wait for it, and print the record. The same job in three forms.

View example files ↗: job_quickstart.py · job_quickstart.yaml · job_quickstart.sh · Related reference: Jobs →

examples/quickstarts/job_quickstart.py
"""The README quickstart.

``["nvidia-smi"]``, ``gpu="h100"``, and timeout ``1h``. Uses the active
Nebius profile.
"""

import nebius_serverless as ns


def main() -> None:
    """Create the README job, wait for it, and print the final record."""

    # Describe what should run, then create it once. Nothing is sent to
    # Nebius before create().
    job = ns.Job(
        command=["nvidia-smi"],
        image="nvidia/cuda:13.1.1-runtime-ubuntu24.04",
        gpu="h100",
        timeout="1h",
    ).create()

    # Wait for it to complete.
    job.wait()
    job.display()


if __name__ == "__main__":
    main()
uv run python examples/quickstarts/job_quickstart.py
examples/quickstarts/job_quickstart.yaml
schema_version: 1
kind: job
image: nvidia/cuda:13.1.1-runtime-ubuntu24.04
command: ["nvidia-smi"]
gpu: h100
timeout: 1h

job_from_yaml.py loads it with ns.Job(ns.JobSpec.from_yaml(path)), creates the job, waits, and exits non-zero unless it ends COMPLETED. A YAML file holds a spec, so the job is built from one:

uv run python examples/quickstarts/job_from_yaml.py \
  --config examples/quickstarts/job_quickstart.yaml
examples/quickstarts/job_quickstart.sh
#!/usr/bin/env bash
# The job from job_quickstart.py as a Nebius CLI command: the output of
# ns.Job(spec).to_cli() for that spec, with a fixed --name. A test keeps the
# two in step.
set -euo pipefail

nebius ai job create \
  --name nvidia-smi-quickstart \
  --image nvidia/cuda:13.1.1-runtime-ubuntu24.04 \
  --timeout 1h \
  --container-command nvidia-smi \
  --gpu h100 \
  --preemptible \
  --follows-spot-price \
  --disk-size 250Gi \
  --shm-size 16Gi

job.to_cli() prints this command for any job. See YAML and the CLI.

job.dry_run() returns the create request and creates nothing: use it to check a job first. job.dry_run(server=True) also asks Nebius to validate it, and still creates nothing.

What happens

  1. ns.Job(...) describes the job: what to run, on what machine, and for how long. Nothing contacts Nebius yet.
  2. create() sends the request and returns once Nebius has accepted the job and its id is known. It prints the id. It does not wait for the container.
  3. wait() polls about every 10 seconds and prints each new state until a final one.
  4. display() prints the record: the machine Nebius picked, disk, timings, and the final state.

The output of nvidia-smi is in the container logs:

nebius ai job logs <id>

Job states

stateDiagram-v2
    %% states: job
    direction LR
    state "PROVISIONING<br>IMAGE_PULLING<br>STARTING" as Starting
    [*] --> Starting: create()
    Starting --> RUNNING
    RUNNING --> COMPLETED: command exits 0
    RUNNING --> FAILED: command fails
    Starting --> ERROR: no capacity, start failure
    RUNNING --> ERROR: timeout, preemption
    RUNNING --> CANCELLING: cancel()
    CANCELLING --> CANCELLED

wait() returns on COMPLETED, FAILED, CANCELLED, ERROR, or DELETING. A failed job is data, not an exception: check job.status, and read the reason in the final progress line or in display(). FAILED means your command failed, after any restart_attempts. ERROR means the platform ended the job: no capacity, a startup failure, the timeout, or a spot preemption.

Pick another machine

gpu="h100" asks Nebius for one H100; in eu-north1 it picks gpu-h100-sxm and 1gpu-16vcpu-200gb. Use gpu="h100:8" for eight, omit gpu for the smallest CPU machine, or pass cpu="amd:16". On a GPU, the job runs on spot by default; pass pricing="on-demand" for a machine that isn't preempted. See Choose a machine and pricing.

Next

Serve a model on your first endpoint, or fine-tune one with the training examples.