> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# The API Server

> Explains running ADK API server to expose agents over HTTP, session endpoints, and streaming or batch run endpoints plus deployment and security considerations

Okay, here's a reality check.

You've been building this agent locally for a couple of weeks. It answers customer questions, calls the right tools, and passes your evaluation tests. Now you need to turn it into a service other programs can call.

During development you used `adk run` or `adk web` to test in a terminal or browser UI, but an application won't integrate with your terminal:

```bash theme={null}
$ adk run support_agent
[user]: Where's my order A1001?
[support_agent]: It shipped.
```

The runner is the ADK component that executes your agent. A message goes in one side, the agent processes it, and events come out the other side. Events can be a text reply, a tool call, or a status update. The production system still uses the same `root_agent` code; what changes is the infrastructure around it.

The first piece of that infrastructure is an API server.

![A flow diagram titled "The Runner and the API Server" showing a Runner sending data to a root\_agent inside an "Infrastructure" box. The root\_agent then branches out to three outputs: Text reply, Tool call, and Status update.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/The-API-Server/runner-root-agent-infrastructure-outputs.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=4d139e0faa95268d5870fe592b4b1ed3)

ADK includes a built-in API server that exposes your agent over HTTP. When you run the ADK API server command, ADK starts a FastAPI application backed by Uvicorn. FastAPI is a modern Python web framework for building APIs; Uvicorn is a fast ASGI server.

```bash theme={null}
$ adk api_server
INFO:    Started server process [41872]
INFO:    Waiting for application startup.
INFO:    Application startup complete.
INFO:    Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```

This HTTP server exposes the same execution machinery you've been using locally — the runner executes your agent code behind the API endpoints, so your agent logic remains unchanged.

There are two primary endpoints you will use:

* POST `/run` — Executes a request and returns the events as a completed response. Use this when you want the full result after processing.
* POST `/run_sse` — Streams events back using Server-Sent Events (SSE). The server keeps the connection open and pushes each event to your client as soon as it's available. This is ideal for chat-like interfaces and for incrementally streaming tokens when enabled. (See MDN: [https://developer.mozilla.org/en-US/docs/Web/API/Server-sent\_events/Using\_server-sent\_events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events))

![A diagram titled "Two Endpoints" showing an API server making POST /run and POST /run\_sse requests to a client app, which receives actions like tool call, status update, and text reply.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/The-API-Server/two-endpoints-api-post-run-sse.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=a135eee055b907977b4a1a1f7d0737d1)

Who sends messages to these endpoints? The API server needs to know which application, which user, and which conversation (session) a message belongs to. That context is the session: a thread tying a run of messages to one user and one conversation.

The API server exposes session management endpoints under a URL that includes the app name, user ID, and session ID. For example:

`/apps/<appName>/users/<userId>/sessions/<sessionId>`

Create a session first, then send turns to the `/run` or `/run_sse` endpoints using the same app, user, and session IDs. Example using curl to create a session and the JSON response the server returns:

```bash theme={null}
$ curl -X POST \
  http://localhost:8000/apps/support_agent/users/u_42/sessions/s_1001
```

```json theme={null}
{
  "id": "s_1001",
  "appName": "support_agent",
  "userId": "u_42",
  "state": {},
  "events": [],
  "lastUpdateTime": 1791813600.512
}
```

![A flow diagram titled "Which User, Which Conversation" showing two user avatars with chat bubbles routed via API endpoints (POST /run and POST /run\_sse) to an API server. On the right is a session panel listing app\_name: support\_agent, user\_id: u\_42, and id: s\_1001.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/The-API-Server/which-user-which-conversation-api-flow.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=0a195440e86a4641388a0fa0892caadc)

The agent itself hasn't changed — you've replaced the terminal UI talking to the runner with HTTP requests that hit an API server, which in turn talks to the runner:

```text theme={null}
The Agent Hasn't Changed

Session
app_name    support_agent
user_id     u_42
id          s_1001

POST /run
POST /run_sse

API server -> Runner -> root_agent
```

Quick reference: endpoints and usage

| Endpoint | Method | Description | Typical use case |
| -: | :-: | - | - |
| `/apps/<appName>/users/<userId>/sessions/<sessionId>` | POST | Create a new session object for an app + user + conversation | Initialize session state before sending messages |
| `/apps/<appName>/users/<userId>/sessions/<sessionId>/run` | POST | Run a single request and return all events when complete | Batch processing or requests where blocking is acceptable |
| `/apps/<appName>/users/<userId>/sessions/<sessionId>/run_sse` | POST | Stream events back via Server-Sent Events | Real-time chat UI or progressive token streaming |

When you expose the API server beyond your laptop/network, secure it. Add authentication, TLS (HTTPS), rate limiting, and sensitive-key management. Also plan for scaling and observability before moving to production.

At this point your service is still running on your laptop and reachable only within your network. To make it publicly available, choose where to run it — there are multiple Google Cloud deployment paths (GCE, GKE, Cloud Run, App Engine, etc.). The right choice depends on the control, scalability, and operational model you need: managed serverless for simplicity, Kubernetes for fine-grained control, or VMs for low-level customization.

Links and references

* FastAPI — [https://fastapi.tiangolo.com/](https://fastapi.tiangolo.com/)
* Uvicorn — [https://www.uvicorn.org/](https://www.uvicorn.org/)
* Server-Sent Events (SSE) — [https://developer.mozilla.org/en-US/docs/Web/API/Server-sent\_events/Using\_server-sent\_events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
* curl — [https://curl.se/](https://curl.se/)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/73e63dcd-2829-46d7-bbaa-5ac2336079d7/lesson/a601d291-aacf-431b-a155-72b2972e23a8)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.