Calling serverless apps with Python

Invoke an endpoint on one of your own Serverless apps and read the task back.

Introduction

Serverless apps are your own code running on Runware, and the same client reaches them. Installation and authentication are on the overview; what the platform does with an invocation is in Invoking an app.

Invoking an endpoint

client.invoke() calls an endpoint on one of your own Serverless apps. A different API from inference, reached through the same client and raising the same error type.

task = await client.invoke("image-tools", "generate", {"prompt": "a red bicycle"})

task["status"]   # "completed" or "failed"
task["output"]   # whatever your handler returned

Choosing how to wait

delivery_method decides how the wait happens, not whether you get a result. async is the default and polls without holding a connection, which is what a long job wants. sync holds one request open and is the fast path for work that finishes in seconds.

Task ids and retries

Every invocation carries a task id, generated unless you pass one. Sending the same id again returns the task it already names rather than starting a second, so a call whose response was lost is safe to repeat.

Leaving it running

wait=False returns as soon as the task is accepted and leaves it running. Read the id off it and pick the task up later with get_task.

from runware import InvokeOptions

accepted = await client.invoke(
    "image-tools", "train", {"epochs": 10}, options=InvokeOptions(wait=False),
)

task = await client.get_task("image-tools", accepted["id"])

When a task fails

A task that runs and fails comes back with status set to "failed" and its error set. Only a failure to start raises.