---
title: "Close expired billing periods"
method: POST
path: "/admin/billing/periods/close-expired"
tags: ["Billing"]
---

# Close expired billing periods

`POST /admin/billing/periods/close-expired`

## Request

- Base URL: `https://api.crawlora.net/api/v1`
- URL: `https://api.crawlora.net/api/v1/admin/billing/periods/close-expired`
- Auth: API key in header `x-api-key`

Admin-only endpoint that scans expired user billing states, writes closed period ledgers, freezes revision 1 snapshots when missing, and then rolls each matched state into a new monthly period. The operation is idempotent across repeated runs because state rolling uses the previous user_id, period_key, and period_end as the update condition.

## Query parameters

- `limit` integer

## Headers

- `x-api-key` string, required

## Response `200`

Close expired periods summary

- BillingBillingPeriodCloseSummaryResponseDoc
  - `code` integer
  - `data` BillingBillingPeriodCloseSummaryDoc
    - `closed` integer
    - `errors` BillingBillingPeriodCloseErrorDoc[]
      - `error` string
      - `period_key` string
      - `user_id` string
    - `failed` integer
    - `scanned` integer
    - `skipped` integer
    - `snapshot_skipped` integer
    - `snapshots_created` integer
  - `msg` string

## Other responses

- `401`: Authentication required
- `403`: Admin plan required
- `500`: Internal server error

---

[API](https://skmtc.dev/crawlora/apis/crawlora-api.md) · [All operations](https://skmtc.dev/crawlora/apis/crawlora-api/llms.txt) · [OpenAPI document](https://skmtc.dev/crawlora/apis/crawlora-api/revisions/028417aa35bb?raw)
