Each gets a stable HTTPS URL in the cloud when deployed, and previews with
lazycloud serve.
Endpoints
Save this asapi_demo.py:
route defaults to / and methods to GET and POST.
Deployed, it answers at the printed URL with an
access token:
{"words": 4}.
In Python, the decorated function is also the client:
request() uses your lazycloud login sign-in and goes to a running preview or
the deployment. See Where a call goes.
ASGI applications
app.asgi(...) wraps an existing FastAPI or Starlette app. FastAPI needs to be
installed locally too, with uv add fastapi, because the CLI imports the file:
request() sends a full request to a route:
method, path, json, data, headers, and params. An
exported client
gives each route a typed method instead. ASGI apps take the endpoint options,
with concurrent_requests for concurrency and keep_warm_seconds for
keep_warm.
Realtime handlers
@app.realtime turns a function into a WebSocket handler. Each incoming
message calls the handler, and LazyCloud sends the return value back. An
iterable return value sends each item as its own message.
Authentication
All three requireAuthorization: Bearer <token> with an
access token for the workspace, and the Python
clients send your sign-in. authorized=False makes the URL public, leaving
access control to your code.
Capacity
An endpoint starts as one process handling one request at a time. Three settings raise that:max_pending_tasks, 100 by default,
requests get 429. Scaling covers choosing the numbers.
checkpoint_enabled=True lets new containers restore a warmed worker instead
of rerunning on_start.
Custom domains
On Team and Business plans,domain="api.example.com" serves any of the three
from a hostname you own. See Custom domains.
Stop and clean up
stop takes it offline and keeps the definition, and delete removes it, as
does --prune once it’s gone from the code.
