{
  "openapi": "3.0.1",
  "info": {
    "title": "Krasyn Developer API",
    "description": "Krasyn public AI capabilities — ambient scribe note generation, medical coding suggestion, prior authorization letter drafting, and natural-language code search. Authenticate with: Authorization: Bearer krasyn_live_<key>",
    "contact": {
      "name": "Krasyn Health",
      "email": "info@krasyn.com"
    },
    "version": "v1"
  },
  "paths": {
    "/api/developer/keys": {
      "post": {
        "tags": [
          "ApiKey"
        ],
        "summary": "Create a new API key for the authenticated user's org.\r\nThe plaintext key is returned ONCE. Store it securely — it cannot be retrieved again.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ApiKeyCreateRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/ApiKeyCreateRequest"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/ApiKeyCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyCreateResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "ApiKey"
        ],
        "summary": "List all active API keys for the authenticated user's org.\r\nNever returns full key values — only prefix, scopes, and metadata.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ApiKeyListItem"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/api/developer/keys/{prefix}": {
      "delete": {
        "tags": [
          "ApiKey"
        ],
        "summary": "Revoke an API key by its prefix (first 8 characters, shown in the key list).",
        "parameters": [
          {
            "name": "prefix",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/scribe/generate": {
      "post": {
        "tags": [
          "PublicApi"
        ],
        "summary": "Generate a clinical note from an audio transcript.\r\nRequires scope: `scribe`.\r\n            \r\nRequest body: `{ audioTranscript: string, patientContext?: string }`\r\nResponse: `{ note: string, tokens: int }`",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScribeGenerateRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/ScribeGenerateRequest"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/ScribeGenerateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScribeGenerateResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable"
          }
        }
      }
    },
    "/api/v1/coder/suggest": {
      "post": {
        "tags": [
          "PublicApi"
        ],
        "summary": "Suggest ICD-10 and CPT codes from a clinical note.\r\nRequires scope: `coder`.\r\n            \r\nRequest body: `{ noteText: string }`\r\nResponse: `{ icdCodes: [{code, description}], cptCodes: [{code, description}] }`",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CoderSuggestRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/CoderSuggestRequest"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/CoderSuggestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CoderSuggestResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable"
          }
        }
      }
    },
    "/api/v1/priorauth/generate": {
      "post": {
        "tags": [
          "PublicApi"
        ],
        "summary": "Generate a prior authorization letter.\r\nRequires scope: `priorauth`.\r\n            \r\nRequest body: `{ patientSummary, payer, treatment, diagnosisCodes[] }`\r\nResponse: `{ letter: string }`",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublicPriorAuthRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/PublicPriorAuthRequest"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/PublicPriorAuthRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicPriorAuthResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable"
          }
        }
      }
    },
    "/api/v1/codes/search": {
      "get": {
        "tags": [
          "PublicApi"
        ],
        "summary": "Search medical codes using natural language.\r\nRequires scope: `codes`.\r\n            \r\nQuery params: `q` (required), `type` (icd10|cpt|hcpcs, optional), `limit` (max 20)\r\nResponse: `{ results: [{code, type, desc, rationale}], answer: string }`",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CodesSearchResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiKeyCreateRequest": {
        "type": "object",
        "properties": {
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ApiKeyCreateResponse": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "nullable": true
          },
          "keyPrefix": {
            "type": "string",
            "nullable": true
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "rateLimit": {
            "type": "integer",
            "format": "int32"
          },
          "warning": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ApiKeyListItem": {
        "type": "object",
        "properties": {
          "keyPrefix": {
            "type": "string",
            "nullable": true
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "rateLimit": {
            "type": "integer",
            "format": "int32"
          }
        },
        "additionalProperties": false
      },
      "CodeItem": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "nullable": true
          },
          "description": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CodeSearchResult": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "nullable": true
          },
          "type": {
            "type": "string",
            "nullable": true
          },
          "desc": {
            "type": "string",
            "nullable": true
          },
          "rationale": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CoderSuggestRequest": {
        "type": "object",
        "properties": {
          "noteText": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CoderSuggestResponse": {
        "type": "object",
        "properties": {
          "icdCodes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CodeItem"
            },
            "nullable": true
          },
          "cptCodes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CodeItem"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CodesSearchResponse": {
        "type": "object",
        "properties": {
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CodeSearchResult"
            },
            "nullable": true
          },
          "answer": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": { }
      },
      "PublicPriorAuthRequest": {
        "type": "object",
        "properties": {
          "patientSummary": {
            "type": "string",
            "nullable": true
          },
          "payer": {
            "type": "string",
            "nullable": true
          },
          "treatment": {
            "type": "string",
            "nullable": true
          },
          "diagnosisCodes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "PublicPriorAuthResponse": {
        "type": "object",
        "properties": {
          "letter": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ScribeGenerateRequest": {
        "type": "object",
        "properties": {
          "audioTranscript": {
            "type": "string",
            "nullable": true
          },
          "patientContext": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ScribeGenerateResponse": {
        "type": "object",
        "properties": {
          "note": {
            "type": "string",
            "nullable": true
          },
          "tokens": {
            "type": "integer",
            "format": "int32"
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "description": "API key for inbound HL7/lab connector endpoints (matches IntegrationCredential HL7_INBOUND_API_KEY)",
        "name": "X-API-Key",
        "in": "header"
      },
      "DeveloperApiKey": {
        "type": "apiKey",
        "description": "Krasyn Developer API key. Format: Bearer krasyn_live_<key>. Generate keys at app.krasyn.com/settings/api.",
        "name": "Authorization",
        "in": "header"
      }
    }
  }
}