Web endpoints
Expose tasks over HTTP: REST, ASGI, WSGI, or a raw web server.
REST endpoint
The simplest HTTP interface. The function receives the parsed JSON body and must return a JSON-serialisable value. Use requires_auth=False for public webhooks.
python
1@app.task()2@gw.web_endpoint(method="POST", path="/predict", requires_auth=False)3async def predict(body: dict) -> dict:4 text = body["text"]5 score = run_classifier(text)6 return {"text": text, "score": score}ASGI app
Return a FastAPI or Starlette app to serve many routes from one task. The app is called directly — no extra process is spawned.
python
1@app.task(gpu=gw.Gpu("A100"))2@gw.asgi_app()3def api():4 from fastapi import FastAPI5 app = FastAPI()6 7 @app.get("/health")8 def health(): return {"ok": True}9 10 @app.post("/embed")11 async def embed(body: dict): ...12 13 return appWSGI app
Wrap a Flask or Django app. gworker adapts WSGI to ASGI automatically.
python
1@app.task()2@gw.wsgi_app()3def flask_app():4 from flask import Flask, jsonify5 app = Flask(__name__)6 7 @app.route("/ping")8 def ping(): return jsonify(ok=True)9 10 return appRaw web server
Start any server process that binds to a port. gworker proxies public traffic to that port once startup_timeout_s has elapsed.
python
1@app.task()2@gw.web_server(port=8080, startup_timeout_s=10.0)3def vllm_server():4 import subprocess5 subprocess.Popen([6 "python", "-m", "vllm.entrypoints.openai.api_server",7 "--model", "mistralai/Mistral-7B-v0.1",8 "--port", "8080",9 ])Custom domains
Attach your own domain to a web endpoint. Add a CNAME record pointing to your app's default URL, then register it in the SDK.
python
1@app.task()2@gw.web_endpoint(3 method="POST",4 custom_domains=("api.mycompany.com",),5)6async def handler(body: dict) -> dict: ...