| Title: | R Client for the 'odds-api.net' Sports Odds API |
|---|---|
| Description: | Access sports, leagues, bookmakers, events, odds snapshots, line movement history, results and racing data from 'odds-api.net' <https://odds-api.net>. Provides authenticated requests, bounded retries, explicit cursor pagination and data frames for sports odds analysis. |
| Authors: | Odds API [aut, cre] |
| Maintainer: | Odds API <[email protected]> |
| License: | Apache License (== 2.0) |
| Version: | 0.1.0 |
| Built: | 2026-11-06 00:33:48 UTC |
| Source: | https://github.com/odds-api/odds-api |
Fetch sports betting odds, events, bookmaker catalogs, results and racing data
from Odds API. Start with odds_client() and
odds_events(), then convert a sports odds_snapshot() with odds_table().
Maintainer: Odds API [email protected]
Authors:
Odds API [email protected]
https://odds-api.net, https://github.com/odds-api/odds-api, https://api.odds-api.net/v1/reference
Connect to the sports odds API at https://odds-api.net. Credentials are
sent in a redacted X-API-Key header, never in the query string.
odds_client( api_key = Sys.getenv("ODDS_API_KEY"), base_url = Sys.getenv("ODDS_API_BASE_URL", "https://api.odds-api.net/v1"), timeout = 30, max_tries = 3L )odds_client( api_key = Sys.getenv("ODDS_API_KEY"), base_url = Sys.getenv("ODDS_API_BASE_URL", "https://api.odds-api.net/v1"), timeout = 30, max_tries = 3L )
api_key |
API key. Defaults to |
base_url |
API base URL. Defaults to |
timeout |
Request timeout in seconds; a positive finite number. |
max_tries |
Maximum total attempts per request, from 1 to 10. Retries apply to HTTP 429, 502, 503 and 504, and connection failures. |
An odds_api_client object. Printing it hides the API key.
client <- odds_client(api_key = "") clientclient <- odds_client(api_key = "") client
Pagination is explicit because each page is a separate API request and may consume credits. A repeated cursor or exhausted page budget raises an error instead of silently returning incomplete results. An empty page with a nonterminal cursor is followed, as required for odds snapshot scans.
odds_collect(client, path, ..., max_pages = 100L)odds_collect(client, path, ..., max_pages = 100L)
client |
A client created by |
path |
Cursor endpoint: |
... |
Named query filters, optionally including a starting |
max_pages |
Positive integer limit on requests (default 100). |
A list containing items, count, pages and next_cursor = NULL.
Use odds_snapshot() for the original snapshot freshness/resume metadata;
collected pages do not represent an atomic snapshot.
## Not run: events <- odds_collect(odds_client(), "/events", league = "NBA", max_pages = 5) ## End(Not run)## Not run: events <- odds_collect(odds_client(), "/events", league = "NBA", max_pages = 5) ## End(Not run)
Thin wrappers around the public odds-api.net API.
Responses remain nested lists; use odds_table() for a sports odds data frame.
Each call requests one page. Use odds_collect() when the endpoint supports
next_cursor. Consult https://api.odds-api.net/v1/reference for filters.
odds_sports(client) odds_leagues(client, ...) odds_bookmakers(client, ...) odds_events(client, ...) odds_event(client, event_id, ...) odds_event_bookmakers(client, event_id) odds_snapshot(client, event_id, ...) odds_history(client, event_id, selection_key, ...) odds_results(client, event_id) odds_bets(client, ...) odds_racing_events(client, ...) odds_racing_event(client, event_id, ...) odds_racing_snapshot(client, event_id, ...) odds_me(client) odds_usage(client) odds_limits(client) odds_status(client)odds_sports(client) odds_leagues(client, ...) odds_bookmakers(client, ...) odds_events(client, ...) odds_event(client, event_id, ...) odds_event_bookmakers(client, event_id) odds_snapshot(client, event_id, ...) odds_history(client, event_id, selection_key, ...) odds_results(client, event_id) odds_bets(client, ...) odds_racing_events(client, ...) odds_racing_event(client, event_id, ...) odds_racing_snapshot(client, event_id, ...) odds_me(client) odds_usage(client) odds_limits(client) odds_status(client)
client |
A client created by |
... |
Named API query filters, forwarded to |
event_id |
Canonical event identifier, as returned by |
selection_key |
Stable selection identifier returned by an odds snapshot. |
Parsed JSON as nested R lists, including any pagination metadata.
## Not run: client <- odds_client() odds_sports(client) odds_bookmakers(client, country_code = c("US", "AU")) events <- odds_events(client, sport = "basketball", league = "NBA", limit = 10) if (length(events$items)) { id <- events$items[[1]]$event_id snapshot <- odds_snapshot(client, id, types = "moneyline") odds_table(snapshot) } ## End(Not run)## Not run: client <- odds_client() odds_sports(client) odds_bookmakers(client, country_code = c("US", "AU")) events <- odds_events(client, sport = "basketball", league = "NBA", limit = 10) if (length(events$items)) { id <- events$items[[1]]$event_id snapshot <- odds_snapshot(client, id, types = "moneyline") odds_table(snapshot) } ## End(Not run)
Returns JSON as nested R lists, preserving pagination and snapshot metadata. Only GET requests are made. See the public API contract at https://api.odds-api.net/v1/reference for filters and response fields.
odds_get(client, path, ...)odds_get(client, path, ...)
client |
A client created by |
path |
API-relative path, for example |
... |
Named query parameters. Vectors become comma-separated filters,
logical values become |
Parsed JSON, usually a list. HTTP 204 returns NULL. Failures raise
odds_api_error with status (or NA for transport failures) and
retry_after fields. Error messages do not echo credentials or server bodies.
## Not run: client <- odds_client() odds_get(client, "/events", sport = "basketball", league = "NBA", limit = 10) ## End(Not run)## Not run: client <- odds_client() odds_get(client, "/events", sport = "basketball", league = "NBA", limit = 10) ## End(Not run)
Preserves selection identifiers, decimal odds, missing values and line text. No prices are inferred and unavailable selections remain visible. This helper accepts sports odds, not the nested racing bookmaker/runner format.
odds_table(snapshot)odds_table(snapshot)
snapshot |
A response from |
A data frame with one row per odds record, stable column types and
NA for absent values. as_of_ts_ms and ttl_seconds are attributes copied
from a single-page snapshot, when present. Empty responses retain columns.
fixture <- system.file("extdata", "odds-snapshot.json", package = "oddsapi") # The bundled fixture is synthetic and needs no API key. snapshot <- httr2::resp_body_json(httr2::response( status_code = 200, headers = list(`content-type` = "application/json"), body = readBin(fixture, "raw", n = file.info(fixture)$size))) odds_table(snapshot)fixture <- system.file("extdata", "odds-snapshot.json", package = "oddsapi") # The bundled fixture is synthetic and needs no API key. snapshot <- httr2::resp_body_json(httr2::response( status_code = 200, headers = list(`content-type` = "application/json"), body = readBin(fixture, "raw", n = file.info(fixture)$size))) odds_table(snapshot)