> ## Documentation Index
> Fetch the complete documentation index at: https://docs.decodahealth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Patient Summary

> Generate patient summary with guaranteed valid JSON output.

Uses Gemini's native structured output streaming with json_repair fallback
and automatic retry on failure to ensure valid JSON is always returned.
Citation references are validated against the patient context.



## OpenAPI

````yaml post /ai/patient/summary
openapi: 3.1.0
info:
  title: Decoda API
  description: External API documentation for the Decoda Health platform.
  version: '1.0'
servers: []
security: []
paths:
  /ai/patient/summary:
    post:
      tags:
        - provider
        - ai
      summary: Generate Patient Summary
      description: >-
        Generate patient summary with guaranteed valid JSON output.


        Uses Gemini's native structured output streaming with json_repair
        fallback

        and automatic retry on failure to ensure valid JSON is always returned.

        Citation references are validated against the patient context.
      operationId: generate_patient_summary_ai_patient_summary_post
      parameters:
        - name: TENANT
          in: header
          required: true
          schema:
            type: string
            title: Tenant
          description: The tenant you are making this request on behalf of
        - name: API-KEY
          in: header
          required: true
          schema:
            type: string
            title: Api-Key
          description: Your api key
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatientSummaryRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    PatientSummaryRequest:
      properties:
        modelName:
          type: string
          title: Modelname
          description: Model to use for generation
          default: gemini-2.5-flash-lite
        useStructuredOutput:
          type: boolean
          title: Usestructuredoutput
          description: Whether to request structured JSON output
          default: true
        conversationHistory:
          anyOf:
            - items:
                $ref: '#/components/schemas/ConversationMessage'
              type: array
            - type: 'null'
          title: Conversationhistory
          description: Previous conversation messages for context
        files:
          anyOf:
            - items:
                $ref: '#/components/schemas/FileAttachment'
              type: array
            - type: 'null'
          title: Files
          description: File attachments for the current request
        context:
          $ref: '#/components/schemas/PatientSummaryContext'
          description: Patient context from frontend
      type: object
      required:
        - context
      title: PatientSummaryRequest
      description: Request schema for generating patient summary.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ConversationMessage:
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
          title: Role
          description: Role of the message sender
        content:
          type: string
          title: Content
          description: Message content
        timestamp:
          anyOf:
            - type: string
            - type: 'null'
          title: Timestamp
          description: Message timestamp
        files:
          anyOf:
            - items:
                $ref: '#/components/schemas/FileAttachment'
              type: array
            - type: 'null'
          title: Files
          description: File attachments (images, documents, etc.)
      type: object
      required:
        - role
        - content
      title: ConversationMessage
      description: A single message in a conversation with an AI.
    FileAttachment:
      properties:
        name:
          type: string
          title: Name
          description: File name
        size:
          type: integer
          title: Size
          description: File size in bytes
        type:
          type: string
          title: Type
          description: MIME type
        data:
          type: string
          title: Data
          description: Base64 encoded file data
      type: object
      required:
        - name
        - size
        - type
        - data
      title: FileAttachment
      description: File attachment schema.
    PatientSummaryContext:
      properties:
        patient:
          $ref: '#/components/schemas/PatientBasicInfo'
        upcomingAppointments:
          anyOf:
            - items:
                $ref: '#/components/schemas/AppointmentInfo'
              type: array
            - type: 'null'
          title: Upcomingappointments
        recentAppointments:
          anyOf:
            - items:
                $ref: '#/components/schemas/AppointmentInfo'
              type: array
            - type: 'null'
          title: Recentappointments
        recentNotes:
          anyOf:
            - items:
                $ref: '#/components/schemas/NoteInfo'
              type: array
            - type: 'null'
          title: Recentnotes
        measurements:
          anyOf:
            - items:
                $ref: '#/components/schemas/MeasurementInfo'
              type: array
            - type: 'null'
          title: Measurements
        medications:
          anyOf:
            - items:
                $ref: '#/components/schemas/MedicationInfo'
              type: array
            - type: 'null'
          title: Medications
        recentCharges:
          anyOf:
            - items:
                $ref: '#/components/schemas/ChargeInfo'
              type: array
            - type: 'null'
          title: Recentcharges
        recentForms:
          anyOf:
            - items:
                $ref: '#/components/schemas/FormInfo'
              type: array
            - type: 'null'
          title: Recentforms
        quickNotes:
          anyOf:
            - items:
                $ref: '#/components/schemas/QuickNoteInfo'
              type: array
            - type: 'null'
          title: Quicknotes
        tenant:
          anyOf:
            - $ref: '#/components/schemas/TenantContext'
            - type: 'null'
      type: object
      required:
        - patient
      title: PatientSummaryContext
      description: Complete patient context for AI generation.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    PatientBasicInfo:
      properties:
        firstName:
          anyOf:
            - type: string
            - type: 'null'
          title: Firstname
        lastName:
          anyOf:
            - type: string
            - type: 'null'
          title: Lastname
        dateOfBirth:
          anyOf:
            - type: string
            - type: 'null'
          title: Dateofbirth
        gender:
          anyOf:
            - type: string
            - type: 'null'
          title: Gender
        phoneNumber:
          anyOf:
            - type: string
            - type: 'null'
          title: Phonenumber
        email:
          anyOf:
            - type: string
            - type: 'null'
          title: Email
        createdDate:
          anyOf:
            - type: string
            - type: 'null'
          title: Createddate
      type: object
      title: PatientBasicInfo
      description: Basic patient information.
    AppointmentInfo:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        title:
          type: string
          title: Title
        start:
          type: string
          title: Start
        status:
          anyOf:
            - type: string
            - type: 'null'
          title: Status
        providerName:
          anyOf:
            - type: string
            - type: 'null'
          title: Providername
      type: object
      required:
        - title
        - start
      title: AppointmentInfo
      description: Appointment information.
    NoteInfo:
      properties:
        summary:
          anyOf:
            - type: string
            - type: 'null'
          title: Summary
        answers:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Answers
          default: []
        questions:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Questions
          default: []
        createdDate:
          type: string
          title: Createddate
      type: object
      required:
        - createdDate
      title: NoteInfo
      description: Note information.
    MeasurementInfo:
      properties:
        weight:
          anyOf:
            - type: number
            - type: 'null'
          title: Weight
        height:
          anyOf:
            - type: number
            - type: 'null'
          title: Height
        systolicBp:
          anyOf:
            - type: number
            - type: 'null'
          title: Systolicbp
        diastolicBp:
          anyOf:
            - type: number
            - type: 'null'
          title: Diastolicbp
        pulse:
          anyOf:
            - type: number
            - type: 'null'
          title: Pulse
        temperature:
          anyOf:
            - type: number
            - type: 'null'
          title: Temperature
        waistCircumference:
          anyOf:
            - type: number
            - type: 'null'
          title: Waistcircumference
        measurementDate:
          type: string
          title: Measurementdate
      type: object
      required:
        - measurementDate
      title: MeasurementInfo
      description: Measurement information.
    MedicationInfo:
      properties:
        name:
          type: string
          title: Name
        amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Amount
        unit:
          anyOf:
            - type: string
            - type: 'null'
          title: Unit
        frequency:
          anyOf:
            - type: string
            - type: 'null'
          title: Frequency
        quantity:
          anyOf:
            - type: number
            - type: 'null'
          title: Quantity
        comment:
          anyOf:
            - type: string
            - type: 'null'
          title: Comment
        administrationLocation:
          anyOf:
            - type: string
            - type: 'null'
          title: Administrationlocation
      type: object
      required:
        - name
      title: MedicationInfo
      description: Medication information.
    ChargeInfo:
      properties:
        id:
          type: string
          title: Id
        total:
          type: integer
          title: Total
        totalOutstanding:
          type: integer
          title: Totaloutstanding
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        status:
          type: string
          title: Status
        createdDate:
          anyOf:
            - type: string
            - type: 'null'
          title: Createddate
        items:
          anyOf:
            - items:
                $ref: '#/components/schemas/ChargeItemInfo'
              type: array
            - type: 'null'
          title: Items
        payments:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Payments
      type: object
      required:
        - id
        - total
        - totalOutstanding
        - status
      title: ChargeInfo
      description: Charge information.
    FormInfo:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        submissionDate:
          type: string
          title: Submissiondate
        isCompleted:
          type: boolean
          title: Iscompleted
      type: object
      required:
        - submissionDate
        - isCompleted
      title: FormInfo
      description: Form information.
    QuickNoteInfo:
      properties:
        note:
          type: string
          title: Note
        createdDate:
          type: string
          title: Createddate
        eventId:
          anyOf:
            - type: string
            - type: 'null'
          title: Eventid
      type: object
      required:
        - note
        - createdDate
      title: QuickNoteInfo
      description: Quick note information.
    TenantContext:
      properties:
        name:
          type: string
          title: Name
        clinicType:
          anyOf:
            - type: string
              enum:
                - DEFAULT
                - WEIGHT_LOSS
                - MED_SPA
            - type: 'null'
          title: Clinictype
        timezone:
          anyOf:
            - type: string
            - type: 'null'
          title: Timezone
      type: object
      required:
        - name
      title: TenantContext
      description: Tenant context information.
    ChargeItemInfo:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        quantity:
          type: number
          title: Quantity
        price:
          type: integer
          title: Price
        discountAmount:
          anyOf:
            - type: integer
            - type: 'null'
          title: Discountamount
      type: object
      required:
        - quantity
        - price
      title: ChargeItemInfo
      description: Charge item information.

````