Image step routes¶
The step routes let a sampler that runs in another program, such as the ComfyUI node pack, call an image model one step at a time. The server holds the weights, encodes prompts, and runs each DiT forward and the VAE. The client keeps the noise, the schedule, the guidance and the sampler. The user side is in ComfyUI.
The contract¶
The routes live under /internal/image-steps/v1. Every request but
GET capabilities carries the contract version the client speaks, as
X-Gmlx-Steps-Contract: MAJOR.MINOR. The server speaks 1.0. A request
without the header, or with another major version, gets 400, and the
message names the side to upgrade. A client reads capabilities first and
uses what it lists:
The answer gives the contract and the oldest client it serves, the gmlx version, the wire container and dtypes, the families, the step conventions, the patch kinds, the features, and the limits: the largest tensor and adapter upload, the most rows in one step, and the most runs held at once.
A sampling run¶
A client that samples one image makes these calls:
POST models/loadloads the model, andGET models/{model}/manifestgives its DiT tensor names and shapes, which a LoRA's keys map onto.POST encodeturns the prompt, and any reference images, into a conditioning. The answer names it by hash, and the server keeps it.- Each LoRA matrix goes up once:
HEAD adapters/{hash}asks whether the server holds it, andPUT adapters/{hash}uploads it.PUT patch-tables/{id}?model=IDthen names the set of patches and their strengths. The patches stack on the model's own LoRAs, as the adapters of an images request do. A table that names a pair of one of the model's own LoRAs sets that LoRA's strength and alpha in place of the model's. POST runs/beginholds the model for the run.POST stepruns once a step, with the latents, the timestep, the conditioning hashes and the patch table id.POST vae/decodeturns the final latents into pixels.POST runs/{run}/endlets the model go.
A conditioning that the client made itself goes up the same way:
HEAD tensors/{hash} answers 200 when the server holds the tensor and 404
when it does not, and PUT tensors/{hash} uploads it. The server checks
that the body hashes to the name in the path.
Routes¶
| Route | Purpose |
|---|---|
GET capabilities |
The contract version, families, wire dtypes and limits |
GET models, GET models/{model}/status, GET models/{model}/manifest |
The image models and the default one; one model's family, latent format, memory and sampling; its DiT tensor names and shapes |
POST models/load, POST models/unload |
Load or unload a model |
POST encode |
A prompt, with reference images for an edit, as a conditioning; the server keeps its tensors by hash |
HEAD tensors/{hash}, PUT tensors/{hash} |
Ask whether the server holds a tensor, or upload it |
HEAD adapters/{hash}, PUT adapters/{hash} |
Ask whether the server holds a LoRA matrix, or upload it |
POST adapters/register |
Read a LoRA file under a model folder of the server |
PUT patch-tables/{id}?model=ID |
Define a set of LoRA patches; its id is the sha256 of its JSON with sorted keys and no spaces |
POST step |
The model output for latents at a timestep, one row per conditioning |
POST vae/decode, POST vae/encode |
VAE decode and encode in the VAE's own latent space |
POST runs/begin, POST runs/{run}/end, POST interrupt |
Hold a model for a sampling run, end the run, stop its step in flight |
A model's status gives, under sampling.schedule, the rule and the
constants of its schedule when that schedule follows the image size,
as on FLUX.2 klein and Qwen-Image 2.1, and null on any other.
Bodies and hashes¶
Tensors travel as a safetensors container with content type
application/vnd.gmlx.tensors+safetensors, in F32, F16, BF16, U8 or
BOOL, and the request fields of a container travel as JSON under
__metadata__["gmlx"]. Other bodies are JSON.
A tensor's hash is the sha256 of three parts in order: its safetensors
dtype name, such as F32; its shape as a JSON list with a space after each
comma, such as [1, 16, 128]; and its bytes. A client uploads a
conditioning or a LoRA matrix once by that hash.
Conditionings and references¶
A conditioning with reference images takes ComfyUI's form: its tensor
holds the text rows, and image_slots names, for each reference image,
the text row that its latents go in before. A step row that names more
reference latents than slots puts the others after the text.
An encode keeps each reference image at its own size, so a client that
sizes its references gives the encoder and its own VAE the same pixels.
Qwen-Image 2.1 takes references of 256x256 to 1024x1024 pixels in area,
with sides a multiple of 32, and an image outside that area gets 400. An
encode with refs: false leaves out the VAE latents of its reference
images, for a client that encodes them with a VAE of its own.
MiniMax-H3-Image takes up to 16 reference images. Its encode takes each
image at the size of its vision copy, as ComfyUI's
MiniMaxH3ImageConditioning gives its encoder, and answers spans, the
[start, stop) rows of each picture's vision block with its markers,
beside image_slots, the block's rows without them. A step row on it
names those rows in image_slots, and names in ref_noise one tensor
for each of its reference latents: the noise its DiT mixes into that
reference's rows, (h / 2 x w / 2, 96) float32 for latents (24, h, w),
which ComfyUI's forward draws from a CPU generator restarted at the
run's seed for each reference. A row with reference latents and no
ref_noise, noise of another shape, or an image slot whose end marker
is past the cond gets 400. Its status names under vae.encode_seed the
seed ComfyUI's VAE samples an encode with, 42, and a vae/encode with
noise in the shape of the latents samples with that noise instead of
taking the mean. A server whose features list ref_noise takes both.
An encode that upsamples the prompt returns the caption as
revised_prompt and its conditioning as cond, and the prompt as typed
as cond_typed. A client that adds reference images after the encode,
as ComfyUI does, samples an edit and a negative on cond_typed. The
encode cannot tell a negative from a positive prompt, so it answers
cond_typed beside every caption. An upsampler that samples, as
MiniMax-H3-Image's does, writes the caption at a fixed seed, so a graph
reruns its caption.
On a server whose features list keyframe_upsampling, the encode of a
video model takes the clip's frames and keyframes, the role of each
image in order, "first" then "last". The upsampler is then told the
clip's length and which keyframes it has, as for POST /v1/videos, and
the images go to the encoder as keyframes. Without frames, a prompt with images is
encoded as typed. keyframes without frames, or with a role count other
than the images', gets 400.
Steps and runs¶
A step names its conditionings and its patch table by hash. When the
server does not hold one, the step gets 409 with a missing list, and
the client uploads those and sends the step again. The server keeps the
body of each patch table it was sent, up to 16 MiB of bodies for each
loaded model with the least recently used going first, and a step on a
table whose LoRA pairs it let go defines the table again from that
body, while it holds the LoRA matrices the body names. A run keeps the
prefix state of each of its conditionings between steps, and the
X-Gmlx-Prefix-Cache header of a step answers hit or miss.
X-Gmlx-Forward-Ms is the time of the model forward, so a client's wall
time less it is the transport time.
A step with ref_cache: true, on a server whose features list
ref_cache, runs as ComfyUI's Flux KV Cache node does on FLUX.2 klein
9B KV. On the first step of the run, each row with reference latents runs
its references at time zero and keeps their keys and values in every
block, and the step returns its output. The keys and values of a
reference depend on the latents of the row, so each row keeps its own,
under its conditioning and its place in the step's rows. Each later
step of the run takes the image and the text of each row alone, and reads
the keys and values of that row. The header answers hit on those steps,
and the end of the run drops the keys and values. A step with ref_cache
and no run gets 400, as does one on a DiT that keeps no such cache.
A step with skip, a list of block indices from zero, on a server whose
features list skip_blocks, runs each of its rows without those blocks,
as ComfyUI's SkipLayerGuidanceDiTSimple runs the negative pass of
MOSS-Image. A client sends the negative rows in a step of their own with
that skip. A model's status gives the blocks its variant leaves out of
the negative pass under sampling.neg_skip, [22] on MOSS-Image and an
empty list on any other model. A skip on a DiT that skips no blocks, a
skip that names a block the DiT lacks, and a skip with ref_cache get
400.
An AV step with int8, off, attention, linears or all, on a
server whose features list int8, runs at that setting over its entry's
defaults.int8, and one without it runs at the entry's. The linear
layers are converted as the DiT loads, so a step names a value whose
linear layers match the entry's. The attention is a setting of the loaded
DiT, so a step that changes it loads nothing. The step is priced at its
setting. A model's status names the entry's setting under int8. A value
off the list gets 400, and so do a value whose linear layers differ from
the entry's, int8 attention on a variant with sparse attention, an
mlx-kquant without the int8 kernels and a GPU without NAX units, each
with param int8.
A run that sits idle for 120 seconds ends within a few seconds after, and
lets the model go. The server holds at most 32 runs, and a begin past that
gets 429. An interrupt names its run and takes effect at the next step:
the step running when it lands finishes on the GPU, gets 409 with code
interrupted, and every later step of the run gets the same. An end
does the same to a step in flight. An interrupt that names no run stops
nothing.
Limits¶
A step, a VAE decode and a VAE encode take the size limits of the OpenAI
routes: an image over 2048x2048 pixels or with a side over 4096 gets 413,
as does a VAE pass of more than 16 images. A model with size limits of its
own takes those instead: MiniMax-H3-Image gets 413 past 20,000,000 pixels
or a side over 7712, and a denoise step under 655,360 pixels or outside
1:3 to 3:1 gets 400, while a VAE pass may take any size under its upper
limits. One whose memory plan does not
fit beside the models loaded gets 400, and so does the encode of a prompt
on a video model, priced by its rows. The message of a step names the
largest term of its plan and, where the plan keeps the keys and values of
the reference latents, how many of them fit. A patch table or a step
whose LoRA bytes do not fit beside its model and the pinned models gets
413 when it arrives, and so does an adapter upload whose bytes do not fit
beside the pinned models. The 413 names the GB the LoRAs need and the
room. The server books the other LoRA bytes on the image thread, at
the turn of the job that reads or builds them. The turn drops idle LoRA
bytes and idle uploads, unloads idle models as a cold load does, and
books what the job needs. A turn whose bytes, such as a step's factors,
need more than the budget leaves beside the model, the encoder its job
holds and the pinned models gets 413 in the same words. A turn left
short gets 503 with Retry-After, naming the GB its LoRAs need and one
of: the model the server is loading; the GB free beside the models in
use whose memory goes once they are idle; the GB free with none of them
in use, to unload a model or retry; or the GB free in the working set
macOS measures, to retry when the models in use finish or, with none in
use, to close other apps or unload a model. While a chat model in use
holds the memory, the turn waits for it up to those seconds first. An
upload that does not fit takes a turn of its own. One the image thread
does not start within those seconds gets the 503 of what is short then,
the budget or the working set, or with neither short, a 503 naming the
models the image thread is busy with. A turn that a model load or
unload holds up past those seconds with neither short gets a 503 that
says so. A model load does not count the uploads the routes hold, and
the next turn drops idle ones when memory runs short. A step whose
table's LoRA pairs and matrices the server let go for memory gets 409
with their GB, and the client sends them again.
The VAE routes decode and encode the images of a batch one at a time. capabilities gives the largest tensor upload, which is the
image.tensor_cache_mb cache,
and the largest adapter upload, which is the smaller of
image.adapter_cache_mb and
1 GiB. Each image model books the tensor
cache while the step routes are on.
Access¶
The routes answer loopback peers only.
image.steps_remote serves other
peers that the API key admits, and
image.steps_api set to false
removes the routes. The steps of all clients queue on the image thread with
the jobs of the OpenAI routes, and share the GPU with chat in the same way.
Timing the step routes¶
gmlx image bench --via-steps runs each step through these routes on a
loopback port of its own process. The prompt is encoded in the process and
uploaded by hash, each step is one request, and the latents move between
steps in the bench with its sampler. Its steps take the reference
convention, which embeds the time as sample does. The ComfyUI pack's
steps take comfy, which embeds the time as ComfyUI's forward does, and
for FLUX.2 klein that is the fp32 time.
Under both, a step's timestep is its sigma, except on MOSS-Image, where
it is the sigma times 1000, as in the OpenMOSS plugin's ComfyUI model.
The record's transport is steps. It holds the median per step of the
request's wall time less the forward time the server reports, and
equal_to_direct, whether the final latents of the last run equal those of
sample at the same seed. Each run also lists its transport time per step.