Skip to main content

Workflow API reference

Use this page after following the tutorials:

Image​

Image.from_registry(name, repository_secret="")
ArgumentDefaultMeaning
nameRequiredContainer image name, tag, or digest.
repository_secret""CGC/Kubernetes secret used to pull a private image.

Returns an Image definition. It does not create a CGC resource.

ShellCommand​

ShellCommand(executable, arguments=(), prelude="")
ArgumentDefaultMeaning
executableRequiredList or tuple containing the executable and optional subcommands, for example ("python", "-m", "my_service").
arguments()List or tuple of non-empty command arguments. An item can contain an option and its value, for example "--port 8000".
prelude""Optional shell setup executed before the main process, for example a small pip install command.

render() validates and quotes the executable and arguments, then returns the shell command. prelude is raw shell syntax and must only contain trusted setup commands. A ShellCommand can be returned by a custom inference function; job functions still return a shell command string.

Each arguments item is split once: "--label hello world" becomes a flag and the value hello world. Put tokens that must not be split, such as python -c source, in executable.

ServicePort​

ServicePort(name, port, ingress=False)
ArgumentDefaultMeaning
nameRequiredNon-empty CGC port name.
portRequiredUnique container port between 1 and 65535.
ingressFalseWhether CGC should create a public ingress for this additional port.

Use ServicePort entries in app.inference(additional_ports=[...]). Their names and numbers cannot duplicate the primary port or another additional port.

Names are stripped and lowercased before duplicate checks. Names accept up to 32 letters, digits or hyphens; ports must be integers and ingress must be a boolean.

Volume​

Volume.from_name(
name,
mount_path="",
size=None,
storage_class=None,
create_if_missing=False,
)
ArgumentDefaultMeaning
nameRequiredCGC volume name.
mount_path""Path where the volume is mounted in the container.
sizeNoneCapacity in GB when creating the volume.
storage_classNoneStorage class; None uses the platform default.
create_if_missingFalseMetadata indicating that the workflow expects a missing volume to be created.
MethodMeaning
create(size=None, storage_class=None)Creates the volume. Method arguments override values stored in the definition.
ensure()Uses a ready volume or creates it when missing.
ready()Returns whether the volume is ready.
delete(force=False)Deletes the volume and its files.

Call ensure(), then wait for ready() before submitting the job. create_if_missing=True alone does not create a volume. Multiple volumes require default mount paths; a custom mount_path supports one volume only.

App​

App(name, image=None, volumes=None, environment=None)
ArgumentDefaultMeaning
nameRequiredWorkflow name and default resource-name prefix.
imageNoneDefault Image used by workflow steps.
volumesNoneDefault list of Volume definitions.
environmentNoneDefault environment variables as a string dictionary.

App stores shared configuration. It does not create a resource.

app.function() and app.job()​

Both decorators create the same type of short-lived workflow task.

@app.function(
image=None,
name=None,
cpu=1,
memory=2,
gpu=0,
gpu_type="",
volumes=None,
environment=None,
arguments=None,
ttl_seconds_after_finished=3600,
shm_size=0,
)
ArgumentDefaultMeaning
imageApp imageImage used by this job.
nameApp and function namesBase job name. A unique suffix is added.
cpu1CPU cores reserved for the job.
memory2Memory reserved in GB.
gpu0Number of GPUs.
gpu_type""CGC GPU identifier.
volumesApp volumesVolumes attached to the job.
environment{}Variables merged with the App environment.
arguments[]Additional container arguments.
ttl_seconds_after_finished3600Seconds before a finished job is removed; None disables automatic cleanup.
shm_size0Shared memory size in GB.

The decorated function must return a non-empty shell command.

submit()​

run = task.submit(*function_args, wait=False, **function_kwargs)

Passes the supplied values to the decorated function, creates a job, and returns JobRun.

for_each()​

runs = task.for_each(*iterables, wait=False, kwargs=None)

Creates one job for each group produced by zip(*iterables). kwargs contains named values passed to every function call.

submit(wait=True) waits and returns JobRun, but does not raise for Failed or Timeout. Check the status before continuing.

JobRun​

