Skip to content

How to Build an NPI Verification Tool in Python

Verifying a healthcare provider's National Provider Identifier (NPI) is a foundational step in any EHR, credentialing, or medical billing workflow. Instead of downloading and managing the massive, multi-gigabyte CMS NPPES flat files yourself, you can use the Bedrock Billing API to look up NPIs programmatically.

In this tutorial, we will write a simple Python function that queries the Bedrock Billing NPPES endpoint to retrieve comprehensive details about a physician or facility.

Setting Up

Ensure you have the requests library installed:

pip install requests

You will also need your Bedrock Billing API key, which can be generated in your organization dashboard.

Querying the NPI Endpoint

The Bedrock Billing API exposes an optimized, lightning-fast wrapper around the NPPES dataset. We can search by exact NPI, or perform fuzzy searches based on name, taxonomy (specialty), and location.

Here is a simple script to verify a specific NPI:

import requests

def verify_npi(npi: str, api_key: str):
    url = f"https://api.bedrockbilling.com/api/v1/nppes/details/{npi}"

    headers = {
        "Authorization": f"X-API-Key {api_key}",
        "Accept": "application/json"
    }

    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        data = response.json()

        # Determine if this is an individual (Type 1) or organization (Type 2)
        entity_type = "Organization" if data.get('entity_type_code') == 2 else "Individual"

        # Extract basic info
        name = data.get('provider_organization_name') or f"{data.get('provider_first_name')} {data.get('provider_last_name')}"

        print(f"✅ NPI Verified: {npi}")
        print(f"Entity Type: {entity_type}")
        print(f"Name: {name}")

        # Print primary taxonomy (specialty)
        taxonomies = data.get('taxonomies', [])
        primary = next((t for t in taxonomies if t.get('primary_taxonomy')), None)
        if primary:
            print(f"Primary Specialty: {primary.get('desc')} (Code: {primary.get('code')})")

    elif response.status_code == 404:
        print(f"❌ Custom Error: NPI {npi} not found in the NPPES registry.")
    else:
        print(f"⚠️ API Error: {response.status_code}")

# Run the test
API_KEY = "sk_live_your_key_here"
verify_npi("1234567890", API_KEY)

Why use an API over the CMS Data files?

  1. Always Up-to-Date: The Bedrock Billing engine syncs with the CMS NPPES dissemination files nightly.
  2. Zero Infrastructure: The raw NPPES registry is a massive CSV file requiring a dedicated database to query quickly. We handle the indexing and hosting.
  3. Structured Relationships: The API automatically joins cryptic taxonomy codes to their human-readable descriptions, saving you from maintaining separate reference tables.

Next Steps

Searching by exact NPI is just the beginning. You can also use the /nppes/search endpoint to build full provider directory search interfaces combining Zip codes, fuzzy name matching, and specialty filters.