> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.taigabilling.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.taigabilling.com/_mcp/server.

# Create patient refund

POST https://api.taigabilling.com/api/patient-refunds/v1
Content-Type: application/json

Creates a new patient refund record and returns the newly created PatientRefund object.
The allocations can describe whether the refund is being applied toward a specific service line,
claim, or billing provider.

Reference: https://docs.taigabilling.com/api-reference/patient-refunds-v-1/patient-refunds-v-1-create

## Authentication

- `Authorization` header (bearer token, required) — Send your Taiga API key as a Bearer token. Create and manage keys in the Taiga developer portal.

## Servers

- `https://api.taigabilling.com` (Production, default)
- `https://api-staging.taigabilling.com` (Staging)

## Request

### Body (application/json)

This endpoint expects an object.

- `amount_cents` (integer, required)
- `patient_external_id` (string, required)
- `allocations` (list of AllocationCreate, required)
- `refund_timestamp` (datetime, optional, nullable)
- `refund_note` (string, optional, nullable)
- `invoice` (string, optional, nullable)
- `refund_reason` (enum, optional, nullable)
  - Allowed values: `OVERCHARGED`, `ENTERED_IN_ERROR`, `TRANSFER`
- `allocation_restrictions` (list of AllocationRestrictionCreate, optional, nullable) — Optional restrictions constraining which claims this refund's credit can be auto-allocated to (e.g. billing provider NPI). Restriction (type, value) pairs must be unique. When omitted, the refund is unrestricted. Refunds created from an existing payment inherit that payment's restrictions instead.
- `raise_on_overdraft` (boolean, optional, nullable) — If true, the refund will be rejected if it would cause any account to be overdrafted. Defaults to false.

## Response

### 200

- `patient_refund_id` (string, required)
- `organization_id` (string, required)
- `refund_source` (enum, required)
  - Allowed values: `MANUAL_ENTRY`, `CHARGEBEE`, `SQUARE`, `STRIPE`, `ELATION`, `CEDAR`, `HEALTHIE`, `REALLOCATION`, `PHREESIA`, `INSTAMED`, `SHERPA_HEALTH`, `LOCKBOX`
- `amount_cents` (integer, required)
- `patient_external_id` (string, required)
- `allocations` (list of Allocation, required)
- `source_internal_id` (string, optional, nullable)
- `refund_timestamp` (datetime, optional, nullable)
- `refund_note` (string, optional, nullable)
- `invoice` (string, optional, nullable)
- `refund_reason` (enum, optional, nullable)
  - Allowed values: `OVERCHARGED`, `ENTERED_IN_ERROR`, `TRANSFER`

## Errors

### 403 Forbidden Error

- `PatientRefunds_v1_createRequestForbiddenError`
  - PatientRefundsV1CreateRequestForbiddenError0

### 404 Not Found Error

- `PatientRefunds_v1_createRequestNotFoundError`
  - PatientRefundsV1CreateRequestNotFoundError0

### 422 Unprocessable Entity Error

- `PatientRefunds_v1_createRequestUnprocessableEntityError`
  - PatientRefundsV1CreateRequestUnprocessableEntityError0
  - PatientRefundsV1CreateRequestUnprocessableEntityError1

## Types

### AllocationCreate

Allocations are portions of payments that are applied to specific resources, known as targets. Each allocation has and amount, defined in cents, and a target.

- `amount_cents` (integer, required)
- `target` (AllocationTargetCreate, required) — Allocation targets describe whether the portion of a payment is being applied toward a specific service line, claim, billing provider, or is unallocated.
- `earmark` (AllocationEarmarkType, optional, nullable) — If enabled for your organization, optional earmarking configuration for patient prepayments. When provided on unattributed allocations, holds the payment for future auto-allocation to matching encounters.

### AllocationRestrictionCreate

Constrains which claims a payment's credit can be auto-allocated to. Restrictions of the same restriction_type are OR'd together (any value may match); different restriction_types are AND'd (every type present must match). A payment with no restrictions can be allocated to any claim.

