Blog

Build a Drug Interaction Checker in 30 Minutes

A step-by-step tutorial for building a working drug interaction checker using the RxLabelGuard API. Includes complete Python and JavaScript code, example output, and guidance on extending to a web interface.

Published Mar 13, 2026Updated Mar 13, 202611 min read
TutorialDrug Interaction APIJavaScriptPythonQuickstart

What we are building

In this tutorial, you will build a working drug interaction checker that accepts drug names as input and returns structured interaction results with severity levels, mechanisms, and clinical recommendations. The entire project takes about 30 minutes from account registration to a running application.

The checker works as a command-line tool that you can run with any combination of drug names. Under the hood, it calls the RxLabelGuard API, which handles drug name normalization via RxNorm, FDA label retrieval, interaction extraction, and severity classification. You write the interface; the API does the heavy lifting.

We will build two versions: one in Python and one in Node.js. Both produce the same output and can be extended to a web interface with minimal additional work. By the end of this tutorial, you will have a functional tool and a clear understanding of the API response structure for building more sophisticated integrations.

Prerequisites

You need three things to follow this tutorial. First, a RxLabelGuard account, which is free and takes about 60 seconds to create at /register. Second, either Python 3.8+ with the requests library installed, or Node.js 18+ (which includes the built-in fetch API). Third, a terminal or command prompt to run the scripts.

The free tier provides 50 API requests per month, which is more than enough for this tutorial and ongoing experimentation. Each request can check interactions between multiple drugs at once, so 50 requests goes further than it might sound. If you are building something more substantial, the Developer tier at $20/month provides higher limits (see /pricing for details).

Get your API key

After registering at /register, sign in to the dashboard. The dashboard displays your current plan, usage metrics, and API key management. Click the button to create a new API key. Give it a descriptive label like 'interaction-checker-tutorial' so you can identify it later.

When the key is created, the dashboard shows the full key value exactly once. Copy it immediately and store it securely. The key is a long random string prefixed with 'rxlg_'. You will not be able to see the full key again after this point, though you can always create a new one if needed.

The API key is passed in the x-api-key header on every request. It authenticates your requests and tracks them against your plan's quota. Do not commit the key to version control or include it in client-side code that would be visible to end users.

Python version: drug_checker.py

Here is a complete Python script that accepts drug names as command-line arguments, checks for interactions via the RxLabelGuard API, and prints formatted results with color-coded severity levels. Save this as drug_checker.py and replace YOUR_API_KEY with the key you copied from the dashboard.

import requests import sys import json API_KEY = "YOUR_API_KEY" API_URL = "https://jd6095ijga.execute-api.us-east-2.amazonaws.com/v1/interactions/check" SEVERITY_COLORS = { "contraindicated": "\033[91m", "major": "\033[91m", "moderate": "\033[93m", "minor": "\033[92m", "unknown": "\033[90m", } RESET = "\033[0m" def check_interactions(drugs): response = requests.post( API_URL, headers={"x-api-key": API_KEY, "Content-Type": "application/json"}, json={"drugs": drugs}, ) response.raise_for_status() return response.json() def format_severity(severity): color = SEVERITY_COLORS.get(severity, "") return f"{color}{severity.upper()}{RESET}" if __name__ == "__main__": drugs = sys.argv[1:] if len(drugs) < 2: print("Usage: python drug_checker.py drug1 drug2 [drug3 ...]") sys.exit(1) print(f"Checking interactions for: {', '.join(drugs)}") result = check_interactions(drugs) pairs = result.get("pairs", []) if not pairs: print("No interactions found.") else: for pair in pairs: severity = pair.get("maxSeverity", "unknown") print(f"\n{pair['drugA']} + {pair['drugB']}: {format_severity(severity)}") for interaction in pair.get("interactions", []): if interaction.get("mechanism"): print(f" Mechanism: {interaction['mechanism']}") if interaction.get("recommendation"): print(f" Recommendation: {interaction['recommendation']}") if interaction.get("evidenceSnippet"): print(f" Evidence: {interaction['evidenceSnippet'][:120]}...") disclaimer = result.get("disclaimer", "") if disclaimer: print(f"\n{disclaimer}")

