SOAPNoteAPI
Python5 min6 steps

Generate a SOAP Note with Python

Install the requests library, send a transcript, and receive a structured SOAP note in five minutes.

1

Install the requests library

The only dependency you need is the requests HTTP library. If you already have it installed, skip ahead.
Terminal
pip install requests
2

Set your API key

Export your API key as an environment variable so it stays out of source code. You can find your key in the dashboard.
Terminal
export SOAPNOTEAPI_KEY="snapi_sk_test_your_key_here"
3

Make the request

Send a POST request to /v1/note with a clinical transcript and a specialty. The API returns a structured SOAP note.
Python
import os
import requests

api_key = os.environ["SOAPNOTEAPI_KEY"]

response = requests.post(
    "https://api.soapnoteapi.com/v1/note",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "transcript": (
            "Patient is a 45-year-old male presenting with lower back pain "
            "for the past two weeks. Pain is rated 6/10, worse with bending. "
            "No radiculopathy. Ibuprofen provides partial relief. Physical exam "
            "shows paravertebral muscle tenderness at L4-L5. Straight leg raise "
            "negative bilaterally. Assessment: acute lumbar strain. Plan: "
            "continue NSAIDs, start physical therapy twice weekly, follow up in "
            "4 weeks if not improved."
        ),
        "specialty": "nurse_practitioner",
    },
)

note = response.json()
print(note)
4

Parse the response

The response body contains the four SOAP sections as separate fields, plus metadata. Each section is a formatted string ready for your EHR.
JSON
# Successful response (200 OK)
{
  "noteId": "note_abc123",
  "subjective": "Patient is a 45-year-old male presenting with lower back pain for the past two weeks...",
  "objective": "Physical exam shows paravertebral muscle tenderness at L4-L5...",
  "assessment": "Acute lumbar strain.",
  "plan": "Continue NSAIDs, start physical therapy twice weekly...",
  "expires_at": "2026-09-21T00:00:00Z"
}
5

Handle errors

Check the status code before parsing. The API returns structured error objects with a message field describing what went wrong.
Python
response = requests.post(
    "https://api.soapnoteapi.com/v1/note",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "transcript": "Patient presents with...",
        "specialty": "nurse_practitioner",
    },
)

if response.status_code == 200:
    note = response.json()
    print("Subjective:", note["subjective"])
    print("Objective:", note["objective"])
    print("Assessment:", note["assessment"])
    print("Plan:", note["plan"])
elif response.status_code == 401:
    print("Invalid API key. Check your SOAPNOTEAPI_KEY variable.")
elif response.status_code == 400:
    error = response.json()
    print("Validation error:", error["message"])
elif response.status_code == 429:
    print("Rate limited. Wait and retry.")
else:
    print(f"Unexpected error ({response.status_code}):", response.text)
6

Complete runnable script

Copy this self-contained script to generate a SOAP note from the command line. Set your SOAPNOTEAPI_KEY environment variable first.
Python
#!/usr/bin/env python3
"""Generate a SOAP note from a clinical transcript."""

import os
import sys
import requests

API_URL = "https://api.soapnoteapi.com/v1/note"


def generate_note(transcript: str, specialty: str = "nurse_practitioner") -> dict:
    """Send a transcript and return the parsed SOAP note."""
    api_key = os.environ.get("SOAPNOTEAPI_KEY")
    if not api_key:
        print("Error: set the SOAPNOTEAPI_KEY environment variable.", file=sys.stderr)
        sys.exit(1)

    response = requests.post(
        API_URL,
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        },
        json={
            "transcript": transcript,
            "specialty": specialty,
        },
    )
    response.raise_for_status()
    return response.json()


if __name__ == "__main__":
    transcript = (
        "Patient is a 45-year-old male presenting with lower back pain "
        "for the past two weeks. Pain is rated 6/10, worse with bending. "
        "No radiculopathy. Ibuprofen provides partial relief. Physical exam "
        "shows paravertebral muscle tenderness at L4-L5. Straight leg raise "
        "negative bilaterally. Assessment: acute lumbar strain. Plan: "
        "continue NSAIDs, start physical therapy twice weekly, follow up in "
        "4 weeks if not improved."
    )

    note = generate_note(transcript)
    for section in ("subjective", "objective", "assessment", "plan"):
        print(f"\n--- {section.upper()} ---")
        print(note[section])

Ready to start building?

Get a free API key and $10 in credit — no credit card required.

Get your free API key