Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:OpenHands OpenHands SaaS Server ASGI App

From Leeroopedia
Knowledge Sources
Domains Server_Architecture, SaaS_Infrastructure
Last Updated 2026-02-11 21:00 GMT

Overview

Concrete tool for composing the SaaS ASGI application by wrapping the FastAPI base app inside a SocketIO ASGIApp, provided by the OpenHands enterprise server layer.

Description

The SaaS Server ASGI App constructs the top-level application object by combining the core OpenHands FastAPI app with the SocketIO server instance. The socketio.ASGIApp wrapper receives all incoming ASGI connections: it handles Socket.IO protocol frames directly and delegates all other HTTP requests to the base_app passed via the other_asgi_app parameter. The module also registers a simple is_saas() health-check endpoint that returns a confirmation that the server is running in SaaS mode. This file serves as the entry point for the entire SaaS server process.

Usage

Use this wrapper when deploying the OpenHands server in SaaS mode where both the REST API and real-time Socket.IO communication must be served from a single ASGI process. The resulting app object is the target for ASGI servers such as Uvicorn.

Code Reference

Source Location

  • Repository: OpenHands
  • File: enterprise/saas_server.py:L1-65

Signature

# Composite ASGI application creation
app = socketio.ASGIApp(sio, other_asgi_app=base_app)

# Health-check endpoint
@base_app.get("/api/is-saas")
async def is_saas() -> bool:
    return True

Import

from openhands.server.app import app as base_app
from openhands.server.listen_socket import sio
import socketio

I/O Contract

Inputs

Name Type Required Description
sio socketio.AsyncServer Yes The Socket.IO async server instance that handles real-time events
base_app FastAPI Yes The core FastAPI application providing REST API endpoints

Outputs

Name Type Description
app socketio.ASGIApp The composite ASGI application ready for deployment with an ASGI server
is_saas response bool Returns True confirming the server is in SaaS mode

Usage Examples

Basic Usage

import socketio
from openhands.server.app import app as base_app
from openhands.server.listen_socket import sio

# Create the composite ASGI application
app = socketio.ASGIApp(sio, other_asgi_app=base_app)

# Run with Uvicorn
# uvicorn enterprise.saas_server:app --host 0.0.0.0 --port 3000

Related Pages

Implements Principle

Environment

Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment