api_demo.py
{"words": 4}. LazyCloud maps
the JSON request body to the function’s arguments and sends the returned
model as JSON; the model also becomes the response schema that
typed client packages
use. route defaults to / and methods to GET and POST. The token is an
access token. Before deploying, the same
file previews with lazycloud serve.
Choose the kind
Call it from 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.
Serve an existing FastAPI app
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:
api before wrapping it. An app built inline in the
app.asgi(...)(...) call fails at import.
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.
Stream or hold a WebSocket
@app.realtime turns a function into a WebSocket handler, and an ASGI app
can stream a response; see Streaming.
Require a token
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.
Handle more requests at once
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.
Serve from your own domain
On Team and Business plans,domain="api.example.com" serves any of the three
from a hostname you own. See Custom domains.
Take it offline
stop takes it offline and keeps the definition, and delete removes it, as
does --prune once it’s gone from the code.
