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

# Upload document

> Uploads a clinical PDF or image for OCR and emits an unstructured_report or clinical_note event log.

<CodeGroup>
  ```python Python theme={null}
  olira.upload_document(
      patient_id: str,
      path: str | Path,
      log_type: DocumentLogType | str,
      timestamp: datetime,
      idempotency_key: str,
      document_type: str | None = None,
      note_type: str | None = None,
      source: Any | None = None,
      content_type: str | None = None,
      wait: bool = False,
      wait_timeout_s: float = 600.0,
  ) -> DocumentHandle
  ```

  ```csharp C# theme={null}
  client.UploadDocument(
      string patientId,
      string | Path path,
      DocumentLogType | string logType,
      DateTimeOffset timestamp,
      string idempotencyKey,
      string? documentType = null,
      string? noteType = null,
      Any? source = null,
      string? contentType = null,
      bool wait = false,
      double waitTimeoutS = 600.0,
  )  // -> DocumentHandle
  ```
</CodeGroup>

**Requires scope:** `sdk:event-log`

The SDK requests a presigned URL, PUTs the binary (with matching Content-Type), commits, and returns a DocumentHandle — call wait() or poll() until log\_emitted or ocr\_failed. You choose log\_type and labels; the platform does not infer them from the file. See the resource ingestion guide for supported formats and the textize/OCR pipeline.

## Parameters

<ParamField body="patient_id" type="str" required>
  Olira patient id that owns the document.
</ParamField>

<ParamField body="path" type="str | Path" required>
  Local filesystem path to a PDF or supported image (max 100 MB).
</ParamField>

<ParamField body="log_type" type="DocumentLogType | str" required>
  "unstructured\_report" (requires document\_type) or "clinical\_note" (requires note\_type + source).
</ParamField>

<ParamField body="timestamp" type="datetime" required>
  Clinical timestamp for the emitted event log (timezone-aware preferred).
</ParamField>

<ParamField body="idempotency_key" type="str" required>
  Stable key for this document; reusing after leaving pending\_upload returns 409.
</ParamField>

<ParamField body="document_type" type="str | None">
  Required for unstructured\_report. Catalog enum (e.g. clinical\_note, lab\_report, discharge\_summary).
</ParamField>

<ParamField body="note_type" type="str | None">
  Required for clinical\_note. Catalog enum (e.g. progress\_note, history\_and\_physical).
</ParamField>

<ParamField body="source" type="Any | None">
  Required for clinical\_note (e.g. ehr\_integration, manual\_entry, or structured Source).
</ParamField>

<ParamField body="content_type" type="str | None">
  MIME type override; defaults from filename (application/pdf, image/png, …).
</ParamField>

<ParamField body="wait" type="bool" default="False">
  When True, block until a terminal status before returning the handle.
</ParamField>

<ParamField body="wait_timeout_s" type="float" default="600.0">
  Timeout for wait=True / handle.wait().
</ParamField>

## Returns

`DocumentHandle` — Poll/wait handle; .document is the current DocumentResource snapshot.

<ResponseField name="document_id" type="str">
  Document resource id.
</ResponseField>

<ResponseField name="document.status" type="DocumentStatus">
  pending\_upload | uploaded | ocr\_running | ocr\_complete | log\_emitted | ocr\_failed.
</ResponseField>

<ResponseField name="document.event_log_id" type="str | None">
  Emitted event log id when status is log\_emitted.
</ResponseField>

<ResponseField name="document.ocr_page_count" type="int | None">
  Pages processed by OCR when available.
</ResponseField>

<ResponseField name="document.error" type="str | None">
  Failure detail when status is ocr\_failed.
</ResponseField>

<Note>
  Guide: /send-data/resource-ingestion.
</Note>

<Note>
  On the presigned PUT, send Content-Type matching the upload-url request; omit the SDK Authorization header.
</Note>

<Note>
  There is no human confirmation on this path — commit starts OCR immediately.
</Note>

## Raises

