File size: 1,167 Bytes
d7229d4
2660792
 
 
 
d7229d4
2660792
d7229d4
2660792
d7229d4
 
2660792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
title: EHRAgent
emoji: "🏥"
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
short_description: SQL-grounded question answering over MIMIC-III/IV and eICU
---

# EHRAgent — backend

FastAPI backend for the [EHRAgent](https://github.com/suyccc/EHRAgent) chat
UI. Loads three EHRSQL benchmark databases (MIMIC-III, MIMIC-IV, eICU)
and answers natural-language questions by running an LLM tool-calling
loop with two read-only SQL tools (`get_schema`, `execute_sql`).

## Strict BYOK

This Space **never reads** an OpenAI key from its environment. Every
`/api/ask` request must include an `X-OpenAI-Api-Key` header with the
caller's own key. Keys are not logged, persisted, or shared across
requests.

## Endpoints

- `GET  /api/health`
- `GET  /api/config``{model, databases: [{id, label, ready}], byok_required: true}`
- `POST /api/ask`    → body `{question, db, question_id?}`. **Required header:**
  `X-OpenAI-Api-Key: sk-…`.

## Frontend

The chat UI is a static Next.js export hosted separately (e.g. on GitHub
Pages). It points at this Space via `NEXT_PUBLIC_BACKEND_URL` at build
time. See the project repo for the source.