> Full text of the [Build a tennis product with Odds API](https://odds-api.net/docs/tennis).

# Build a tennis product with Odds API

Discover tournament fixtures, load match and set prices, then follow odds changes. Use the returned event_id to connect opponents, bookmaker markets and match records.

## Integration path

### Find a match

Filter by tennis and save the fixture’s event_id.

### Load bookmaker prices

Collect every snapshot page before building your odds board.

### Follow price changes

Subscribe with the snapshot’s resume token.

```bash
curl -sS -G 'https://api.odds-api.net/v1/events' \
  -H "X-API-Key: $ODDS_API_KEY" \
  --data-urlencode 'sport=tennis' \
  --data-urlencode 'not_started_only=true' \
  --data-urlencode 'limit=50'
```

- **Base URL:** https://api.odds-api.net/v1
- **Authentication:** X-API-Key
- **Sport filter:** sport=tennis

Keep your API key on your server. [Compare request and streaming allowances](https://odds-api.net/pricing) or [open the full API reference](https://odds-api.net/docs).

## Tennis fixtures and tournament filters

Use sport=tennis for the schedule. The league field identifies a tournament, such as ATP Finals, ATP Challenger Helsinki or WTA Finals.

```bash
curl -sS -G 'https://api.odds-api.net/v1/events' \
  -H "X-API-Key: $ODDS_API_KEY" \
  --data-urlencode 'sport=tennis' \
  --data-urlencode 'league=ATP Challenger Helsinki' \
  --data-urlencode 'not_started_only=true' \
  --data-urlencode 'limit=50'
```

Read the response’s `items`. Keep each match’s `event_id`, opponents, start time and league. Pass `next_cursor` back as `cursor` with the same filters until it is empty. Use an exact league name from discovery or [coverage](https://odds-api.net/coverage).

### Match records and results

`GET /v1/events/{event_id}` retrieves the source match record. `GET /v1/events/{event_id}/results` returns the result record; handle its pending or available status separately from live score updates.

## Tennis market names and fields

Match the bet type, metric, period, line and player selection. A full-match game total is a different bet from a first-set game total.

| Market | API bet_type | Selection and scope |
| --- | --- | --- |
| Match winner | `moneyline` | Compare the two players in a match. Example selections: Jannik Sinner or Carlos Alcaraz. |
| Set winner | `moneyline` | Use period to select the 1st set or 2nd set. Keep set winners separate from the match winner. |
| Total games | `total` | metric: games. Compare Over and Under at the same line, such as 22.5 games, for the same period. |
| Game handicaps | `handicap` | metric: games. Compare player selections at a matching handicap, such as −2.5 games. |
| Set totals and handicaps | `total` `handicap` | metric: sets. Build total-set and set-handicap views, keeping the line and selection attached to each price. |
| Player game totals | `team total` | metric: games. The normalized team total market identifies an individual tennis participant through its selection fields. |

`moneyline` identifies a match or set winner; `period` separates the sets. For totals and handicaps, `metric` distinguishes games from sets. Keep the exact returned line and participant selection when grouping prices.

Use the returned `market_key` for filtering and `selection_key` for history. Preserve the bookmaker and odds-row `id` when applying updates.

## Load a tennis odds snapshot

Replace the event ID with one returned by fixture discovery. Choose the bookmakers you want to compare.

```bash
curl -sS -G "https://api.odds-api.net/v1/events/$EVENT_ID/odds/snapshot" \
  -H "X-API-Key: $ODDS_API_KEY" \
  --data-urlencode 'bookmakers=bet365,pinnacle,sportsbet' \
  --data-urlencode 'price_fields=odds'
```

Follow `next_cursor` through every page. Each odds row identifies its bookmaker, market, selection and decimal price. Preserve period, metric, line and timestamps alongside the price.

### Capture the stream checkpoint

Save the `resume` token from the first snapshot page. After reading all pages, open the stream with that token so changes during pagination can be replayed.

## Stream tennis odds with SSE or WebSockets

Start with a snapshot, then apply changes to your local odds rows. Use the same bookmaker and price filters for both requests.

```bash
curl -N -G "https://api.odds-api.net/v1/events/$EVENT_ID/odds/stream" \
  -H "X-API-Key: $ODDS_API_KEY" \
  --data-urlencode 'bookmakers=bet365,pinnacle,sportsbet' \
  --data-urlencode 'price_fields=odds' \
  --data-urlencode "since=$RESUME" \
  --data-urlencode 'catchup=true'
```

The WebSocket equivalent is `wss://api.odds-api.net/v1/events/{event_id}/odds/ws`. It accepts the same query filters and sends JSON envelopes with `event` and `data`.

- Apply deltas by odds-row `id` and retain the latest resume token.
- Reconnect with `since` and `catchup=true`, using backoff.
- If the server requires a reset, load a new snapshot before continuing.

These endpoints carry pre-match bookmaker prices. Builder, Live and Pro include Betfair in-play exchange access through the exchange endpoints. Discover a match’s exchange markets at `GET /v1/events/{event_id}/exchange/markets`.

## Tennis sets, games, points and serving state

Ask support to enable tennis score access on your API client. This is a separate entitlement from in-play exchange access.

Discover the tennis match with `GET /v1/events/{event_id}/exchange/markets`. Use the canonical event ID from the returned `score_subscription.command`—not a market ID.

```text
wss://api.odds-api.net/v1/exchange/tennis/scores/ws
Header: X-API-Key: YOUR_API_KEY

{"op":"subscribe","event_ids":["CANONICAL_ID_FROM_DISCOVERY"]}
```

| Field | Meaning |
| --- | --- |
| `home`, `away` | Participant names, integer sets and games, string points, nullable is_serving and game_sequence arrays. |
| `current_set`, `current_game` | Current set and game state; unknown values remain null. |
| `tie_break`, `match_status` | Tie-break and match state. |
| `stream_id`, `sequence`, `update_kind` | Identify the stream and ordered changes, including corrections and resets. |
| `freshness` | Receipt-time freshness. Score and exchange price receipt times are independent. |

The first observation is an `image`. Every subsequent `delta` contains the complete replacement score state. Apply corrections too. Compare sequence numbers only within the same stream_id.

A connection supports up to ten active events and consumes one stream unit plus the plan’s stream-hour and byte allowances. Scores are match-state updates, not final settlement results. There is no historical score replay or resume token; reconnect and subscribe again for a fresh image.

## Historical tennis odds and line movement

History Lite adds 30 days of retained pre-match odds for $50 USD/month on a paid plan. Use a selection_key from the snapshot to follow one selection’s recorded prices.

```bash
curl -sS -G "https://api.odds-api.net/v1/events/$EVENT_ID/odds/history" \
  -H "X-API-Key: $ODDS_API_KEY" \
  --data-urlencode "selection_key=$SELECTION_KEY" \
  --data-urlencode "from_ts=$FROM_ISO8601" \
  --data-urlencode "to_ts=$TO_ISO8601"
```

Keep the bookmaker, player, market, period, metric and line attached to each series. A first-set total of 9.5 games and a match total of 22.5 games belong on separate series. Follow the endpoint’s pagination and retain returned timestamps.

[Explore historical odds](https://odds-api.net/historical-odds-api) or [compare plan access](https://odds-api.net/pricing).

## Complete Python fixture and snapshot example

Install `requests` and set `ODDS_API_KEY` on your server. This example discovers a current tennis match with a selected bookmaker and reads all its snapshot pages.

```python
import os
import requests

BASE = "https://api.odds-api.net/v1"
HEADERS = {"X-API-Key": os.environ["ODDS_API_KEY"]}
BOOKMAKERS = ["bet365", "pinnacle", "sportsbet"]

def pages(path, params):
    params = dict(params)
    while True:
        response = requests.get(BASE + path, headers=HEADERS, params=params, timeout=20)
        response.raise_for_status()
        payload = response.json()
        yield payload
        cursor = payload.get("next_cursor")
        if not cursor:
            return
        params["cursor"] = cursor

fixtures = pages("/events", {
    "sport": "tennis",
    "not_started_only": "true", "limit": 50,
})
event = next((event for page in fixtures for event in page["items"]
              if any(book in event.get("bookmakers", []) for book in BOOKMAKERS)), None)
if event is None:
    raise RuntimeError("No upcoming tennis match with the selected bookmakers. Try again later.")

for snapshot in pages(f"/events/{event['event_id']}/odds/snapshot", {
    "bookmakers": ",".join(BOOKMAKERS), "price_fields": "odds",
}):
    print(snapshot)  # Keep timestamps and stream resume information with the rows.
```

## Handle empty results, access errors and reconnects

- **No fixture:** follow all discovery pages and check the tournament and bookmaker filters.
- **Authentication or access failure:** verify X-API-Key and the required entitlement. Tennis scores need separate enablement.
- **Rate limit:** respect returned rate-limit headers and back off before retrying.
- **Odds stream disconnect:** reconnect with the last resume token; reload the snapshot when a reset is required.
- **Score correction:** replace the entire score state, even when the score moves backwards.
- **Score unavailable:** show an unavailable state; this does not mean the match finished. Reconnect with backoff for a fresh image.

Read the [full endpoint reference](https://odds-api.net/docs) for response schemas and status codes.