MethodDefault argumentsReturn value
status()NoneCurrent phase, NotFound, or Unknown.
wait()poll_seconds=5, timeout_seconds=600Succeeded, Failed, or Timeout.
logs()timestamps=FalseJob log response.
delete()NoneDelete response.

app.resource()​

app.resource(
image=None,
name=None,
startup_command=None,
cpu=1,
memory=2,
gpu=0,
gpu_type="",
volumes=None,
environment=None,
repository_secret="",
# Keyword-only options:
arguments=None,
entity="custom",
shm_size=0,
node_port_enabled=False,
)
ArgumentDefaultMeaning
imageApp imageContainer image.
name<app-name>-resourceExact CGC resource name.
startup_commandNoneCommand started in a custom container. When a custom resource has neither a command nor arguments, the SDK uses sleep infinity.
arguments[]Arguments parsed by the existing backend. Cannot be combined with startup_command.
entity"custom"Custom image or the name of a resource template available in the current CGC environment.
cpu1CPU cores.
memory2Memory in GB.
gpu0Number of GPUs.
gpu_type""CGC GPU identifier.
volumesApp volumesAttached volumes.
environment{}Variables merged with App variables.
repository_secretImage secretPrivate registry secret override.
shm_size0Shared memory in GB.
node_port_enabledFalseEnables node-port exposure.

Returns ResourceDefinition, which provides create(), ready(), and delete().

A custom resource requires an image. A template resource must not receive an image or startup_command; pass its native arguments through arguments.

Pass arguments, entity, shm_size and node_port_enabled to app.resource() by keyword only.

app.inference()​

@app.inference(
image=None,
name=None,
port=8000,
port_name="web",
cpu=1,
memory=2,
gpu=0,
gpu_type="",
volumes=None,
environment=None,
repository_secret="",
shm_size=0,
node_port_enabled=False,
ingress=True,
# Keyword-only options:
entity="custom",
additional_ports=None,
)
ArgumentDefaultMeaning
imageApp imageContainer image.
nameApp and function namesCGC resource name.
entity"custom"Custom image or a resource template available in the current CGC environment.
port8000Port used by the HTTP server.
port_name"web"CGC port and ingress identifier.
additional_ports[]Additional ServicePort definitions configured after the resource reaches Running.
cpu1CPU cores.
memory2Memory in GB.
gpu0Number of GPUs.
gpu_type""CGC GPU identifier.
volumesApp volumesAttached volumes.
environment{}Variables merged with App variables.
repository_secretImage secretPrivate registry secret override.
shm_size0Shared memory in GB.
node_port_enabledFalseEnables node-port exposure.
ingressTrueCreates an ingress URL.

For entity="custom", a function may return a non-empty shell command, a ShellCommand, or a list/tuple of arguments for the image entrypoint. A backend template accepts a list/tuple of arguments; do not supply a custom image or shell command in that declaration. entity and additional_ports in app.inference() are keyword-only options.

Argument List Limitations​

The backend splits "--port 8000" into a flag and value. Items with more than one space are rejected, and repeated keys may be overwritten. Use ShellCommand for complex custom commands.

deploy()​

endpoint = service.deploy(
*function_args,
wait=False,
reuse_existing=False,
resource_timeout_seconds=600,
poll_seconds=5,
**function_kwargs,
)

Creates the resource and its ports, then returns DeployedEndpoint. Additional ports force a wait for Running, even when wait=False, because the backend can only add them to an available resource. A port configuration error preserves the created resource for inspection and explicit cleanup.

A readiness error or timeout stops port setup and preserves the resource. Already added ports are not rolled back. Exceptions include the resource name and available code, reason and details.

reuse_existing=False raises on a name conflict. True reuses the resource and can add missing ports, but does not update its image, command, environment or existing ports.

DeployedEndpoint​

Property or methodDefault argumentsReturn value
urlNonePrimary-port ingress URL; raises SDKException when primary ingress is disabled.
exists()NoneWhether the compute listing contains a pod labelled with this resource's app-name.
refresh_url()NoneRefreshed primary-port ingress URL.
status()NoneRunning or Pending.
wait()poll_seconds=5, timeout_seconds=600Running or Timeout.
wait_http()path="", status_code=200, poll_seconds=5, timeout_seconds=300, request_timeout=10Successful HTTP response or SDKException.
post_json()path, payload, headers=None, timeout=30Decoded JSON or response text.
logs()timestamps=FalseResource log response.
delete()NoneDelete response.

