MOISSCode REST API
The MOISSCode API lets you execute protocols and call module functions over HTTP. Use it to integrate clinical decision support into your applications, EHR systems, or data pipelines.
Base URL: https://api.moisscode.com/v1
Authentication
All requests (except /health and /tiers) require an API key in the X-API-Key header:
curl -H "X-API-Key: your_key_here" https://api.moisscode.com/v1/health
API keys are issued per-organization. Contact dev@aethryva.com to request access.
Endpoints
GET /health
Health check. No authentication required.
Response:
{
"status": "healthy",
"version": "1.0.0",
"engine_version": "2.0.0",
"modules": 19
}
GET /tiers
List available pricing tiers. No authentication required.
Response:
{
"tiers": [
{
"id": "sandbox",
"name": "Sandbox",
"requests_per_month": 50,
"price_usd": 0,
"rate_limit_per_minute": 5,
"description": "Free evaluation tier for testing and prototyping"
},
{
"id": "starter",
"name": "Starter",
"requests_per_month": 5000,
"price_usd": 99,
"rate_limit_per_minute": 30,
"description": "For small teams and pilot projects"
},
{
"id": "professional",
"name": "Professional",
"requests_per_month": 50000,
"price_usd": 299,
"rate_limit_per_minute": 120,
"description": "For production clinical decision support workloads"
},
{
"id": "enterprise",
"name": "Enterprise",
"requests_per_month": -1,
"price_usd": -1,
"rate_limit_per_minute": 600,
"description": "Custom pricing for high-volume and on-premise deployments"
}
]
}
GET /modules
List all available modules and their functions. No authentication required.
Response:
{
"module_count": 19,
"modules": {
"scores": ["qsofa", "sofa", "news2", "meld", ...],
"pk": ["calculate_dose", "check_interactions", "renal_adjust", ...],
"lab": ["interpret", "gfr", "panel"],
"glucose": ["hba1c_from_glucose", "time_in_range", "gmi", ...],
"chem": ["molecular_weight", "lipinski_check", "screen_compound", ...],
"signal": ["detect_peaks", "heart_rate_from_rr", "hrv_metrics", ...],
"icd": ["lookup", "search", "drg_lookup", "validate_codes", ...]
}
}
POST /run
Execute a MOISSCode protocol. Returns events, alerts, and execution statistics.
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | MOISSCode source code |
patient | object | No | Patient vitals override (see below) |
Patient object fields (all optional):
| Field | Type | Default |
|---|---|---|
bp | number | 90 |
hr | number | 110 |
rr | number | 22 |
temp | number | 38.3 |
spo2 | number | 94 |
weight | number | 70 |
age | number | 55 |
gcs | number | 15 |
lactate | number | 2.0 |
sex | string | "M" |
Example request:
curl -X POST https://api.moisscode.com/v1/run \
-H "X-API-Key: your_key_here" \
-H "Content-Type: application/json" \
-d '{
"code": "protocol Test { input: Patient p; let score = med.scores.qsofa(p); }",
"patient": {"bp": 85, "hr": 120, "rr": 24, "age": 62}
}'
Response:
{
"success": true,
"events": [
{"event": "[1] LOG: [Protocol] Executing: Test"},
{"event": "[3] LOG: [Let] score = 3"}
],
"alerts": [],
"stats": {
"event_count": 4,
"execution_time_ms": 12.5,
"engine_version": "2.0.0"
},
"error": null
}
Error response (400):
{
"success": false,
"events": [],
"alerts": [],
"stats": {},
"error": "Syntax error: Expected '}' at line 3"
}
POST /call
Call a single module function directly, without writing a full protocol.
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
module | string | Yes | Module name (e.g. "scores", "lab", "glucose") |
function | string | Yes | Function name (e.g. "qsofa", "interpret") |
args | array | No | Positional arguments |
kwargs | object | No | Keyword arguments |
Example - Lab interpretation:
curl -X POST https://api.moisscode.com/v1/call \
-H "X-API-Key: your_key_here" \
-H "Content-Type: application/json" \
-d '{
"module": "lab",
"function": "interpret",
"args": ["Glucose", 220]
}'
Response:
{
"success": true,
"result": {
"type": "LAB_RESULT",
"test": "Glucose",
"value": 220,
"flag": "HIGH",
"is_critical": false,
"reference_range": "70.0-100.0 mg/dL"
},
"error": null
}
Example - Drug interaction check:
curl -X POST https://api.moisscode.com/v1/call \
-H "X-API-Key: your_key_here" \
-H "Content-Type: application/json" \
-d '{
"module": "pk",
"function": "check_interactions",
"args": ["Morphine", ["Midazolam"]]
}'
Example - Lipinski screening:
curl -X POST https://api.moisscode.com/v1/call \
-H "X-API-Key: your_key_here" \
-H "Content-Type: application/json" \
-d '{
"module": "chem",
"function": "lipinski_check",
"args": [285.34, 1.2, 1, 4]
}'
GET /usage
Get usage statistics for your API key.
Response:
{
"tier": "starter",
"owner": "your_org",
"requests_used": 142,
"requests_limit": 5000,
"period": "2026-02"
}
Error Codes
| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad request (missing fields, syntax error in code) |
| 401 | Invalid or missing API key |
| 408 | Execution timeout (protocol exceeded 10 second limit) |
| 413 | Request too large (code exceeds 10,000 character limit) |
| 429 | Rate limit exceeded (monthly or per-minute) |
| 500 | Internal server error |
Rate Limits
Rate limits are enforced at two levels:
| Level | Sandbox | Starter | Professional | Enterprise |
|---|---|---|---|---|
| Per month | 50 | 5,000 | 50,000 | Unlimited |
| Per minute | 5 | 30 | 120 | 600 |
When a rate limit is exceeded, the API returns HTTP 429 with a message indicating which limit was hit and when it resets.
Self-Hosting
You can run the API server locally for development:
pip install -e ".[api]"
# Dev mode (no auth required)
MOISSCODE_API_DEV_MODE=1 uvicorn moisscode.api.server:app --reload
# Production mode
uvicorn moisscode.api.server:app --host 0.0.0.0 --port 8000
Interactive API documentation is available at http://localhost:8000/docs (Swagger UI) and http://localhost:8000/redoc (ReDoc).
SDKs
Python
import requests
API_KEY = "your_key_here"
BASE = "https://api.moisscode.com/v1"
HEADERS = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
# Run a protocol
resp = requests.post(f"{BASE}/run", json={
"code": "protocol Test { input: Patient p; let score = med.scores.qsofa(p); }"
}, headers=HEADERS)
print(resp.json())
# Call a function directly
resp = requests.post(f"{BASE}/call", json={
"module": "lab",
"function": "interpret",
"args": ["Glucose", 220]
}, headers=HEADERS)
print(resp.json()["result"])
JavaScript
const API_KEY = "your_key_here";
const BASE = "https://api.moisscode.com/v1";
// Call a function directly
const resp = await fetch(`${BASE}/call`, {
method: "POST",
headers: { "X-API-Key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({
module: "glucose",
function: "hba1c_from_glucose",
args: [172]
})
});
const data = await resp.json();
console.log(data.result);
cURL
# Interpret a lab result
curl -X POST https://api.moisscode.com/v1/call \
-H "X-API-Key: your_key_here" \
-H "Content-Type: application/json" \
-d '{"module": "lab", "function": "interpret", "args": ["HbA1c", 8.2]}'
See Also
- Python SDK — direct Python embedding without REST
- Deployment — deploying the API to production
- CLI — command-line protocol execution