---
title: "POST /api/generate-letter"
method: POST
path: "/api/generate-letter"
---

# POST /api/generate-letter

`POST /api/generate-letter`

Generates a Letter of Medical Necessity (LMN) from uploaded procedure notes using AI analysis. The letter can be returned as plain text or as a formatted PDF document based on the `output_format` parameter.

## Request body

- GenerateLetterRequest — Request body for generating a Letter of Medical Necessity from encounter notes
  - `file_content` string, required — Base64 encoded content of the procedure notes file (PDF)
  - `patient_identifier` string, required — Unique identifier for the patient
  - `patient_name` string, required — Patient's full name
  - `patient_age` string, required — Patient's age
  - `facility_name` string, required — Name of the medical facility or center
  - `visit_cost` string, required — Cost of the visit or procedure
  - `provider_email` string, email, required — Provider's contact email address
  - `provider_phone` string, required — Provider's contact phone number
  - `provider_signature` string, required — Signature line text for the letter
  - `provider_name` string, required — Name and credentials of the provider signing the letter
  - `output_format` 'text' | 'pdf' — Output format for the letter. Defaults to 'text' if not specified.

## Response `200`

Letter of Medical Necessity generated successfully

- LetterResponse — Response containing the generated Letter of Medical Necessity. The response format depends on the `output_format` parameter in the request.
  - `letter` string — The generated Letter of Medical Necessity content in text format. Present when `output_format` is 'text' or not specified.
  - `fileContent` string — Base64 encoded PDF content of the generated letter. Present when `output_format` is 'pdf'.
  - `timestamp` string, date-time — Timestamp when the letter was generated
  - `invoice_cost` string — The visit cost associated with the letter generation
  - `patient_identifier` string — The patient identifier associated with the letter

## Other responses

- `400` — Invalid request or file processing error
- `401` — Unauthorized access or invalid organization ID
- `500` — Server error or letter generation failure

---

[API](https://skmtc.net/cairhealth/apis/cair-health-apis.md) · [All operations](https://skmtc.net/cairhealth/apis/cair-health-apis/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/cairhealth/cair-health-apis/revisions/dfc60069747b/schema)
