Endpoints¶
Reference for the endpoints surface of nebius_serverless. The jobs surface is in Jobs.
An endpoint is a container that stays up and answers on a managed URL. A job runs a command and finishes. Creating an endpoint allocates the machine, and it bills while it runs, until it is stopped or deleted. Closing the process does neither.
Import the package as ns. Machine selection (gpu, cpu), pricing, volumes, env handling, and the error types are the same as for jobs.
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()
How an endpoint moves through its states, and the calls that move it. How jobs, endpoints and tasks work explains each one.
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 --> [*]
Overview¶
| Name | Role |
|---|---|
Endpoint |
One Nebius endpoint, built from its parameters and created once with create(). |
endpoints |
Fetch an endpoint from a saved id. |
EndpointSpec |
The same parameters as data: YAML and reuse. No cloud id. |
Constructing an Endpoint or an EndpointSpec, loading YAML, or importing the package does not authenticate, upload, or create. Only create() creates the endpoint, once. For another endpoint, build another ns.Endpoint(...). Each one bills for compute while it runs. A stopped endpoint is not billed for compute or its disk; mounted volumes still bill (pricing).
Sync calls work in a notebook cell, and the awaited twins keep an event loop responsive: see Async and notebooks. Only delete / delete_async deletes an endpoint: interrupting or cancelling a call doesn't.
create, get, wait, delete, and endpoints.get, plus their awaited twins, print progress on stderr the same way as the job calls (Progress, logs, and diagnostics). wait ends with the URL under the RUNNING line. quiet=True is keyword-only and suppresses progress for that call only. dry_run() prints nothing.
Endpoint¶
One endpoint on Nebius: built from its parameters, created once, then used.
ns.Endpoint(*, image, command=None, **parameters) # the parameters below
ns.Endpoint(spec) # from an EndpointSpec
Building an Endpoint contacts nothing. create() sends the endpoint once and sets id and token. The other calls need a created endpoint.
command is passed by name. An unnamed first value must be an EndpointSpec, and anything else raises ValidationError. ns.Endpoint(spec) takes no other argument, and checks the spec again (see Changing a spec).
ns.endpoints.get(id) returns an Endpoint for one that already exists. Its spec is not known, so spec, dry_run, to_cli and create raise on it. Use record.
Parameters¶
ns.Endpoint(...) and ns.EndpointSpec(...) take these parameters, all by keyword. A mistake raises ValidationError when the endpoint is built, before any Nebius call. Rules shared with jobs link to the Jobs reference.
What runs
| Parameter | Required | Meaning |
|---|---|---|
image |
yes | name:tag or registry/path@sha256:<64 hex>, sent unchanged: a tag is not resolved to a digest. |
command |
no | List of strings that overrides the image entrypoint; None keeps it. A shell string is rejected. Details |
name |
no | The label shown in the console. When omitted, each create() makes a new endpoint-<12 hex> name. Details |
working_dir |
no | Container working directory, at most 128 characters. Defaults to the image WORKDIR. |
env |
no | dict[str, str]. Values never appear in dry runs or errors. Use secrets for tokens. |
secrets |
no | dict[str, str] of variable name to MysteryBox id (mbsec-… or mbsecver-…). Details |
registry_secret |
no | MysteryBox version id (mbsecver-…) for a private image registry. Details |
volumes |
no | Mount strings, such as s3://<bucket name>:/data:ro. Mode ro or rw (default). Details |
inject_files |
no | local_path:container_path strings. Each file is read on create, at most 64 KiB. Details |
Ports and auth
| Parameter | Required | Meaning |
|---|---|---|
port |
one of | One HTTP container port, from 1 to 65535, served at a managed https:// URL. Shortcut for ports=[port]. |
ports |
one of | Several ports in the CLI's --container-port syntax, such as [8000, "6379/tcp"]. Pass exactly one of port and ports. Details |
auth |
no | "token" (default): callers send Authorization: Bearer <token>. "none": a public URL that anyone who has it can call, at your cost. Details |
token |
no | Bearer token for auth="token". When omitted, each create generates one and sets Endpoint.token. Details |
token_secret |
no | MysteryBox id whose payload has AUTH_TOKEN, in place of token. Details |
Machine
| Parameter | Required | Meaning |
|---|---|---|
gpu |
no | GPU selector MODEL[:COUNT], such as "h100": Nebius picks the platform and preset. See Machine selection. |
cpu |
no | CPU selector FAMILY:VCPUS, such as "amd:16". Excludes gpu. |
platform |
no | Explicit platform id. Excludes gpu and cpu. |
preset |
no | Explicit preset id. Defaults to the platform's smallest preset. An unknown platform needs it. |
disk |
no | Boot disk size, such as "500Gi". Defaults to 250Gi. |
shm |
no | /dev/shm size, such as "64Gi", or 0; an integer is bytes. Defaults to 16Gi on a GPU machine and none on CPU, as in the CLI. |
Pricing
| Parameter | Required | Meaning |
|---|---|---|
pricing |
no | "spot" or "on-demand"; anything else raises ValidationError. Defaults to spot on a GPU machine and on-demand on CPU, where spot raises UnsupportedFeature. A preempted spot endpoint goes to STOPPED, and start() runs it again. |
spot_policy |
no | Pricing policy id that caps the spot price: the machine is preempted above the cap. Requires spot pricing. |
Where
| Parameter | Required | Meaning |
|---|---|---|
project |
no | Project id. Overrides the profile's project. |
profile |
no | Nebius CLI profile name. Defaults to the active profile. |
subnet_id |
no | Subnet id. Needed only when the project has more than one subnet. |
There is no timeout or restart_attempts parameter: an endpoint has no job deadline, and the endpoint API has no restart count. The CLI flag and API field of each parameter are in the CLI and API map.
Parameter details¶
ports¶
An int is an HTTP container port, and a string is HOST[:CONTAINER][/http|tcp|udp], for example "80:8080". The protocol defaults to http and is case-insensitive. An HTTP port gets an https:// URL, a TCP port a tls://HOST:443 URL, and a UDP port no managed URL. A repeated container port and protocol raises ValidationError. Token auth needs exactly one port, and it must be HTTP: Nebius rejects an extra TCP or UDP port behind its auth proxy (checked live). Other port sets need auth="none".
auth¶
The default differs from the CLI's --auth none on purpose and matches Nebius's own endpoint templates: a billing GPU URL is public only when the code says auth="none". Token auth needs exactly one HTTP port (see ports). Any other value raises ValidationError.
token¶
Setting it with auth="none" raises ValidationError. A generated token comes with a printed notice. Endpoint.reveal_token() fetches the token again later. The value is left out of repr, dry-run descriptions and exception text.
token_secret¶
A secret id (mbsec-…) or a version id (mbsecver-…). It requires auth="token" and can't be combined with token: either mistake raises ValidationError. No token is generated, Endpoint.token is None, and the dry run shows "token": "secret" with the id.
Properties¶
Property reads do not perform I/O.
| Property | Meaning |
|---|---|
spec |
The spec this endpoint was built from. Raises on one from endpoints.get. |
id |
Nebius endpoint id, or None before create(). |
name |
Display name: the name parameter, or the one create() generated. |
status |
Raw status.state string. Before the first successful fetch, this is the state from the create response, or None when create did not include one. |
record |
Last fetched endpoint JSON, or None before the first successful get or wait. spec.auth_token is removed from fetched JSON. |
url |
The first managed https:// URL in the last fetch, or None when it has none. |
urls |
Every managed URL in the last fetch, in API order: https:// for HTTP ports, tls:// for TCP ports. |
token |
Bearer token from this create call or from reveal_token(). None when auth="none", with token_secret, and on an endpoint from endpoints.get until reveal_token(). |
Endpoint.dry_run¶
The create request as data. Creates nothing. Project and region come from project= / region= when passed, otherwise from the active SDK profile (profile= on the spec selects it). A missing or ambiguous project or region raises ValidationError.
The description includes image, command and args when a command was set, ports (normalized strings such as ["8000/http", "6379/tcp"]), project, region, gpu, cpu or platform and preset, pricing, auth, token when auth="token", subnet_id when set, volumes when set, inject_files when set, env (key names only), name, disk, and shm when sent. token is the word "provided" or "generated", never the value. Env values and inject-file contents are not included.
server=True also sends the request to Nebius with dry_run set: Nebius validates it and creates nothing. Its answer is under "server". A rejection raises what create() would raise. Bucket names in volumes are looked up first.
Endpoint.to_cli¶
The nebius ai endpoint create command for this spec, as for Job.to_cli: --container-port per port, --auth, and --token-secret by id. A token= value is never printed; a # note says to add --token yourself.
Endpoint.create¶
Creates the endpoint on Nebius, once, and returns this Endpoint. It blocks until Nebius has accepted the endpoint and the id is known. It does not wait until the URL is ready: acceptance is not readiness. A second create() on the same Endpoint raises ValidationError. Without token or token_secret, a random token is generated, kept in endpoint.token, and a notice is printed.
region and project work as for dry_run. project on this call overrides the project parameter. An optional transport= keyword replaces the Nebius SDK client. Tests use it. Scripts leave it unset.
idempotency_key= works as for jobs (Job.create). With a key you pass, token auth needs token= or token_secret=: a token generated in another process would differ, so a reconnected endpoint would not match it.
Endpoint.create_async¶
await endpoint.create_async(*, region=None, project=None, idempotency_key=None, quiet=False) -> Endpoint
Same call as create. Cancelling the await leaves the endpoint running when create was already accepted.
Endpoint.get¶
One nebius ai endpoint get. Returns the endpoint JSON. Stores that JSON on record and status, and sets url when status.public_endpoints contains an https:// URL. Does not change token.
ERROR and STOPPED are data. get does not raise because the workload failed. A missing id raises Error and includes that id.
Endpoint.wait¶
Polls get about every 5 seconds until the endpoint reaches the target in until, or will not reach it, then returns that JSON.
until="ready" (default): ready means status.state is RUNNING and the fetched record has a managed URL for each protocol that gets one: https:// when the endpoint exposes an HTTP port and tls:// when it exposes a TCP port. A UDP-only endpoint is ready at RUNNING. ERROR, STOPPED, and DELETING end the wait as data. The caller reads endpoint.status and endpoint.url. PROVISIONING, STARTING, IMAGE_PULLING, and STOPPING keep the poll going, and so does RUNNING without a URL. After start() on this handle, the STOPPED left over from before the start keeps the poll going until another state appears.
An endpoint in ERROR is not billed; it keeps its id until delete.
until="stopped": ends on STOPPED, or on ERROR or DELETING as data. Use it after stop(): a plain wait() right after a stop can return on the RUNNING that is still reported. Any other until raises ValidationError.
endpoint.url always reflects the latest fetch, and is None when that record has no URL. An ERROR or DELETING record can still list its URL.
By default the wait gives up after 3600 seconds (60 minutes) and raises WaitTimeout. The message names the endpoint id and its last state, says it may be billing, and names wait() and delete() as the next calls. Sixty minutes covers Nebius's capacity search (up to 30 minutes), creation, and an image pull with model load. timeout is seconds, a duration string such as "45m" or "1h30m", or a timedelta; anything else raises ValidationError. wait(timeout=None) waits without a limit. wait(timeout=0) performs one fetch. wait(timeout=seconds) stops the local poll at that deadline. No form deletes or stops the endpoint. Job wait has no default limit, because the job's own timeout ends it on the server. An endpoint has no such deadline.
RUNNING with a URL means the tunnel is up, not that the server inside answers: a model can still be loading. probe="/v1/models" then GETs url + probe every 5 seconds until it answers 2xx, within the same deadline. It sends Authorization: Bearer <token> when the handle knows the token (from create, reveal_token(), or token=). A refused connection, 404, 502, 503 and other codes keep polling, with one progress line per new answer; 401 or 403 raises AccessError at once. Running out of time raises WaitTimeout. The token goes only into the request header and is never logged.
Endpoint.stop¶
Requests a stop and returns {"id": ..., "resource_id": ...} when the request is accepted. The endpoint keeps its id and configuration; only delete removes it. While it is stopped, Nebius does not bill compute or the disk; mounted volumes still bill (pricing). start runs it again. The state passes through STOPPING to STOPPED; wait(until="stopped") blocks until then.
Endpoint.start¶
Requests a start of a stopped endpoint and returns {"id": ..., "resource_id": ...} when the request is accepted. It does not wait: call wait() to block until the endpoint is RUNNING with its URL. The endpoint comes back at the same URL and IP address; the boot disk is not preserved (stop and start). A preempted spot endpoint goes to STOPPED with code Preempted; start resumes it.
endpoint.stop()
endpoint.wait(until="stopped")
endpoint.start()
endpoint.wait() # RUNNING with the same URL
Endpoint.delete¶
Requests deletion and returns {"id": ..., "resource_id": ...} when the request is accepted. The payload does not claim the machine has stopped or that billing has ended. A later get reports DELETING or a missing id once Nebius has finished.
There is no cancel. Cancellation is the job verb. An endpoint is removed with delete.
Endpoint.reveal_token¶
Fetches the endpoint once and returns its bearer token, and sets endpoint.token. Nebius's Get returns spec.auth_token to anyone allowed to read the endpoint (checked live on 19 November 2026), so a handle loaded with endpoints.get can recover the token after a restart. Returns None for a public endpoint and for one that reads its token from MysteryBox (token_secret). The value is never logged, and record never holds it.
Endpoint.display¶
Prints the last fetched record on stdout, including the managed URL, image, platform, and instances. Does not fetch. Before the first successful get or wait, prints the id and name.
Awaited twins¶
await endpoint.get_async(*, quiet=False)
await endpoint.wait_async(timeout=3600, *, until="ready", probe=None, token=None, quiet=False)
await endpoint.stop_async(*, quiet=False)
await endpoint.start_async(*, quiet=False)
await endpoint.delete_async(*, quiet=False)
Same calls as the synchronous methods. Cancelling wait_async or get_async does not delete the endpoint. A cancelled wait_async stops polling once a get already in flight returns.
endpoints¶
Module-level collection, ns.endpoints. It matches the CLI noun nebius ai endpoint.
endpoints.get¶
One nebius ai endpoint get, starting from an id string. Returns an Endpoint whose record is already filled. Does not create an endpoint. token is None; call reveal_token() to fetch it.
profile and project select the SDK profile for this fetch. transport= is the same test injection as on Endpoint.create.
endpoints.get_async¶
Same fetch as endpoints.get.
EndpointSpec¶
Specs as data, for advanced use. An EndpointSpec holds the parameters of ns.Endpoint as frozen data, as JobSpec does for jobs: to load and save YAML, to reuse a recipe with clone(), or to keep an allow-list of what code may start. ns.Endpoint(spec) builds an endpoint from it.
Each parameter is readable as an attribute of the same name. port is None when ports was used, and ports holds normalized strings such as "8000/http". token is a Pydantic SecretStr: spec.token.get_secret_value() reads it, and it is None when it will be generated or read from token_secret. command is None when the image entrypoint is kept. env and secrets are dicts, and pricing is None unless it was set.
EndpointSpec is data, as JobSpec is: frozen, compared by value, with clone(**changes), to_dict(redact=True), to_yaml(redact=True), from_yaml(path), model_json_schema() and model_validate(data). to_dict and to_yaml write the token as "<hidden>" unless redact=False.
EndpointSpec.from_yaml¶
Load a schema-version-1 endpoint document. Relative strings inside the document are not expanded.
The keys are schema_version, kind, and the same keys as the parameters, except profile, project, inject_files and token. schema_version must be 1 and kind must be endpoint. A kind: job document is rejected and points at JobSpec.from_yaml; JobSpec.from_yaml does the same for kind: endpoint. command may be omitted; when present it is a list of strings. port is an integer, ports is a list in the Python form, and only one of them may be set. gpu may be omitted for CPU; gpu: cpu is rejected. env values are treated like the Python values. A token key raises ValidationError, because YAML files are often committed: store the token in MysteryBox and set token_secret, or pass token= in Python. The error never contains the value. What else a document may not hold is in YAML and the CLI.
Changing a spec¶
Use spec.clone(**changes), which checks a change like the constructor's arguments. Pydantic's model_copy(update=...) and model_construct() skip the checks, so ns.Endpoint(spec) checks the spec again: an invalid one raises ValidationError with the constructor's message, without env values or tokens, and a valid one is kept as it is (ns.Endpoint(spec).spec == spec).
Not supported¶
Things you might look for, and what to use instead:
- Listing endpoints, or getting one by name. Use
nebius ai endpoint list.ns.endpoints.gettakes an id. - Logs. Use the Nebius CLI or the web console. This package does not stream them.
- A context manager that deletes on exit. A process that dies would leave the endpoint billing, and the API has no remote lifetime to enforce. Call
delete()in afinally, as First endpoint does. - A public IP (
--public). The managedhttps://URL doesn't need one. - Secret names.
secrets,token_secretandregistry_secrettake MysteryBox ids, not the names orID@VERSIONselectors the CLI resolves. - Scaling and replicas. One preset is one machine.