Our API supports sampling on all /results endpoints to provide a uniform sample of the dataset for efficient data analysis and visualization. This feature is particularly useful for use cases like charting (if you only have 4 000 pixels on the chart, then 10 000 datapoints are plenty), where analyzing a full dataset isn’t necessary. Sampling returns a subset (with a uniform distribution) of data, optimizing usage of very large results with reduced latency and costs. You can apply sampling to the following endpoints:

Example Sampling Request

curl -X GET "https://api.dune.com/api/v1/query/{{query_id}}/results?sample_count=10000" -H "x-dune-api-key: {{api_key}}"

Sampling Parameters

sample_count

  • Type: integer
  • Description: Determines the number of rows to return as a sample from the result set. If the available dataset contains fewer rows than the specified sample_count, the entire dataset is returned.
  • Sampling is designed to provide a randomized subset of data, with each request potentially producing different outcomes.
  • When specifying sample_count (e.g., sample_count = 10000), the number is approximate. The actual number of rows returned may vary slightly (e.g., 10013, 10017), reflecting the probabilistic nature of the sampling process.
  • sample_count is incompatible with offset, limit, and filters parameters.
  • sample_count can be used with columns to specify which data fields to include in the sample.
  • Specifying a low sample_count relative to total rows, being probabilistic, may return 0 rows due to the probability based sampling calculation (e.g., 10 in 100,000, means each row has ~0.01% chance to be included)

Sampling Response