- `restriction_type` (enum, required) — The dimension along which a payment's auto-allocation can be restricted.
  - Allowed values: `billing_provider_npi`, `service_facility_id`
- `restriction_value` (string, required) — For billing_provider_npi, the NPI. For service_facility_id, the organization service facility ID.

### Allocation

- `amount_cents` (integer, required)
- `target` (AllocationTarget, required) — Allocation targets describe whether the portion of a payment is being applied toward a specific service line, claim, billing provider, or is unallocated.
- `allocation_id` (string, optional, nullable)
- `earmark` (BalanceEarmark, optional, nullable) — The active earmark created by this allocation, if any. Only present when this allocation created an earmark for future auto-allocation and the earmark has not been deleted.
- `allocated_on` (datetime, optional, nullable)

### PatientRefundsV1CreateRequestForbiddenError0

- `errorName` (enum, optional)
  - Allowed values: `UnprocessableEntityError`
- `content` (UnauthorizedErrorMessage, optional)

### PatientRefundsV1CreateRequestNotFoundError0

- `errorName` (enum, optional)
  - Allowed values: `UnprocessableEntityError`
- `content` (EntityNotFoundErrorMessage, optional)

### PatientRefundsV1CreateRequestUnprocessableEntityError0

- `errorName` (enum, optional)
  - Allowed values: `UnprocessableEntityError`
- `content` (UnprocessableEntityErrorMessage, optional)

### PatientRefundsV1CreateRequestUnprocessableEntityError1

thrown if `raise_on_overdraft` is true and the refund would cause any account to be overdrafted.

- `errorName` (enum, optional)
  - Allowed values: `ReallocationWouldOverdraftError`
- `content` (ReallocationWouldOverdraftErrorContent, optional) — Error content when a reallocation would cause an account to be overdrafted. Contains both legacy string messages and new structured allocation details.

### AllocationTargetCreate

Allocation targets describe whether the portion of a payment is being applied toward a specific service line, claim, billing provider, or is unallocated.

- AllocationTargetCreate0
- AllocationTargetCreate1
- AllocationTargetCreate2
- AllocationTargetCreate3
- AllocationTargetCreate4
- AllocationTargetCreate5

### AllocationEarmarkType

If enabled for your organization, defines how a patient prepayment allocation should be earmarked for future auto-allocation. Earmarks hold the allocation until a matching encounter is created, then attempt to allocate to that encounter. Only applicable for unattributed allocations.

- AllocationEarmarkType0
- AllocationEarmarkType1

### AllocationTarget

Allocation targets describe whether the portion of a payment is being applied toward a specific service line, claim, billing provider, or is unallocated.

- AllocationTarget0
- AllocationTarget1
- AllocationTarget2
- AllocationTarget3
- AllocationTarget4

### BalanceEarmark

Represents an active balance earmarking record that holds allocated funds for future auto-allocation. Earmarks are created when funds are allocated but should be held for a specific encounter or date of service. Only active (non-deleted) earmarks are returned.

- `id` (string, required)
- `target` (AllocationEarmarkType, required) — The target for this earmark (date of service or external encounter ID)
- `amount_earmarked_cents` (integer, optional, nullable) — The amount earmarked in cents for future allocation
- `created_by_allocation_id` (string, optional, nullable) — The ID of the allocation that created this earmark

### UnauthorizedErrorMessage

- `message` (string, optional, nullable)

### EntityNotFoundErrorMessage

- `id` (string, required)

### UnprocessableEntityErrorMessage

- `message` (string, optional, nullable)

### ReallocationWouldOverdraftErrorContent

Error content when a reallocation would cause an account to be overdrafted. Contains both legacy string messages and new structured allocation details.

- `messages` (list of string, required) — Legacy field containing error messages as strings. Deprecated - use allocation_details for structured data. Will be removed in a future version after frontend migration.
- `allocation_details` (list of AllocationOverdraftDetail, optional, nullable) — Structured details about which allocations would be overdrafted. Each detail includes entity type, ID, and error message for table display.

### AllocationTargetCreate0

