---
title: "Deploy OpenMed | Medical NER and PII De-identification API"
description: "OpenMed REST API: clinical entity extraction and PII de-identification"
category: "AI/ML"
url: https://railway.com/deploy/openmed-api
---

# Deploy OpenMed | Medical NER and PII De-identification API

OpenMed REST API: clinical entity extraction and PII de-identification

**[Deploy OpenMed | Medical NER and PII De-identification API on Railway](https://railway.com/template/openmed-api)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/openmed-api/manifest.json

- **Creator:** Two Workspaces
- **Category:** AI/ML

## Template content

### OpenMed https://raw.githubusercontent.com/maziyarpanahi/openmed/v3.1.0/docs/website/favicon.svg

- **Image:** ghcr.io/maziyarpanahi/openmed:v3.1.0
- **Start command:** `python -c "import os,json,hashlib,sys;k=os.environ.get('OPENMED_API_KEY','').strip();k or sys.exit('OPENMED_API_KEY is empty');os.environ['OPENMED_SERVICE_AUTH_API_KEYS']=json.dumps([{'id':'railway','key_hash':hashlib.sha256(k.encode()).hexdigest(),'scopes':['*']}]);os.execvp('python',['python','-m','openmed.service.logging','--host','0.0.0.0','--port',os.environ.get('PORT','8080')])"`
- **Health check:** /readyz
- **Public domain:** Yes

## Documentation

# Deploy and Host OpenMed on Railway

[![Deploy on Railway](https://railway.com/button.svg)](https://railway.com/new/template/openmed-api?referralCode=sLjDXb&utm_medium=integration&utm_source=button&utm_campaign=openmed-api)

[OpenMed](https://github.com/maziyarpanahi/openmed) is an open-source toolkit for clinical text: it finds diseases, drugs, genes and anatomy in medical notes, and it detects and removes personal information (names, dates of birth, record numbers, phones, addresses) in many languages. Its models are small open models that run on CPU. This template runs OpenMed's REST API from a pinned release, protected by an API key from the first boot, with downloaded models kept on a volume.

## About Hosting OpenMed

One service, the official OpenMed image, with a volume for the model cache. Models download from Hugging Face the first time a request uses them (a few seconds), then load from the volume after every redeploy.

OpenMed's own API key auth is turned on: every model route needs the `X-API-Key` header, while `/health`, `/readyz` and the `/docs` page stay open. The key is generated when you deploy. Request logs never contain the text you send.

## Common Use Cases

- De-identifying clinical notes before they reach an LLM, a data warehouse or a vendor
- Extracting diagnoses, medications and other entities from free-text medical records
- A PII-redaction API for support tickets, transcripts or forms, in English and other languages
- A self-hosted, open alternative to cloud medical NLP services, with data that stays in your project

## Dependencies for OpenMed Hosting

- Nothing external. Models come from Hugging Face; set `HF_TOKEN` only for gated models or heavy use.

### Deployment Dependencies

- [OpenMed on GitHub](https://github.com/maziyarpanahi/openmed)
- [REST service guide](https://github.com/maziyarpanahi/openmed/blob/master/docs/rest-service.md)
- [OpenMed models on Hugging Face](https://huggingface.co/OpenMed)

### Implementation Details

**First use:** copy `OPENMED_API_KEY` from the service's Variables tab, then:

```bash
curl -X POST https://‹your-domain›/pii/deidentify \
  -H "X-API-Key: $OPENMED_API_KEY" -H "Content-Type: application/json" \
  -d '{"text":"Patient John Smith, DOB 03/14/1962, phone 555-201-3344.","lang":"en","method":"mask"}'
# "Patient [first_name] [last_name], DOB [date_of_birth], phone [phone_number]."
```

Medical entities:

```bash
curl -X POST https://‹your-domain›/analyze \
  -H "X-API-Key: $OPENMED_API_KEY" -H "Content-Type: application/json" \
  -d '{"text":"Type 2 diabetes and hypertension, started on metformin.","model_name":"disease_detection_superclinical"}'
```

Open `https://‹your-domain›/docs` for every endpoint: `/pii/extract`, `/pii/deidentify` (mask, remove, replace or hash), `/analyze`, `/brief`, `/ground`, streaming and async jobs.

**Models and memory:** idle uses about 200 MB. The default English PII model brings it to about 350 MB; a large entity model (434M parameters) adds about 2 GB, so give the service 2.5 GB or more for those. `OPENMED_SERVICE_KEEP_ALIVE` unloads idle models, and `OPENMED_SERVICE_MAX_RESIDENT_MODELS` caps how many stay loaded. List models in `OPENMED_SERVICE_PRELOAD_MODELS` to load them at boot, so the first request isn't slow.

**Speed:** `OMP_NUM_THREADS` caps CPU threads per call. Without it torch starts one thread per host core, and a short request takes seconds instead of a quarter of one.

**Custom domain:** add it to `OPENMED_SERVICE_TRUSTED_HOSTS`, or OpenMed rejects requests to it.

Notes and limits:

- Change `OPENMED_API_KEY` and redeploy to rotate the key.
- OpenMed is a research toolkit, not a certified medical device. Review de-identified output before treating it as anonymous.
- Each template update pins a newer OpenMed release.

## Why Deploy OpenMed on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying OpenMed on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius v0.1 Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/openmed-api
