# Medicare Part D Drug Spending Scraper - CMS Pricing Data (`themineworks/medicare-part-d-drug-spending`) Actor

Scrape Medicare Part D drug spending from CMS: total cost, claims, beneficiaries, unit cost & manufacturer for every brand/generic drug. Structured JSON, no API key. An IQVIA-style pharma pricing source for Claude, ChatGPT & any MCP agent.

- **URL**: https://apify.com/themineworks/medicare-part-d-drug-spending.md
- **Developed by:** [The Mine Works](https://apify.com/themineworks) (community)
- **Categories:** Business, Developer tools, MCP servers
- **Stats:** 1 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 drug record scrapeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Medicare Part D Drug Spending — CMS Pricing & Utilization

Pull **Medicare Part D drug spending data** from CMS — total expenditure, beneficiary count, unit cost, and manufacturer — for every branded and generic drug in the Medicare program, as clean structured JSON. Built for **pharma pricing intelligence, formulary analysis, market research, and policy work**. No API key required.

**Keywords:** Medicare Part D spending, CMS drug spending, drug pricing data, Medicare utilization, pharma market data, CMS drug costs API.

---

### Why this actor

CMS publishes annual Medicare Part D spending data covering every drug prescribed to Medicare beneficiaries — total cost, number of claims, beneficiary count, and average unit cost. Commercial data providers (IQVIA, Symphony Health) charge thousands per year for equivalent data. This actor gives you direct, structured access to the official CMS source at PPE pricing.

- **All Part D drugs** — branded and generic, 2013–2022.
- **Manufacturer-level data** — track spending by brand owner.
- **Unit cost trends** — year-over-year average cost per unit.
- **No API key** — official CMS open data (Socrata API).

---

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `drugName` | string | `Ozempic` | Brand or generic name, partial match. |
| `manufacturer` | string | — | Filter by manufacturer name. |
| `year` | integer | — | Reporting year (2013–2022). |
| `minSpend` | integer | — | Minimum total Medicare spend ($). |
| `maxResults` | integer | 200 | Maximum records to return. |

---

### Output

```json
{
  "year": "2022",
  "brand_name": "OZEMPIC",
  "generic_name": "SEMAGLUTIDE",
  "manufacturer": "NOVO NORDISK INC",
  "total_beneficiaries": 1240000,
  "total_claims": 8900000,
  "total_spending_usd": 5820000000,
  "spending_per_beneficiary_usd": 4693.55,
  "unit_cost_avg_usd": 847.23,
  "scraped_at": "2026-06-15T00:00:00.000Z"
}
````

***

### Pricing

**First 25 records free per account**, then **$0.004 per record** ($4 per 1,000). Zero charge on empty runs.

***

### FAQ

**What years are available?** CMS publishes Part D spending data from 2013 through 2022 (most recent available). New years are typically released 18 months after the close of the reporting period.

**Does this include generic drugs?** Yes — both brand-name and generic drugs are included, identified separately in the output.

**What is the unit cost field?** The `unit_cost_avg_usd` field is a weighted average cost per unit (pill, vial, etc.) across all dispensing pharmacies and claim types.

**Can I track a drug's spending over multiple years?** Yes — leave the `year` field blank to retrieve all available years for a given drug name, then sort by year for a trend view.

**Who uses this data?** Pharma market researchers tracking competitor drug utilization; payer and PBM analysts benchmarking formulary spend; biotech investors sizing drug market opportunity; health economists and policy researchers; journalists covering drug pricing.

**How is this different from other drug databases?** This data comes directly from CMS claims — it represents actual Medicare reimbursement, not list price. It is the most authoritative source for Medicare utilization and real-world spending.

**Can I automate regular updates?** Yes — schedule this actor annually on Apify to pull the latest year when CMS releases updated data.

### Use in Claude, ChatGPT & any MCP agent

This actor is also a **Model Context Protocol (MCP) server tool** — call it directly from Claude, ChatGPT, Cursor, Windsurf, or any MCP-compatible AI agent. The agent only pays for results delivered (same pay-per-result model).

- Per-actor MCP endpoint: `https://mcp.apify.com/?tools=themineworks/medicare-part-d-drug-spending`
- Full Mine Works MCP server (all tools): `https://the-mine-works-mcp.hatchable.site/api/mcp`

```js
// Call this actor as a tool via apify-client (Node)
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'YOUR_APIFY_TOKEN' });
const run = await client.actor('themineworks/medicare-part-d-drug-spending').call({ /* input from the table above */ });
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

# Actor input Schema

## `drugName` (type: `string`):

Brand or generic drug name (partial match). e.g. Humira, atorvastatin, Ozempic.

## `manufacturer` (type: `string`):

Filter by manufacturer / brand name owner (partial match).

## `year` (type: `integer`):

Reporting year (recent release covers ~2019-2023). Leave blank to use the latest year available per drug.

## `minSpend` (type: `integer`):

Return only drugs with total Medicare spend above this threshold.

## `maxResults` (type: `integer`):

Maximum drug records to return.

## Actor input object example

```json
{
  "drugName": "Ozempic",
  "maxResults": 25
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "drugName": "Ozempic",
    "maxResults": 25
};

// Run the Actor and wait for it to finish
const run = await client.actor("themineworks/medicare-part-d-drug-spending").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "drugName": "Ozempic",
    "maxResults": 25,
}

# Run the Actor and wait for it to finish
run = client.actor("themineworks/medicare-part-d-drug-spending").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "drugName": "Ozempic",
  "maxResults": 25
}' |
apify call themineworks/medicare-part-d-drug-spending --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=themineworks/medicare-part-d-drug-spending",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Medicare Part D Drug Spending Scraper - CMS Pricing Data",
        "description": "Scrape Medicare Part D drug spending from CMS: total cost, claims, beneficiaries, unit cost & manufacturer for every brand/generic drug. Structured JSON, no API key. An IQVIA-style pharma pricing source for Claude, ChatGPT & any MCP agent.",
        "version": "0.1",
        "x-build-id": "rhtQvPRrNeP36NMkf"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/themineworks~medicare-part-d-drug-spending/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-themineworks-medicare-part-d-drug-spending",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/themineworks~medicare-part-d-drug-spending/runs": {
            "post": {
                "operationId": "runs-sync-themineworks-medicare-part-d-drug-spending",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/themineworks~medicare-part-d-drug-spending/run-sync": {
            "post": {
                "operationId": "run-sync-themineworks-medicare-part-d-drug-spending",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "drugName": {
                        "title": "Drug name",
                        "type": "string",
                        "description": "Brand or generic drug name (partial match). e.g. Humira, atorvastatin, Ozempic."
                    },
                    "manufacturer": {
                        "title": "Manufacturer name",
                        "type": "string",
                        "description": "Filter by manufacturer / brand name owner (partial match)."
                    },
                    "year": {
                        "title": "Year",
                        "type": "integer",
                        "description": "Reporting year (recent release covers ~2019-2023). Leave blank to use the latest year available per drug."
                    },
                    "minSpend": {
                        "title": "Min total spend ($)",
                        "type": "integer",
                        "description": "Return only drugs with total Medicare spend above this threshold."
                    },
                    "maxResults": {
                        "title": "Max results",
                        "minimum": 1,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Maximum drug records to return.",
                        "default": 200
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