- `type` (enum, required)
  - Allowed values: `service_line_by_id`
- `value` (string, optional)

### AllocationTargetCreate1

- `type` (enum, required)
  - Allowed values: `claim_by_id`
- `value` (string, optional)

### AllocationTargetCreate2

- `type` (enum, required)
  - Allowed values: `claim_by_encounter_external_id`
- `value` (string, optional)

### AllocationTargetCreate3

- `type` (enum, required)
  - Allowed values: `billing_provider_by_id`
- `value` (string, optional)

### AllocationTargetCreate4

- `appointment_id` (string, required)
- `patient_external_id` (string, required)
- `type` (enum, required)
  - Allowed values: `appointment_by_id_and_patient_external_id`

### AllocationTargetCreate5

- `type` (enum, required)
  - Allowed values: `unattributed`

### AllocationEarmarkType0

- `type` (enum, required)
  - Allowed values: `date_of_service`
- `value` (string, optional) — ISO 8601 date; formatted YYYY-MM-DD (i.e. 2012-02-01)

### AllocationEarmarkType1

- `type` (enum, required)
  - Allowed values: `external_encounter_id`
- `value` (string, optional)

### AllocationTarget0

- `claim_id` (string, required)
- `encounter_id` (string, required)
- `service_line_id` (string, required)
- `type` (enum, required)
  - Allowed values: `service_line`

### AllocationTarget1

- `claim_id` (string, required)
- `encounter_id` (string, required)
- `type` (enum, required)
  - Allowed values: `claim`

### AllocationTarget2

- `billing_provider_id` (string, required)
- `type` (enum, required)
  - Allowed values: `billing_provider_id`

### AllocationTarget3

- `appointment_id` (string, required)
- `patient_external_id` (string, required)
- `type` (enum, required)
  - Allowed values: `appointment`

### AllocationTarget4

- `type` (enum, required)
  - Allowed values: `unattributed`

### AllocationOverdraftDetail

Structured information about an allocation that would be overdrafted. Provides entity-specific details to display in a table format.

- `allocation_target` (AllocationTarget, required) — The allocation target that would be overdrafted (service_line, claim, unattributed, etc.)
- `patient_paid_amount_cents` (integer, required) — The amount in cents that the patient has currently paid toward this target (available to reallocate from)
- `current_balance_cents` (integer, required) — The current balance in cents on this entity before the reallocation
- `overage_amount_cents` (integer, required) — The amount in cents by which the reallocation would overdraft (always positive)
- `error_message` (string, required) — A descriptive error message explaining the overdraft condition

## Examples

**Request**

```json
{
  "amount_cents": 1,
  "patient_external_id": "string",
  "allocations": [
    {
      "amount_cents": 1,
      "target": {
        "type": "service_line_by_id"
      }
    }
  ]
}
```

**Response**

```json
{
  "patient_refund_id": "string",
  "organization_id": "string",
  "refund_source": "MANUAL_ENTRY",
  "amount_cents": 1,
  "patient_external_id": "string",
  "allocations": [
    {
      "amount_cents": 1,
      "target": {
        "claim_id": "string",
        "encounter_id": "string",
        "service_line_id": "string",
        "type": "service_line"
      },
      "allocation_id": "string",
      "earmark": {
        "id": "string",
        "target": {
          "type": "date_of_service",
          "value": "string"
        },
        "amount_earmarked_cents": 1,
        "created_by_allocation_id": "string"
      },
      "allocated_on": "2024-01-15T09:30:00Z"
    }
  ],
  "source_internal_id": "string",
  "refund_timestamp": "2024-01-15T09:30:00Z",
  "refund_note": "string",
  "invoice": "string",
  "refund_reason": "OVERCHARGED"
}
```

**SDK Code**

```python
import requests

url = "https://api.taigabilling.com/api/patient-refunds/v1"

payload = {
    "amount_cents": 1,
    "patient_external_id": "string",
    "allocations": [
        {
            "amount_cents": 1,
            "target": { "type": "service_line_by_id" }
        }
    ]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```