---
title: "Monthly Billing Cycle"
method: POST
path: "/api/tasks/monthly-billing-cycle"
tags: ["Tasks", "Tasks"]
---

# Monthly Billing Cycle

`POST /api/tasks/monthly-billing-cycle`

M-1 + M-4: monthly invoice generation with weekend/holiday adjustment.

BILLING_RULES.md Section 3:
  - Invoice date: 26th of M+1 calendar-basis
  - Weekend/holiday adjustment: next business day

The Cloud Scheduler job runs DAILY (cron under our control). Each run:
  1. Calls invoice_date_for_billing_cycle(today) to decide whether
     today is the canonical invoice date (M-4 logic encapsulated there).
  2. If not the invoice day, no-ops and returns success.
  3. If it IS the invoice day, calls
     InvoiceGenerator.generate_monthly_invoices(today).

Idempotent: the generator skips any attribution row already invoiced.
Two firings on the same canonical day will not double-charge.

## Headers

- `x-cloudscheduler-secret` string, nullable
- `x-scheduler-secret` string, nullable
- `authorization` string, nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `401` — Unauthorized
- `422` — Validation Error
- `500` — Internal Server Error

---

[API](https://skmtc.dev/primetime/apis/primetime-media-api.md) · [All operations](https://skmtc.dev/primetime/apis/primetime-media-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/primetime/primetime-media-api/revisions/9da9a9f64e11/schema)
