How jobs, endpoints and tasks work¶
The library runs three kinds of workloads on Nebius Serverless AI. This page shows what each one is for, the states it goes through, and which call moves it from one state to the next.
Which one to use¶
| Job | Endpoint | Task | |
|---|---|---|---|
| Runs | one command, then stops | a server, until stopped or deleted | one Python function or script, as a job |
| Bills | while it runs | while it runs, idle or not; not while stopped | while its job runs |
| Use for | training, batch | serving, interactive use | functions with results, pipelines, notebooks, agents |
Billing follows the Serverless pricing page: a running job or endpoint is billed for its compute and storage, and a stopped endpoint is not. A mounted bucket or filesystem is billed separately, also while the endpoint is stopped.
Job¶
A job runs one command in a container, then stops. create() sends it once. wait() polls until it reaches a final state.
stateDiagram-v2
%% states: job
state "PROVISIONING<br>IMAGE_PULLING<br>STARTING" as Starting
state "COMPLETED<br>FAILED" as Ended
[*] --> Starting: create()
Starting --> RUNNING
RUNNING --> Ended: exits
RUNNING --> CANCELLING: cancel()
CANCELLING --> CANCELLED
Starting --> ERROR: no capacity
RUNNING --> ERROR: timeout, preempted
- The command's exit code decides the final state:
COMPLETEDfor 0,FAILEDfor any other.wait()returns onCOMPLETED,FAILED,CANCELLED,ERRORorDELETING. A failed job is data, not an exception: checkjob.status. ERRORmeans the platform ended the job: no capacity, a startup failure, thetimeout, or a spot preemption.get()andns.jobs.get(id)read the state. They change nothing.- A preempted spot job ends in
ERRORwith the reasonPreempted. Nothing creates it again, andjob.idnever changes. To run it again, create a new job:ns.Job(job.spec).create(). - Start with First job. Every call is in the Jobs reference.
Endpoint¶
An endpoint runs a server on a URL until you stop or delete it.
stateDiagram-v2
%% states: endpoint
state "PROVISIONING<br>IMAGE_PULLING<br>STARTING" as Starting
[*] --> Starting: create()
Starting --> RUNNING
Starting --> ERROR: no capacity
RUNNING --> STOPPING: stop()
STOPPING --> STOPPED
RUNNING --> STOPPED: preempted
STOPPED --> Starting: start()
RUNNING --> DELETING: delete()
STOPPED --> DELETING: delete()
ERROR --> DELETING: delete()
DELETING --> [*]
RUNNINGmeans the container started, not that the server answers.wait(probe="/v1/models")waits until it does.- A spot endpoint that is preempted goes to
STOPPED. - A
STOPPEDendpoint keeps its id and URL.start()runs it again. - Start with First endpoint. Every call is in the Endpoints reference.
Task run¶
A task runs a Python function or a bash script as a job. The run's arguments and result are files in the task bucket.
%%{init: {"sequence": {"width": 90, "actorMargin": 30}}}%%
sequenceDiagram
participant You
participant Bucket
participant Job
You->>Bucket: submit(): code, payload
You->>Job: create the job
Job->>Bucket: result.json, files/
You->>Bucket: result() reads it
Note over Bucket,Job: preempted: ERROR, TaskFailed
submit()writes the arguments (payload.json), then creates one job. The job writesresult.json, oroutputs.binfor a script, andresult()reads it.- A task runs on-demand unless it sets
pricing, on a GPU too. - A preempted spot task ends in
TaskFailed. Submit it again for a new run. - Start with First task. Every call is in the Tasks reference.