nebius-serverless¶
Unofficial Python client for Nebius Serverless AI: jobs, endpoints, images and tasks. Describe a container workload in Python or YAML, create it on a Nebius GPU or CPU, and wait for it from a script, a notebook, or CI.
Get started Browse examples → · Reference →
Install¶
Python 3.10 or later. It depends on nebius>=0.6.43,<0.7, PyYAML>=6, and rich>=13. The import name is nebius_serverless.
create() and jobs.get() need a Nebius CLI profile (nebius profile create), or in CI a service account or NEBIUS_IAM_TOKEN (Run in CI). ns.whoami() shows the account, and the project and region create() will use, without creating anything.
Featured examples¶
Fine-tune a model with Axolotl¶
QLoRA on Qwen/Qwen2.5-0.5B on one spot H100, with the config and the results in Object Storage.
Uses: Jobs · Format: Python · YAML
Read walkthrough → · View files →
Serve a model with vLLM¶
Qwen/Qwen3-0.6B behind an OpenAI-compatible API and a bearer token, on one H100 endpoint.
Uses: Endpoints · Format: Python · YAML
Read walkthrough → · View files →
Train MNIST with a pipeline of tasks¶
Prepare, train with four learning rates at once, evaluate, and pick the best run, as ns.Task steps. Runs as plain Python or as a Prefect flow.
Uses: Tasks · Images · Format: Python
Read walkthrough → · View files →
Every other example is in the catalog.
Run a job¶
import nebius_serverless as ns
job = ns.Job(
command=["nvidia-smi"],
image="nvidia/cuda:13.1.1-runtime-ubuntu24.04",
gpu="h100",
timeout="1h",
)
job.dry_run() # the request as data; nothing is created
job.create() # once; sets job.id
job.wait()
job.display()
Building a Job makes no Nebius calls. gpu="h100" asks Nebius for one H100, and Nebius picks the platform and preset in the project's region. On a GPU, jobs run on spot by default: cheaper, but Nebius can preempt them. Pass pricing="on-demand" to avoid that. job.create() creates the job once and returns when Nebius has accepted it. job.wait() polls until the job ends and prints each new state. job.get() fetches once, job.cancel() requests cancellation, and ns.jobs.get(id) reloads a job from a saved id. job.dry_run() returns the request and creates nothing. Logs are nebius ai job logs <id>: this library does not stream them.
To load a job from YAML, reuse it with changes, or save it, use a spec: ns.Job(ns.JobSpec.from_yaml("job.yaml")). See Specs as data.
Run a function as a task¶
def count_words(text: str) -> dict[str, int]:
"""Count each word in a text. Runs in the job, so it imports there."""
from collections import Counter
return dict(Counter(text.split()))
count = ns.Task(count_words, image="python:3.12-slim-bookworm", timeout="10m")
print(count(text="to be or not to be")) # runs a job, returns the dict
A task runs a Python function as a job and returns what it returned. Reading the result needs Object Storage credentials, and the first run creates the bucket ns-workspace-<project id>: see First task.
Serve an endpoint¶
An endpoint is a container that stays up and answers on a managed https:// URL. It bills for compute while it runs, until you stop or delete it. On a GPU it runs on spot by default: a preemption stops it, and endpoint.start() runs it again.
endpoint = ns.Endpoint(
image="vllm/vllm-openai:v0.19.1",
command=["bash", "-c", "vllm serve Qwen/Qwen3-0.6B --port 8000"],
gpu="h100",
port=8000,
)
endpoint.dry_run() # the request as data; nothing is created
endpoint.create() # once; sets endpoint.id and endpoint.token
endpoint.wait(probe="/v1/models") # RUNNING, and the server answers
print(endpoint.url, endpoint.token)
endpoint.delete()
Endpoints require a bearer token by default: callers send Authorization: Bearer {endpoint.token}. A random token is generated on create, and endpoint.reveal_token() fetches it again later. For production, keep it in MysteryBox with token_secret=. auth="none" makes a public URL that anyone who has it can call, at your cost.