> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# serve

> Start a Hono web server to serve this agent's SWML and SWAIG endpoints.

[run]: /docs/server-sdks/reference/typescript/agents/agent-base/run

Start a Hono web server (via `@hono/node-server`) to serve this agent. The server
exposes endpoints for SWML document delivery, SWAIG function execution,
post-prompt summary handling, and health checks.

The server automatically includes:

* SWML document endpoint at the agent's route
* SWAIG function dispatch at `{route}/swaig`
* Post-prompt handler at `{route}/post_prompt`
* `/health` and `/ready` health check endpoints
* Security headers middleware
* Basic Auth middleware

Set `SWML_SSL_ENABLED`, `SWML_SSL_CERT_PATH`, and `SWML_SSL_KEY_PATH` to serve HTTPS;
webhook URLs then use `https`, on `SWML_SSL_DOMAIN` when it's set. When the certificate
or key file is missing, it warns and serves HTTP. See
[environment variables](/docs/server-sdks/reference/typescript/agents/configuration/environment-variables).

> **Info**
>
> [`run()`][run] starts the server like `serve()`, except that when it's given a serverless `event`,
> or detects a serverless platform from the environment, it handles that one invocation instead.
> Call `serve()` when you always want a server.

## **Parameters**

**`opts`** `object`

Optional host and port overrides.

---

**`opts.host`** `string`

Host to bind the server to. Falls back to the constructor's `host` option.

---

**`opts.port`** `number`

Port to listen on. Falls back to the constructor's `port` option.

---

> **Note**
>
> When the `SWAIG_CLI_MODE` environment variable is set to `"true"`, `serve()`
> returns immediately without starting the server. This lets the `swaig-test`
> CLI load the agent's configuration without binding a port.

## **Returns**

`Promise<void>` -- Resolves once the server is running.

## **Example**

```typescript {5}
import { AgentBase } from '@signalwire/sdk';

const agent = new AgentBase({ name: 'my-agent', host: '0.0.0.0', port: 3000 });
agent.setPromptText('You are a helpful assistant.');
await agent.serve(); // Blocks here, serving at http://0.0.0.0:3000/
```