{
  "openapi": "3.1.0",
  "info": {
    "title": "MedLegal AI Public API",
    "version": "1.0.0",
    "description": "Programmatic access to MedLegal AI for paying customers. Issue keys at /settings/api-keys. Pro tier ships 1000 calls/hr; Enterprise scales to 10,000+.",
    "contact": {
      "email": "support@medicalai.law",
      "url": "https://medicalai.law/developers"
    }
  },
  "servers": [
    {
      "url": "https://medicalai.law",
      "description": "Production"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mlai_*",
        "description": "Issue keys at /settings/api-keys. Format: `Authorization: Bearer mlai_<32 hex chars>`."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "message"
        ]
      },
      "WitnessResearchResult": {
        "type": "object",
        "properties": {
          "query": {
            "type": "object"
          },
          "result": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "specialty": {
                "type": "string"
              },
              "publications": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "publicationCount": {
                "type": "integer"
              },
              "topJournals": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "topYears": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "observations": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "fetchedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/witness/research": {
      "post": {
        "summary": "9-source expert-witness workup",
        "description": "PubMed publication history + heuristics for the named witness. Specialty / focusArea filters narrow PubMed search. NPI passthrough for downstream lookups. v1 surfaces PubMed only — full 9-source aggregation is v2.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "firstName": {
                    "type": "string"
                  },
                  "lastName": {
                    "type": "string"
                  },
                  "npi": {
                    "type": "string"
                  },
                  "specialty": {
                    "type": "string",
                    "example": "cardiology"
                  },
                  "focusArea": {
                    "type": "string",
                    "example": "interventional"
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "lastName"
                    ]
                  },
                  {
                    "required": [
                      "npi"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workup",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WitnessResearchResult"
                }
              }
            }
          },
          "400": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Bearer token"
          },
          "429": {
            "description": "Per-key rate limit exceeded"
          }
        }
      }
    },
    "/v1/witness/prior-depositions": {
      "post": {
        "summary": "CourtListener prior-depositions / prior-litigation lookup",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "npi": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string",
                    "example": "FL"
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "name"
                    ]
                  },
                  {
                    "required": [
                      "npi"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Hits + summary"
          },
          "400": {
            "description": "Validation failed"
          },
          "401": {
            "description": "Auth"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/v1/citation/verify": {
      "post": {
        "summary": "Verify a legal citation against its CourtListener opinion",
        "description": "Returns a verdict (verified / refuted / unsupported / not_found) + Claude-generated reasoning + a link to the CourtListener opinion.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "citation",
                  "propositionContext"
                ],
                "properties": {
                  "citation": {
                    "type": "string",
                    "example": "123 F.3d 456"
                  },
                  "propositionContext": {
                    "type": "string",
                    "example": "A treating physician may give expert opinion testimony without disclosure under Rule 26(a)(2)(B)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification result"
          },
          "400": {
            "description": "Validation failed"
          },
          "401": {
            "description": "Auth"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/v1/daubert/memo": {
      "post": {
        "summary": "Generate the 14-section Daubert memo (markdown)",
        "description": "Requires `read-write` scope. Consumes Claude tokens; counted toward your hourly quota. .docx / PDF rendering is deferred to v2 — for now the markdown can be piped to your own renderer.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "caseContext"
                ],
                "properties": {
                  "caseContext": {
                    "type": "object",
                    "properties": {
                      "witnessName": {
                        "type": "string"
                      },
                      "specialty": {
                        "type": "string"
                      },
                      "caseCaption": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "witnessName"
                    ]
                  },
                  "witnessResearch": {
                    "type": "object",
                    "description": "Optional: pass a prior /v1/witness/research result to enrich the memo."
                  },
                  "transcript": {
                    "type": "string",
                    "description": "Optional: deposition transcript text (max ~50,000 chars)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Memo (markdown)"
          },
          "400": {
            "description": "Validation failed"
          },
          "401": {
            "description": "Auth"
          },
          "403": {
            "description": "Read-write scope required"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Per-key call count + remaining quota",
        "responses": {
          "200": {
            "description": "Quota state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keyId": {
                      "type": "string"
                    },
                    "keyHint": {
                      "type": "string"
                    },
                    "scope": {
                      "type": "string",
                      "enum": [
                        "read",
                        "read-write"
                      ]
                    },
                    "limitPerHour": {
                      "type": "integer"
                    },
                    "used": {
                      "type": "integer"
                    },
                    "remaining": {
                      "type": "integer"
                    },
                    "resetAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}