---
title: "Serverless Agents"
description: "Deploy agents to AWS Lambda, Vercel, and other platforms"
---

Deploying agents to serverless platforms is easy with `ai-query`. 

For deep dives into architecture and adapters, see the [Deployment Guide](/core/deployment).

## AWS Lambda

Use the `handle_lambda` adapter.

```python
# lambda_function.py
from ai_query.adapters.aws import handle_lambda
from my_agent import SupportAgent

def handler(event, context):
    agent_id = event.get("pathParameters", {}).get("agent_id", "default")
    return handle_lambda(SupportAgent(agent_id), event, context)
```

## Vercel / Next.js

Use the `handle_vercel` adapter with the standard Python runtime.

```python
# api/agent/[agent_id].py
from http.server import BaseHTTPRequestHandler
from ai_query.adapters.vercel import handle_vercel
from my_agent import SupportAgent

class handler(BaseHTTPRequestHandler):
    def do_POST(self):
        agent_id = self.path.split("/")[-1]
        handle_vercel(SupportAgent(agent_id), self)
```

## Consuming

You can consume these agents from any Python client using `connect()`:

```python
from ai_query import connect

agent = connect("https://my-lambda-url.com/agent/user-1")
response = await agent.chat("Hello!")
```