With primary ingress=False, do not use url, wait_http() or post_json(). Internal ports are reachable from workloads in the same namespace. The handle exposes only the primary port URL.

port_name="http" normally uses the root ingress path /; other names normally add /<port_name>. Use the returned URL and match application routes to that prefix. wait() returning Running is not an HTTP health check.

RTDetrWorkflow​

Import it from the ready-made workflow recipes:

from cgc.sdk.recipes.rtdetr import RTDetrConfig, RTDetrWorkflow
RTDetrWorkflow(
name,
image,
volume=None,
config=None,
inference_name=None,
)
ArgumentDefaultMeaning
nameRequiredWorkflow and default inference resource name.
imageRequiredImage used by RT-DETR.
volumeNonePersistent volume required for dataset and training workflows, but not pretrained inference.
configRTDetrConfig()Model and resource configuration.
inference_nameWorkflow nameSeparate inference resource name.

RTDetrConfig arguments:

ArgumentDefaultMeaning
model_namertdetr-l.ptUltralytics model weights.
gpu_typenvidia-rtx-a5000GPU identifier used by training jobs.
epochs3Number of training epochs.
image_size640Training image size in pixels.
install_packagesTrueInstalls required Python packages when remote commands start.
download_cpu2CPU cores for dataset download jobs.
download_memory8Memory in GB for dataset download jobs.
train_cpu4CPU cores for training jobs.
train_memory24Memory in GB for training jobs.
inference_cpu4Inference CPU cores.
inference_memory16Inference memory in GB.
inference_gpu1Inference GPU count.
inference_gpu_typenvidia-rtx-a5000Inference GPU identifier.
inference_port8000Generated server port.
inference_port_nameapiCGC port name.
ttl_seconds_after_finished86400Seconds before completed training jobs are removed.
workflow.deploy_pretrained_inference(
wait=False,
gpu=None,
gpu_type=None,
reuse_existing=False,
)
ArgumentDefaultMeaning
waitFalseWaits for the inference resource to run.
gpuNoneOverrides config.inference_gpu for this deployment.
gpu_typeNoneOverrides config.inference_gpu_type for this deployment.
reuse_existingFalseReuses an inference resource with the same name.

Returns DeployedEndpoint.

RoboflowDataset​

Import dataset helpers from the recipes package:

from cgc.sdk.recipes.datasets import RoboflowDataset, VolumeDataset
RoboflowDataset(
workspace_id,
project_id,
version,
format="yolov11",
api_key="",
target_class="",
)
ArgumentDefaultMeaning
workspace_idRequiredRoboflow workspace identifier.
project_idRequiredRoboflow project identifier.
versionRequiredNumeric dataset version.
formatyolov11Roboflow export format.
api_key""Roboflow API key used by the download job.
target_class""Optional target-class metadata.

Pass it to YoloWorkflow.download() or RTDetrWorkflow.download(), then call submit() on the returned job definition. See Datasets.

VolumeDataset​

VolumeDataset(
name,
path,
data_yaml="data.yaml",
target_class="",
)
ArgumentDefaultMeaning
nameRequiredLogical dataset name.
pathRequiredDataset directory on the workflow volume.
data_yamldata.yamlUltralytics dataset configuration file.
target_class""Optional target-class metadata.

The workflow checks this dataset on the volume instead of downloading it.

YoloWorkflow​

Import it from the ready-made workflow recipes:

from cgc.sdk.recipes.yolo import YoloConfig, YoloWorkflow
YoloWorkflow(
name,
image,
volume=None,
config=None,
inference_name=None,
)

It uses the same constructor and shared Ultralytics configuration fields as RTDetrWorkflow. YoloConfig defaults model_name to yolo11n.pt.

Important methods:

MethodMeaning
download(dataset)Returns a dataset download/check job definition.
train(dataset, model_id=None)Returns a YOLO training job definition.
deploy_inference(dataset, model_id=None, wait=False, reuse_existing=False)Deploys weights produced by training.
deploy_pretrained_inference(wait=False, gpu=None, gpu_type=None, reuse_existing=False)Deploys pretrained weights without a volume.

See YOLO inference.