To implement server-side ad insertion (SSAI) with HLS or DASH livestream, use
the Pod Serving API to request adaptive bitrate ad pods. For supported
resolutions and bitrates, see [Video and audio formats and
transcoding](https://support.google.com/admanager/answer/1181018).

This page covers using the Pod Serving API for livestream.

## Prerequisites

Before you continue, you must have the following:

- Configure a livestream event with the **Pod serving redirect** Dynamic Ad
  Insertion (DAI) type. Choose either of the following options:

  - [Set up a livestream for
    DAI](https://support.google.com/admanager/answer/7294289).
  - Select a SOAP API client library and call the [`LiveStreamEventService.createLiveStreamEvents`](https://developers.google.com/ad-manager/api/reference/latest/LiveStreamEventService#createlivestreamevents) method with a `LiveStreamEvent` object and the `dynamicAdInsertionType` type set to the [`POD_SERVING_REDIRECT`](https://developers.google.com/ad-manager/api/reference/latest/LiveStreamEventService.DynamicAdInsertionType) enum. For all client libraries, see [Client libraries and example
    code](https://developers.google.com/ad-manager/api/clients).
- A client app running in a web browser, mobile device or TV, to load the
  stream and handle events, such as play, pause, click, or tap.

- A manifest manipulator to handle stream requests from the client app.
  Important: For your manifest service, we recommend the [**advanced serving
  flow**](https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/live/get-started#advanced_serving_flow).

- A Google Ad Manager account with Pod serving DAI enabled.

## Basic serving flow

To deliver your stream, choose a streaming protocol and do the following:

### HLS

1. To register a session, make a stream request from your video player to
   Google Ad Manager.

2. Start polling ad metadata for upcoming ad events.

3. Request the livestream manifest from your manifest manipulator.

4. Optional: [Send an early ad break
   notification](https://developers.google.com/ad-manager/api/beta/ad-breaks) to
   Google Ad Manager.
   Important: We recommend this step for enhanced fill rate.

5. When your manifest manipulator detects an ad break marker, construct the
   ad segment URLs and stitch them into the manifest.

   - During an ad break, your client video player requests an ad segment and follows the segment redirect URL to download the ad segment file.
6. Extract the ad event IDs from ID3 tags to find and send media
   verification pings to Google.

![Pod serving redirect with HLS - Basic serving
flow](https://developers.google.com/static/ad-manager/dynamic-ad-insertion/api/pod-serving/images/hls-basic-live.png "Pod serving redirect with HLS - Basic serving flow")

### DASH

1. Follow all steps in the HLS tab.

2. Request a DASH period template once and cache the template. This
   approach builds the periods for all ad breaks of the session.

![Pod serving redirect with DASH - Basic serving
flow](https://developers.google.com/static/ad-manager/dynamic-ad-insertion/api/pod-serving/images/dash-basic-live.png "Pod serving redirect with DASH - Basic serving flow")

## Advanced serving flow

To deliver your stream, choose a streaming protocol:

### HLS

1. To register a session, make a stream request from your client video
   player to Google Ad Manager.

2. Start polling ad metadata for upcoming ad events.

3. Request the livestream manifest from your manifest manipulator.

4. Optional: [Send an early ad break
   notification](https://developers.google.com/ad-manager/api/beta/ad-breaks) to
   Google Ad Manager for enhanced fill rate.

5. Make an ad pod timing metadata (ATM) request to Google Ad Manager.

6. Retrieve the precise ad pod and slate time to construct the ad segment
   URLs.

7. Stitch the ad segment URLs into the manifest.

8. When your manifest manipulator detects an ad break marker, construct the
   ad segment URLs and stitch the URLs into the manifest.

   - During an ad break, your client video player requests an ad segment and follows the segment redirect URL to download the ad segment file.
9. Extract the ad event IDs from ID3 tags to find and send media
   verification pings to Google.

![Pod serving redirect with HLS - Advanced serving
flow](https://developers.google.com/static/ad-manager/dynamic-ad-insertion/api/pod-serving/images/hls-advanced-live.png)

### DASH

1. Follow all steps in the HLS tab.

2. Use the Ad pod Timing Metadata (ATM) responses for additional required
   fields to build the DASH periods.

![Pod serving redirect with DASH - Advanced serving
flow](https://developers.google.com/static/ad-manager/dynamic-ad-insertion/api/pod-serving/images/dash-advanced-live.png "Pod serving redirect with DASH - Advanced serving flow")

## Step by step instructions

For details on API endpoints, example request and response data, see [Client
video player app for
livestreams](https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/live/client) and
[Manifest manipulator for
livestreams](https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/live/manipulator).