# SDK Bidding Process

The following diagram provides an overview of the SDK bidding process:

{% @mermaid/diagram content="sequenceDiagram
participant MediationSDK as Mediation SDK
participant MediationBackend as Mediation Backend
participant DTExchangeSDK as DT Exchange SDK
participant DTExchangeBackend as DT Exchange Backend
autonumber
MediationSDK ->> DTExchangeSDK: Initialize and request a Token
DTExchangeSDK -->> MediationSDK: Provide Token
MediationSDK ->> MediationBackend: Pass Token
MediationBackend ->> DTExchangeBackend: OpenRTB Bid Request (with Token)
DTExchangeBackend ->>  DTExchangeBackend: Perform OpenRTB auction among DSPs
DTExchangeBackend -->> MediationBackend: OpenRTB Bid Response (winning bid)
MediationBackend ->> MediationBackend: Perform second auction\&lt<br> (DTX Winning Bid vs. Other Networks)
alt DT Exchange Wins
MediationBackend ->> DTExchangeBackend: Send Win Notification (with macros)
MediationBackend ->> DTExchangeSDK: Send winning bid for rendering
DTExchangeSDK ->> MediationSDK: Impression happened
MediationSDK ->> MediationBackend: Impression detected
MediationBackend ->> DTExchangeBackend: Send Billing Notification
else DT Exchange Loses
MediationBackend ->> DTExchangeBackend: Send Loss Notification (with macros)
end" %}

## Bidding Process

1. **Initiating the Bid Request:** The Mediation SDK begins the process by requesting a unique identification token from the DT Exchange SDK, which is a key part of setting up the ad request.
2. **Receiving a Security Token:** The DT Exchange SDK provides the requested token back to the Mediation SDK to confirm its identity. For more information about generating a token, see Fetching the Ad for SDK Bidding ([Android docs](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-android-sdk/android-ad-formats), [iOS docs](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-ios-sdk/ios-ad-formats)).
3. **Forwarding the Token:** The Mediation SDK sends this token to its server-side component, the Mediation Backend, which will handle the rest of the bid process.
4. **Creating a Bid Request:** The Mediation Backend creates and sends an OpenRTB bid request to the DT Exchange Backend. This request includes the security token and other relevant information for the ad placement. For more information, see [Bid Request Specifications](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/sdk-bidding-guidelines#h_01k6nysk3tgvkg1m3gwf6apxgy).
5. **Running an Internal Auction:** The DT Exchange Backend receives the bid request and runs an internal OpenRTB auction among its network of Demand-Side Platforms (DSPs) to find the best ad.
6. **Sending the Winning Bid:** After the auction concludes, the DT Exchange Backend sends the highest bid response, including the creative and price, back to the Mediation Backend. For more information, see [Bid Response Specifications](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/sdk-bidding-guidelines#h_01k6nysk3tbxf1gpv908v3f3nj).
7. **Conducting a Final Auction:** The Mediation Backend then performs a secondary auction, comparing the winning bid from DT Exchange against bids from all other ad networks to find the overall best bid.

#### Alternative 1: DT Exchange Wins <a href="#h_01k6jx9hsg7x69zy4z1kr72npk" id="h_01k6jx9hsg7x69zy4z1kr72npk"></a>

8. **Notifying of Win:** If the DT Exchange bid wins the final auction, the Mediation Backend notifies the DT Exchange Backend with a win notification that includes details about the successful bid. For more information, see the `seatbid.bid.nurl` attribute in the [Bid Response Specifications](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/sdk-bidding-guidelines#h_01k6nysk3tbxf1gpv908v3f3nj).
9. **Preparing to Render:** The Mediation Backend sends the winning ad creative from DT Exchange back to the DT Exchange SDK on the user's device, preparing it for display.
10. **Confirming Impression:** Once the ad is displayed to the user, the DT Exchange SDK notifies the Mediation SDK that an impression has occurred.
11. **Logging the Impression:** The Mediation SDK relays this impression notification to the Mediation Backend to log the event.
12. **Sending a Billing Confirmation:** The Mediation Backend sends a final billing notification to the DT Exchange Backend to complete the transaction for the winning ad impression. For more information, see the `seatbid.bid.burl` attribute in the [Bid Response Specifications](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/sdk-bidding-guidelines#h_01k6nysk3tbxf1gpv908v3f3nj).

#### Alternative 2: DT Exchange Loses <a href="#h_01k6jx9hsgq09w85tab27fnbat" id="h_01k6jx9hsgq09w85tab27fnbat"></a>

13. **Notifying of Loss:** If another network's bid is higher, the Mediation Backend sends a loss notification to the DT Exchange Backend, informing it that its bid was not selected. For more information, see the `seatbid.bid.lurl` attribute in the [Bid Response Specifications](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/sdk-bidding-guidelines#h_01k6nysk3tbxf1gpv908v3f3nj).
