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

# Extract ICD-10 codes from clinical notes

> Processes clinical notes (text or PDF) and returns ICD-10 code assessments with  confidence scores, detailed justifications, and discarded codes analysis. Supports optional AI model selection and tracking headers.




## OpenAPI

````yaml /openapi/openapi.yaml post /v1/codify
openapi: 3.0.3
info:
  title: Sofia Clinical Documentation API
  version: 1.0.0
  description: >
    Comprehensive AI-powered clinical documentation platform that includes
    ICD-10 medical coding, transcription management, AI conversation threads,
    and clinical note generation with support for various clinical templates
    (SOAP, BIRP, etc.).
servers:
  - url: https://{your-prod-endpoint}
    description: Production (provided after deployment)
  - url: https://{your-dev-endpoint}
    description: Development (provided upon request)
security:
  - bearerAuth: []
paths:
  /v1/codify:
    post:
      summary: Extract ICD-10 codes from clinical notes
      description: >
        Processes clinical notes (text or PDF) and returns ICD-10 code
        assessments with  confidence scores, detailed justifications, and
        discarded codes analysis. Supports optional AI model selection and
        tracking headers.
      operationId: codify
      parameters:
        - in: header
          name: x-doctor
          schema:
            type: string
          required: true
          description: Doctor identifier for tracking and auditing
          example: dr_123
        - in: header
          name: x-patient
          schema:
            type: string
          required: false
          description: Patient identifier for tracking and auditing
          example: pt_456
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CodifyRequest'
            examples:
              textInput:
                $ref: '#/components/examples/TextInputRequest'
              pdfInput:
                $ref: '#/components/examples/PdfInputRequest'
      responses:
        '200':
          description: Successfully extracted ICD-10 codes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CodifyResponse'
              examples:
                successfulCoding:
                  $ref: '#/components/examples/SuccessfulResponse'
        '400':
          description: Bad request (medical_note missing or invalid request format)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Bad Request
                details: medical_note is required
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Unauthorized
                details: Missing or invalid authentication token
        '413':
          description: >-
            Payload too large (medical_note exceeds 50KB or pdf_file exceeds 5MB
            decoded)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Payload Too Large
                details: Request payload exceeds the maximum allowed size
        '422':
          description: Unprocessable entity (invalid PDF structure or encoding)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Unprocessable Entity
                details: Invalid JSON Schema Draft-07
        '429':
          description: Too many requests (rate limit exceeded)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Too Many Requests
                details: Too many requests, please try again later
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Internal Server Error
                details: An unexpected error occurred during codification
        '503':
          description: Service unavailable (AI service temporarily unavailable)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Service Unavailable
                details: Service temporarily unavailable
        '504':
          description: Gateway timeout (processing exceeded 10-minute limit)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                error: Gateway Timeout
                details: Request timed out after 10 minutes
components:
  schemas:
    CodifyRequest:
      type: object
      required:
        - medical_note
      properties:
        medical_note:
          type: string
          description: (REQUIRED) Clinical text to process for ICD-10 coding (max 50KB)
          example: Patient with Type 2 Diabetes...
        pdf_file:
          type: object
          description: >-
            (OPTIONAL) PDF file object with base64 encoded data for additional
            context (max 5MB decoded)
          required:
            - type
            - source_type
            - data
            - mime_type
            - filename
          properties:
            type:
              type: string
              enum:
                - file
              description: Must be "file"
            source_type:
              type: string
              enum:
                - base64
              description: Must be "base64"
            data:
              type: string
              description: Base64 encoded PDF content
            mime_type:
              type: string
              enum:
                - application/pdf
              description: Must be "application/pdf"
            filename:
              type: string
              description: Original filename
              example: medical_report.pdf
        model:
          type: string
          description: Optional AI model quality level selection
          enum:
            - fast
            - balanced
            - high-quality
          example: balanced
    CodifyResponse:
      type: object
      required:
        - final_code_assessments
        - discarded_code_assessments
        - run_id
      properties:
        final_code_assessments:
          type: array
          description: Array of approved ICD-10 code assessments
          items:
            $ref: '#/components/schemas/CodeAssessment'
        discarded_code_assessments:
          type: array
          description: Array of considered but rejected code assessments
          items:
            $ref: '#/components/schemas/CodeAssessment'
        run_id:
          type: string
          description: Unique identifier (UUID) for this codification run
          example: 1ef8e0d4-7890-6b3c-8f90-abcdef123456
    Error:
      type: object
      required:
        - success
        - error
        - details
      properties:
        success:
          type: boolean
          enum:
            - false
          description: Always false for error responses
        error:
          type: string
          description: Error name/type
          example: Bad Request
        details:
          type: string
          description: Detailed error message
          example: Either medical_note or pdf_file must be provided
    CodeAssessment:
      type: object
      required:
        - code
        - description
        - justification
        - confidence_percent
      properties:
        code:
          type: string
          description: ICD-10 medical code
          example: E11.9
        description:
          type: string
          description: Medical description of the code
          example: Type 2 diabetes mellitus without complications
        justification:
          type: string
          description: AI reasoning for code selection
          example: >-
            The note documents Type 2 Diabetes without mention of decompensation
            or complications...
        confidence_percent:
          type: number
          format: float
          minimum: 0
          maximum: 100
          description: Confidence score (0-100)
          example: 95.2
  examples:
    TextInputRequest:
      summary: Medical note text input
      value:
        medical_note: >-
          Patient presents with Type 2 Diabetes Mellitus. Current medications:
          Metformin 500mg BID, Glipizide 5mg QD. Blood glucose levels stable. No
          complications noted. Patient reports good compliance with medications
          and diet. HbA1c: 6.8%.
        model: balanced
    PdfInputRequest:
      summary: PDF file input (base64 encoded)
      value:
        pdf_file:
          type: file
          source_type: base64
          data: JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9GaWx0ZXI...
          mime_type: application/pdf
          filename: medical_report.pdf
        model: high-quality
    SuccessfulResponse:
      summary: Successful ICD-10 coding result
      value:
        final_code_assessments:
          - code: E11.9
            description: Type 2 diabetes mellitus without complications
            justification: >-
              The note documents Type 2 Diabetes without mention of
              decompensation or complications; corresponds to E11.9 (DM2 without
              complications). The stable blood glucose levels and HbA1c of 6.8%
              indicate controlled diabetes with no evidence of complications.
            confidence_percent: 95.2
          - code: Z79.84
            description: Long term (current) use of oral hypoglycemic drugs
            justification: >-
              The patient uses metformin and glipizide chronically; both are
              oral antidiabetic drugs, supporting long term use of oral
              hypoglycemic drugs.
            confidence_percent: 98.1
        discarded_code_assessments:
          - code: E11.65
            description: Type 2 diabetes mellitus with hyperglycemia
            justification: >-
              Discarded because blood glucose levels are stable and controlled
              (120-140 mg/dL fasting), not indicating hyperglycemia.
            confidence_percent: 12.3
        run_id: 1ef8e0d4-7890-6b3c-8f90-abcdef123456
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Bearer token for API authentication

````