| Exception         | When                                                                                                                  |
| ----------------- | --------------------------------------------------------------------------------------------------------------------- |
| `ValidationError` | File missing/empty, or required document\_type / note\_type+source omitted for the chosen log\_type.                  |
| `AuthError`       | HTTP 401 or 403 — invalid API key or insufficient OAuth scope for this endpoint.                                      |
| `ServerError`     | HTTP 409 (e.g. conflicting external identifier) or repeated 5xx after retries; includes status\_code when applicable. |
| `RateLimitError`  | HTTP 429 — rate limited; check retry\_after (seconds).                                                                |
| `NetworkError`    | Connection timeout, DNS failure, or read error after retries.                                                         |

<RequestExample>
  ```python Python theme={null}
  from datetime import datetime, timezone
  from olira import OliraClient

  client = OliraClient(api_key="YOUR_API_KEY")
  handle = client.upload_document(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      path="progress-note.pdf",
      log_type="unstructured_report",
      document_type="clinical_note",
      timestamp=datetime(2026, 7, 15, 14, 30, tzinfo=timezone.utc),
      idempotency_key="emr-note-88421",
  )
  doc = handle.wait()
  ```

  ```csharp C# theme={null}
  using Olira;

  using var client = new OliraClient(apiKey: "YOUR_API_KEY");
  var handle = client.UploadDocument(
      patientId: "8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      path: "progress-note.pdf",
      logType: DocumentLogType.UnstructuredReport,
      documentType: "clinical_note",
      timestamp: new DateTimeOffset(2026, 7, 15, 14, 30, 0, TimeSpan.Zero),
      idempotencyKey: "emr-note-88421");
  var doc = handle.Wait();
  ```

  ```http HTTP theme={null}
  POST /v1/documents:upload-url
  Authorization: Bearer YOUR_API_KEY
  Content-Type: application/json

  {
    "patient_id": "8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
    "content_type": "application/pdf",
    "content_sha256": "<sha256 of file>",
    "size_bytes": 48210,
    "filename": "progress-note.pdf",
    "log_type": "unstructured_report",
    "document_type": "clinical_note",
    "timestamp": "2026-07-15T14:30:00+00:00",
    "idempotency_key": "emr-note-88421"
  }

  # Then PUT upload_url with Content-Type: application/pdf (no Authorization),
  # then POST /v1/documents/{document_id}:commit
  ```
</RequestExample>

<ResponseExample>
  ```python 200 theme={null}
  DocumentResource(
      document_id="doc-001",
      status="log_emitted",
      filename="progress-note.pdf",
      event_log_id="…",
      ocr_page_count=3,
  )
  ```

  ```json 401 theme={null}
  {
    "error": true,
    "status_code": 401,
    "error_type": "authentication_error",
    "message": "Could not validate credentials",
    "details": [
      {
        "type": "authentication_error",
        "message": "Could not validate credentials"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 403 theme={null}
  {
    "error": true,
    "status_code": 403,
    "error_type": "authorization_error",
    "message": "Insufficient OAuth scope for this endpoint",
    "details": [
      {
        "type": "authorization_error",
        "message": "Insufficient OAuth scope for this endpoint"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 404 theme={null}
  {
    "error": true,
    "status_code": 404,
    "error_type": "not_found_error",
    "message": "Patient not found",
    "details": [
      {
        "type": "not_found_error",
        "message": "Patient not found"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 422 theme={null}
  {
    "error": true,
    "status_code": 422,
    "error_type": "validation_error",
    "message": "Request validation failed (1 error)",
    "details": [
      {
        "type": "missing",
        "message": "Field required",
        "field": "patient_id",
        "location": ["body", "patient_id"],
        "input_value": null
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 429 theme={null}
  {
    "error": true,
    "status_code": 429,
    "error_type": "server_error",
    "message": "Rate limit exceeded",
    "details": [
      {
        "type": "rate_limit",
        "message": "Too many requests; retry after backoff"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 500 theme={null}
  {
    "error": true,
    "status_code": 500,
    "error_type": "internal_server_error",
    "message": "An internal server error occurred",
    "details": [
      {
        "type": "internal_server_error",
        "message": "An unexpected error occurred while processing your request"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```
</ResponseExample>
