# Bid Selection

After all eligible creatives are collected for an impression, the system selects the winning bid.

## Selection algorithm

1. **Filter eligible creatives**: Only creatives that pass the delivery ratio check (`ratio > random`) or have a CPC segment match are kept
2. **Random shuffle**: All eligible creatives are randomly shuffled (for fairness when prices are equal)
3. **Sort by price**: Creatives are sorted by effective CPM in descending order, with currency conversion applied
4. **Select winner**: The highest-priced creative wins the impression

## Price priority

The effective CPM for a creative is determined by the first available value:

1. **Segment CPM** (from CPC segment match) -- highest priority
2. **Split CPM** (from the split's `cpm` field, if > 0)
3. **Line item rate** (from `delivery.rate`) -- base price

## Currency conversion

All prices are converted to the bid request's target currency (from `bidRequest.cur`, default `USD`) before comparison. The conversion uses rates from the Prebid currency CDN, updated every hour.

If conversion fails for a creative (unknown currency), that creative is deprioritized in the sort.

## Bid response

The winning creative is returned as an OpenRTB 2.5 bid response:

```json
{
  "id": "response-uuid",
  "cur": "USD",
  "seatbid": [
    {
      "seat": "Advertiser Name",
      "bid": [
        {
          "id": "bid-uuid",
          "impid": "impression-id",
          "price": 3.50,
          "crid": "creative-id",
          "adm": "<ad markup>",
          "adomain": ["advertiser.com"],
          "w": 300,
          "h": 250,
          "dealid": "deal-external-id",
          "ext": {
            "lineItemId": 12345,
            "splitId": 1,
            "splitName": "Split A",
            "segmentId": 10
          }
        }
      ]
    }
  ]
}
```

### Bid ext fields

| Field        | Presence          | Description                        |
| ------------ | ----------------- | ---------------------------------- |
| `lineItemId` | Always            | The line item that won             |
| `splitId`    | When from a split | The split identifier               |
| `splitName`  | When from a split | The split name                     |
| `segmentId`  | When CPC          | The matched CPC segment identifier |

## No bid

If no creative passes all checks for any impression, the DSP returns HTTP 204 (No Content).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.nexx360.io/campaign-delivery/bid-selection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
