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

# Fees

> Understand product fees: how each fee links to a contract, product, rate card and rate, and how to list, filter, update or delete them.

A [fee](https://getlago.com/docs/v2/api-reference/fees/retrieve.md) is a line item that Lago computes from a [rate](https://getlago.com/docs/v2/guide/rate-cards/rates.md) applied to a [contract](https://getlago.com/docs/v2/guide/contracts/overview.md). Use the fee endpoints to trace an invoice amount back to its product, rate card and rate, or to manage fees that are not invoiced yet.

A fee can exist before it is attached to an invoice. In that case `lago_invoice_id` is `null`.

## What a fee links to

Each fee carries the identifiers of the objects that produced it:

| Field | Links to |
| - | - |
| `external_customer_id`, `lago_customer_id` | [Customer](https://getlago.com/docs/v2/guide/customers/customer-management.md) |
| `external_contract_id`, `lago_contract_id` | [Contract](https://getlago.com/docs/v2/guide/contracts/overview.md) |
| `product_code`, `product_category_code` | [Product](https://getlago.com/docs/v2/guide/product-catalog/products) and [category](https://getlago.com/docs/v2/guide/product-catalog/product-categories.md) |
| `product_filter_code`, `filters` | [Product filter](https://getlago.com/docs/v2/guide/product-catalog/product-filters.md) |
| `rate_card_code` | [Rate card](https://getlago.com/docs/v2/guide/rate-cards/overview.md) |
| `rate_code`, `lago_rate_override_id` | [Rate](https://getlago.com/docs/v2/guide/rate-cards/rates.md), or the contract [override](https://getlago.com/docs/v2/guide/contracts/overrides.md) that replaced it |
| `lago_true_up_fee_id`, `lago_true_up_parent_fee_id` | The related true-up fee, or the parent fee of a true-up fee |
| `event_transaction_id` | The event behind an advance-billed fee |

Related products, filters and rates can point to deleted catalog records for historical fees.

## Amounts

| Field | Meaning |
| - | - |
| `units` | Quantity, as a decimal string. |
| `unit_amount_cents`, `precise_unit_amount_cents` | Unit price, rounded and precise. |
| `amount_cents` | Fee amount. |
| `sub_total_excluding_taxes_amount_cents` | Amount after discounts and before tax. |
| `taxes_amount_cents` | Tax on the fee. |
| `total_amount_cents` | Amount including tax. |
| `from_datetime`, `to_datetime` | Billed period, when available. |
| `billing_timing` | `advance` or `arrears`, inherited from the rate card. |

### Example

In the [running example](https://getlago.com/docs/v2/guide/invoicing/overview.md#worked-example), 2,000 API calls at \$0.01 produce this fee on `api_calls_usd`:

| Field | Value |
| - | - |
| `product_code` | `api_calls_product` |
| `rate_card_code` | `api_calls_usd` |
| `rate_code` | `calls_standard` |
| `units` | `"2000.0"` |
| `amount_cents` | `2000` |
| `billing_timing` | `arrears` |

With a 20% tax assigned, `taxes_amount_cents` is `400` and `total_amount_cents` is `2400`.

## List and retrieve fees

> [tab] Dashboard
>
> 1. Open an invoice from **Invoices** or from the customer view; and
> 2. Review the fee lines in the invoice detail.

> [tab] API
>
> The list is cursor-paginated, newest first. Filters include `lago_invoice_id`, `external_customer_id`, `external_contract_id`, `product_code`, `rate_card_code`, `payment_status`, `currency`, `event_transaction_id`, and date bounds on creation, success, failure and refund.
>
> ```bash List the fees of a contract theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
>
> curl --location --request GET "$LAGO_URL/api/v2/fees?external_contract_id=contract_example&rate_card_code=api_calls_usd" \
>   --header "Authorization: Bearer $API_KEY"
> ```
>
> ```bash Retrieve a fee with its rate and taxes theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
> FEE_ID="__YOUR_FEE_ID__"
>
> curl --location --request GET "$LAGO_URL/api/v2/fees/$FEE_ID?expands[]=rate&expands[]=applied_taxes" \
>   --header "Authorization: Bearer $API_KEY"
> ```
>
> Supported expansions on retrieval: `applied_taxes`, `invoice`, `product`, `product_filter`, `rate_card`, `rate`, `contract` and `customer`. Only one expansion level is supported.

## Update a fee payment status

`payment_status` is the only editable field: `pending`, `succeeded`, `failed` or `refunded`. An invoiced fee cannot be updated and returns `422 invoiced_fee`.

```bash Set an uninvoiced fee as paid theme={"dark"}
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
FEE_ID="__YOUR_FEE_ID__"

curl --location --request PUT "$LAGO_URL/api/v2/fees/$FEE_ID" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "fee": {
      "payment_status": "succeeded"
    }
  }'
```

## Delete a fee

Only uninvoiced fees can be deleted. A fee already attached to an invoice returns `422 invoiced_fee`.

> [!WARNING]
>
> Deleting a fee removes a billable amount. It cannot be undone. Check the fee identifier and review the change before you run it in production.

```bash Delete an uninvoiced fee theme={"dark"}
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
FEE_ID="__YOUR_FEE_ID__"

curl --location --request DELETE "$LAGO_URL/api/v2/fees/$FEE_ID" \
  --header "Authorization: Bearer $API_KEY"
```

## Next steps

> [card] [Invoices](https://getlago.com/docs/v2/guide/invoicing/overview.md)
>
> How fees are grouped and totaled.

> [card] [Credit notes](https://getlago.com/docs/v2/guide/invoicing/credit-notes/overview.md)
>
> Credit a fee on a finalized invoice.

> [card] [List fees (API)](https://getlago.com/docs/v2/api-reference/fees/list.md)
>
> Filters and response schema.

> [card] [Update a fee (API)](https://getlago.com/docs/v2/api-reference/fees/update.md)
>
> Change the payment status of an uninvoiced fee.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.