The script is straightforward. The check_interactions function sends a POST request to the /v1/interactions/check endpoint with the drug list. The API returns a response containing a pairs array, where each pair includes the two drug names, a maxSeverity classification, and an array of individual interactions with mechanism, recommendation, and evidence snippet details. The format_severity function adds ANSI color codes so that contraindicated and major interactions appear in red, moderate in yellow, minor in green, and unknown in gray.

Install the requests library if you do not have it already: pip install requests. Then run the script with two or more drug names as arguments.

JavaScript version: checker.mjs

Here is the equivalent script in Node.js using the built-in fetch API available in Node.js 18+. Save this as checker.mjs (the .mjs extension enables ES module syntax) and replace YOUR_API_KEY with your key.

const API_KEY = "YOUR_API_KEY"; const API_URL = "https://jd6095ijga.execute-api.us-east-2.amazonaws.com/v1/interactions/check"; const SEVERITY_COLORS = { contraindicated: "\x1b[91m", major: "\x1b[91m", moderate: "\x1b[93m", minor: "\x1b[92m", unknown: "\x1b[90m", }; const RESET = "\x1b[0m"; async function checkInteractions(drugs) { const response = await fetch(API_URL, { method: "POST", headers: { "x-api-key": API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ drugs }), }); if (!response.ok) { throw new Error(`API error: ${response.status} ${response.statusText}`); } return response.json(); } function formatSeverity(severity) { const color = SEVERITY_COLORS[severity] || ""; return `${color}${severity.toUpperCase()}${RESET}`; } const drugs = process.argv.slice(2); if (drugs.length < 2) { console.log("Usage: node checker.mjs drug1 drug2 [drug3 ...]"); process.exit(1); } console.log(`Checking interactions for: ${drugs.join(", ")}`); const result = await checkInteractions(drugs); const pairs = result.pairs || []; if (pairs.length === 0) { console.log("No interactions found."); } else { for (const pair of pairs) { const severity = pair.maxSeverity || "unknown"; console.log(`\n${pair.drugA} + ${pair.drugB}: ${formatSeverity(severity)}`); for (const interaction of pair.interactions || []) { if (interaction.mechanism) { console.log(` Mechanism: ${interaction.mechanism}`); } if (interaction.recommendation) { console.log(` Recommendation: ${interaction.recommendation}`); } if (interaction.evidenceSnippet) { console.log(` Evidence: ${interaction.evidenceSnippet.slice(0, 120)}...`); } } } } if (result.disclaimer) { console.log(`\n${result.disclaimer}`); }

The JavaScript version follows the same logic as the Python script. It uses Node.js built-in fetch (no external dependencies required), sends the drug list to the API, and formats the response with terminal colors. The top-level await syntax requires the .mjs file extension or a package.json with "type": "module".

Running your checker

With either script saved and your API key configured, you can test it immediately. Try a well-known interaction pair like warfarin and aspirin, which has a documented interaction involving increased bleeding risk.

For Python: python drug_checker.py warfarin aspirin. For Node.js: node checker.mjs warfarin aspirin. You should see output showing the drug pair, severity level (likely major), the mechanism of interaction, and a clinical recommendation. The response also includes an evidence snippet from the source FDA label.

Try adding more drugs to see how the API handles multi-drug checks. For example: python drug_checker.py warfarin aspirin metformin lisinopril. The API checks all pairwise combinations and returns interactions for each pair that has documented interactions. Pairs without documented interactions are omitted from the response, keeping the output focused on actionable results.

The output includes an FDA disclaimer reminding users that the information is derived from FDA Structured Product Labeling and should not substitute for professional medical advice. This disclaimer is always present in API responses and should be displayed in any user-facing application. For the full API response schema and additional fields, see the documentation at /docs/check-interactions.

