> 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.

# runServerless

> Handle one serverless invocation on AWS Lambda, Google Cloud Functions, Azure Functions, or CGI.

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

[serverless-adapter]: /docs/server-sdks/reference/typescript/agents/configuration/serverless-adapter

Handle a single serverless invocation by routing the platform's event through the agent's
HTTP app, and return the platform's response. This is the explicit serverless path:
[`run()`][run] calls it when it detects a serverless platform, and you call it yourself from a
handler file to opt in deliberately.

The routing is done by a [`ServerlessAdapter`][serverless-adapter] for the given platform. On
CGI with no event, the request is read from the CGI environment and standard input, and the
response is written to standard output.

## Parameters

**`event`** `ServerlessEvent` — required

The platform's invocation event, such as a Lambda event or a Cloud Functions request.

---

**`context`** `unknown`

The platform's invocation context. Accepted for the handler signature; the base agent
doesn't use it.

---

**`platform`** `'lambda' | 'gcf' | 'azure' | 'cgi' | 'auto'` — default: auto

Serverless platform. `auto` detects it from the environment.

---

## Returns

`Promise<ServerlessResponse>` -- The normalized response for the platform.

## Example

```typescript {6-7}
import { AgentBase, type ServerlessEvent } from '@signalwire/sdk';

const agent = new AgentBase({ name: 'dispatch', route: '/dispatch' });
agent.setPromptText('You are Ada, the dispatcher for Bayview Taxi.');

export const handler = (event: ServerlessEvent, context: unknown) =>
  agent.runServerless(event, context, 'lambda');
```