The Mine Works
Medicare Part D Drug Spending Data: Unit Cost, Claims, and Beneficiary Counts via API
← All posts
tutorial June 23, 2026 · 2 min read

Medicare Part D Drug Spending Data: Unit Cost, Claims, and Beneficiary Counts via API

Pull Medicare Part D drug spending from CMS: total cost, claims, beneficiaries, and unit price by drug name or manufacturer. Track pharmaceutical pricing trends. No API key required.

Try the scraper

The actor referenced in this article. Pay only for results delivered.

View the scraper →

Medicare Part D covers prescription drugs for over 50 million Americans. CMS publishes the full spending dataset each year: how much Medicare paid per drug, per manufacturer, per provider. Our Medicare Part D Scraper makes that data queryable by drug name or manufacturer without downloading multi-gigabyte flat files.

What you get per record

  • drug_name — generic or brand name
  • manufacturer — pharmaceutical company
  • total_spending — total Medicare spend (USD)
  • total_claims — number of prescription claims
  • total_beneficiaries — number of Medicare beneficiaries
  • unit_cost_avg — average cost per unit
  • cost_per_beneficiary — total spend divided by beneficiaries
  • year — data year
  • scraped_at — ISO timestamp

Python example

import requests, time

run = requests.post(
    "https://api.apify.com/v2/acts/themineworks~medicare-part-d-drug-spending/runs",
    headers={"Authorization": f"Bearer {APIFY_TOKEN}"},
    json={
        "drug": "ozempic",
        "maxResults": 100
    }
)

run_id = run.json()["data"]["id"]

while True:
    r = requests.get(
        f"https://api.apify.com/v2/actor-runs/{run_id}",
        headers={"Authorization": f"Bearer {APIFY_TOKEN}"}
    ).json()
    if r["data"]["status"] in ("SUCCEEDED", "FAILED"):
        break
    time.sleep(5)

records = requests.get(
    f"https://api.apify.com/v2/actor-runs/{run_id}/dataset/items",
    headers={"Authorization": f"Bearer {APIFY_TOKEN}"}
).json()

for r in records:
    print(r["drug_name"], r["year"])
    print(f"  Total spend: ${r['total_spending']:,.0f}")
    print(f"  Claims: {r['total_claims']:,}")
    print(f"  Avg unit cost: ${r['unit_cost_avg']:.2f}")

Year-over-year pricing trend

import pandas as pd

df = pd.DataFrame(records)
df["total_spending"] = pd.to_numeric(df["total_spending"], errors="coerce")
df["unit_cost_avg"] = pd.to_numeric(df["unit_cost_avg"], errors="coerce")

trend = df.groupby("year").agg({
    "total_spending": "sum",
    "total_claims": "sum",
    "unit_cost_avg": "mean"
}).reset_index()

print(trend)

Top drugs by total Medicare spend

run = requests.post(
    "https://api.apify.com/v2/acts/themineworks~medicare-part-d-drug-spending/runs",
    headers={"Authorization": f"Bearer {APIFY_TOKEN}"},
    json={"maxResults": 500, "sortBy": "total_spending"}
)
# ... poll and fetch
df = pd.DataFrame(records)
print(df.nlargest(20, "total_spending")[["drug_name", "manufacturer", "total_spending", "unit_cost_avg"]])

Parameters

ParameterDefaultNotes
drugDrug name (partial match supported)
manufacturerManufacturer name filter
yearlatestData year
sortBy"total_spending"Sort field
maxResults100Maximum records to return

Use cases

Pharma market intelligence. Track how Medicare spending on your drug or a competitor’s has shifted year over year. Identify which manufacturers are gaining Medicare market share.

Drug pricing research. Compare unit costs across similar drug classes. Identify where generic entry has compressed prices versus branded drugs maintaining premium positioning.

Investment research. Before taking a position in a pharmaceutical company, map their Medicare revenue exposure by drug. High Medicare concentration is both an opportunity and a regulatory risk.

Policy analysis. Quantify total Medicare expenditure on a drug class to model the fiscal impact of coverage or pricing policy changes.

Healthcare consulting. Deliver data-backed pharmaceutical cost benchmarking to hospital systems and payers negotiating formulary contracts.

Pricing

$0.002 per record. Empty queries are not charged.

Available on Apify.

Related Actor

Explore the scraper referenced in this article — see inputs, outputs, and pricing, then run it on Apify.