Extending to a web interface

The command-line checker is useful for testing and scripting, but most production use cases need a web interface. The good news is that wrapping the API call in a web framework is straightforward with either language.

In Python, a minimal Flask application can serve a form that accepts drug names and displays results. The core logic is identical to the CLI script: collect drug names from the form, call the RxLabelGuard API, and render the structured results. Flask's Jinja2 templates make it easy to color-code severity levels and format the interaction details as HTML. A basic Flask wrapper adds roughly 30 lines of code on top of the checker logic.

In Node.js, an Express application follows the same pattern. A simple HTML form submits drug names to a POST route, which calls the RxLabelGuard API server-side and renders the results. Alternatively, you can build a client-side application that calls the API directly from the browser, but this exposes your API key in client-side code and is only appropriate for internal tools. For public-facing applications, always proxy API calls through your backend.

RxLabelGuard also provides a /v1/interactions/ask endpoint that accepts natural language queries like 'Can I take ibuprofen with warfarin?' and returns the same structured interaction data. This endpoint is particularly useful for chatbot integrations or patient-facing interfaces where users are more likely to type questions than structured drug lists. See /docs/ask for the request and response format.

Adding severity filtering

In production applications, you often want to filter interactions by severity to reduce noise and focus on clinically significant results. The API response includes a maxSeverity field on each pair, making it straightforward to implement client-side filtering.

Here is how to modify the Python checker to only display major and contraindicated interactions. Add a --severity flag that accepts a minimum severity level, and filter the pairs before displaying them.

SEVERITY_ORDER = ["unknown", "minor", "moderate", "major", "contraindicated"] def meets_threshold(pair_severity, min_severity): pair_idx = SEVERITY_ORDER.index(pair_severity) if pair_severity in SEVERITY_ORDER else 0 min_idx = SEVERITY_ORDER.index(min_severity) if min_severity in SEVERITY_ORDER else 0 return pair_idx >= min_idx # Usage: python drug_checker.py --min-severity major warfarin aspirin metformin

With this filter in place, running the checker with --min-severity major shows only interactions classified as major or contraindicated. This is particularly useful when checking large drug lists where many moderate or minor interactions would otherwise dominate the output. For EHR integrations where alert fatigue is a concern, severity filtering is essential. Our article on alert fatigue at /blog/alert-fatigue-drug-interaction-severity-scoring discusses this topic in depth.

What is next

You now have a working drug interaction checker that you can use from the command line, extend to a web interface, and customize with severity filtering. Here are the next steps depending on your use case.

For API reference and full response schema details, visit /docs. The documentation covers all available fields, error codes, rate limit headers, and request options for both the /v1/interactions/check and /v1/interactions/ask endpoints. For the check endpoint specifically, see /docs/check-interactions.

If you are building an EHR integration or clinical decision support system, the guide at /use-cases/ehr-integration covers production patterns including tiered alerting, audit logging, and compliance considerations. Our article on how to check drug interactions programmatically at /blog/how-to-check-drug-interactions-programmatically provides additional architectural guidance.

For scaling beyond the free tier, visit /pricing to compare the Developer ($20/month) and Professional ($99/month) plans. If you are evaluating RxLabelGuard against other options, the comparison page at /compare provides a detailed feature matrix, and /free-drug-interaction-api explains what is available at no cost.

The code from this tutorial is deliberately minimal. In a production application, you would add error handling for network failures, retries with exponential backoff, response caching to avoid redundant API calls, and proper secret management for your API key. These are standard API integration patterns, and the RxLabelGuard API behaves like any well-designed REST API in terms of error codes and rate limit headers.

References

  1. openFDA Drug Label Endpoint (U.S. Food and Drug Administration (FDA); accessed Mar 6, 2026)
  2. RxNorm API (U.S. National Library of Medicine (NLM); accessed Mar 6, 2026)