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

# POST /api/generate-letter

`POST /api/generate-letter`

## Request

- Base URL: `https://forecaster.cairhealth.com`
- URL: `https://forecaster.cairhealth.com/api/generate-letter`
- Auth: HTTP bearer

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

## Changes

- **2026-11-03** `b32380ccde9a`: 3 info
  - added the optional property `error` to the response with the `400` status
  - added the optional property `error` to the response with the `401` status
  - added the optional property `error` to the response with the `500` status

[Operation history](https://skmtc.dev/cairhealth/apis/cair-health-apis/changes/api/generate-letter/post.md)

---

[API](https://skmtc.dev/cairhealth/apis/cair-health-apis.md) - [All operations](https://skmtc.dev/cairhealth/apis/cair-health-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/cairhealth/apis/cair-health-apis/revisions/b32380ccde9a?raw)
