# frontend

Python API: `depthai_nodes.runtime.frontend`

Serve a built custom frontend alongside a DepthAI application.

## Functions

| Name | Description |
| --- | --- |
| [`serve_frontend`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/runtime/frontend.md#frontend-Functions-serve_frontend) | Serve a built frontend over HTTP for the duration of the context. |

### function `serve_frontend`

```python
def serve_frontend(
    directory: str | Path,
    *,
    host: str = '127.0.0.1',
    port: int = 8082,
    enabled: bool = True,
) -> Iterator[str | None]
```

Serve a built frontend over HTTP for the duration of the context.

Wrap device initialization and the pipeline's run loop with this context and use `dai.RemoteConnection(serveFrontend=False)` for
live data. The server disables caching, falls back to `index.html` for missing extensionless paths, and closes on exit, including
exceptions.

> **Notes**
> Serves static files only; provides no TLS, authentication, or WebSocket proxy.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `directory` | `str | Path` | Directory containing the built `index.html`. Construct it from the application's `__file__` to avoid depending on the working directory. | required |
| `host` | `str` | Address to bind. Defaults to loopback for local browser access. | `'127.0.0.1'` |
| `port` | `int` | HTTP port, defaulting to 8082. Independent of the WebSocket port. | `8082` |
| `enabled` | `bool` | Set false to skip hosting when another server serves the frontend. | `True` |

Returns

| Type | Description |
| --- | --- |
| `Iterator[str | None]` |  |

Yields

| Type | Description |
| --- | --- |
|  | The HTTP URL, or None when frontend hosting is disabled. |

Raises

| Type | Description |
| --- | --- |
| `FileNotFoundError` | The directory has no built `index.html`. |
| `OSError` | The server cannot bind to the requested address and port. |

## Module Attributes

| Name | Description |
| --- | --- |
| [`logger`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/runtime/frontend.md#frontend-Module-Attributes-logger) |  |

### variable `logger`

```python
logger = logging.getLogger(__name__)
```
