# calendar.deadline

Calculate a deadline in local business days or hours and trace skipped dates.

- REST: `POST https://api.kanagu.dev/v1/calendar/deadline`
- MCP tool: `calendar.deadline` at https://api.kanagu.dev/mcp
- Price: $0.001 USD per successful call. Trial: 10 calls per IP per UTC day without a key, shared by REST and MCP.
- Auth: `Authorization: Bearer <key>` for billed calls. Retries: reuse `Idempotency-Key`.

## Request body

- `country` ("AD" | "AE" | "AG" | "AI" | "AL" | "AM" | … (207 values), required): Country or territory code. GB defaults to England and Wales.
- `subdivision` (string (max 24 chars)): date-holidays subdivision code, e.g. CA or US-CA, BY or DE-BY, SCT or GB-SCT.
- `start` (string (date-time), required): Start instant with a UTC offset.
- `timezone` (string (max 64 chars), required): IANA time zone, e.g. America/New_York.
- `cutoff` (string, required): Daily closing time in the selected time zone (HH:mm).
- `weekend` (array of integer (1 to 7)): Closed weekdays, expressed as ISO numbers (1 = Monday).
- `closures` (array of string (date)): Additional closed dates in the selected time zone.

Then exactly one of these shapes:

1. With days:

- `days` (integer (0 to 4000), required): Business days after the first open day before cutoff. Zero uses that day's cutoff.

2. With hours, opensAt:

- `hours` (number (0 to 8760), required): Elapsed hours during business windows, rounded to the nearest millisecond.
- `opensAt` (string): Daily opening time (HH:mm), before cutoff.

## Response

- `due` (string (date-time), required): Deadline as a UTC instant.
- `skipped` (array of object, required)
- `skipped[].date` (string (date), required)
- `skipped[].reasons` (array of "weekend" | "public_holiday" | "custom_closure" | "cutoff_passed", required)

## Example

```sh
curl https://api.kanagu.dev/v1/calendar/deadline \
  -H "Authorization: Bearer $KANAGU_KEY" \
  -H "Content-Type: application/json" \
  -d '{"country":"US","subdivision":"US-NY","start":"2026-11-25T21:30:00Z","hours":2,"timezone":"America/New_York","cutoff":"17:00","closures":["2026-11-27"]}'
```

```ts
const res = await fetch("https://api.kanagu.dev/v1/calendar/deadline", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KANAGU_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "country": "US",
    "subdivision": "US-NY",
    "start": "2026-11-25T21:30:00Z",
    "hours": 2,
    "timezone": "America/New_York",
    "cutoff": "17:00",
    "closures": [
      "2026-11-27"
    ]
  }),
});
if (!res.ok) throw new Error((await res.json()).error.message);
const result = await res.json();
```

## Errors

JSON `{"error":{"code","message"}}`.

- 400 `invalid_input`: The body does not match the request schema. The message names each field.
- 400 `invalid_json`: The body is missing or is not valid JSON.
- 400 `invalid_idempotency_key`: Idempotency-Key must be 1–128 visible ASCII characters.
- 401 `invalid_api_key`: The Bearer key is missing, malformed, invalid or inactive.
- 402 `free_allowance_exhausted`: This month's free usage is used up and the account has no subscription. Subscribe from the dashboard, or wait for the next UTC month; Retry-After gives the seconds left.
- 404 `not_found`: No operation at this path.
- 409 `idempotency_conflict`: The Idempotency-Key was already used with a different body.
- 413 `payload_too_large`: JSON bodies may be at most 64 KiB.
- 429 `trial_limit`: The anonymous trial allows 10 calls per IP per UTC day, shared by REST and MCP. Retry-After gives the seconds left.
- 500 `internal_error`: The call failed on our side. It is not billed; retry with the same Idempotency-Key.

## JSON Schema

Request:
```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "country": {
          "type": "string",
          "enum": [
            "AD",
            "AE",
            "AG",
            "AI",
            "AL",
            "AM",
            "AO",
            "AR",
            "AS",
            "AT",
            "AU",
            "AW",
            "AX",
            "AZ",
            "BA",
            "BB",
            "BD",
            "BE",
            "BF",
            "BG",
            "BH",
            "BI",
            "BJ",
            "BL",
            "BM",
            "BN",
            "BO",
            "BQ",
            "BR",
            "BS",
            "BW",
            "BY",
            "BZ",
            "CA",
            "CC",
            "CD",
            "CF",
            "CG",
            "CH",
            "CI",
            "CK",
            "CL",
            "CM",
            "CN",
            "CO",
            "CR",
            "CU",
            "CV",
            "CW",
            "CX",
            "CY",
            "CZ",
            "DE",
            "DJ",
            "DK",
            "DM",
            "DO",
            "DZ",
            "EC",
            "EE",
            "EG",
            "EH",
            "ER",
            "ES",
            "ET",
            "FI",
            "FJ",
            "FO",
            "FR",
            "GA",
            "GB",
            "GD",
            "GE",
            "GF",
            "GG",
            "GH",
            "GI",
            "GL",
            "GM",
            "GN",
            "GP",
            "GQ",
            "GR",
            "GT",
            "GU",
            "GW",
            "GY",
            "HK",
            "HN",
            "HR",
            "HT",
            "HU",
            "IC",
            "ID",
            "IE",
            "IL",
            "IM",
            "IN",
            "IR",
            "IS",
            "IT",
            "JE",
            "JM",
            "JP",
            "KE",
            "KM",
            "KN",
            "KR",
            "KY",
            "KZ",
            "LC",
            "LI",
            "LK",
            "LR",
            "LS",
            "LT",
            "LU",
            "LV",
            "LY",
            "MA",
            "MC",
            "MD",
            "ME",
            "MF",
            "MG",
            "MK",
            "ML",
            "MQ",
            "MR",
            "MS",
            "MT",
            "MU",
            "MW",
            "MX",
            "MY",
            "MZ",
            "NA",
            "NC",
            "NE",
            "NF",
            "NG",
            "NI",
            "NL",
            "NO",
            "NZ",
            "PA",
            "PE",
            "PF",
            "PH",
            "PK",
            "PL",
            "PM",
            "PR",
            "PT",
            "PY",
            "RE",
            "RO",
            "RS",
            "RU",
            "RW",
            "SA",
            "SC",
            "SD",
            "SE",
            "SG",
            "SH",
            "SI",
            "SJ",
            "SK",
            "SL",
            "SM",
            "SN",
            "SO",
            "SR",
            "SS",
            "ST",
            "SV",
            "SX",
            "SZ",
            "TC",
            "TD",
            "TG",
            "TH",
            "TN",
            "TO",
            "TR",
            "TT",
            "TW",
            "TZ",
            "UA",
            "UG",
            "US",
            "UY",
            "UZ",
            "VA",
            "VC",
            "VE",
            "VG",
            "VI",
            "VN",
            "VU",
            "WF",
            "XK",
            "YT",
            "ZA",
            "ZM",
            "ZW"
          ],
          "description": "Country or territory code. GB defaults to England and Wales."
        },
        "subdivision": {
          "description": "date-holidays subdivision code, e.g. CA or US-CA, BY or DE-BY, SCT or GB-SCT.",
          "type": "string",
          "maxLength": 24,
          "pattern": "^[A-Z0-9]+(?:-[A-Z0-9]+){0,2}$"
        },
        "start": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
          "description": "Start instant with a UTC offset."
        },
        "timezone": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "description": "IANA time zone, e.g. America/New_York."
        },
        "cutoff": {
          "type": "string",
          "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$",
          "description": "Daily closing time in the selected time zone (HH:mm)."
        },
        "weekend": {
          "default": [
            6,
            7
          ],
          "description": "Closed weekdays, expressed as ISO numbers (1 = Monday).",
          "maxItems": 6,
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 7
          }
        },
        "closures": {
          "default": [],
          "description": "Additional closed dates in the selected time zone.",
          "maxItems": 366,
          "type": "array",
          "items": {
            "type": "string",
            "format": "date",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
          }
        },
        "days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4000,
          "description": "Business days after the first open day before cutoff. Zero uses that day's cutoff."
        }
      },
      "required": [
        "country",
        "start",
        "timezone",
        "cutoff",
        "days"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "country": {
          "type": "string",
          "enum": [
            "AD",
            "AE",
            "AG",
            "AI",
            "AL",
            "AM",
            "AO",
            "AR",
            "AS",
            "AT",
            "AU",
            "AW",
            "AX",
            "AZ",
            "BA",
            "BB",
            "BD",
            "BE",
            "BF",
            "BG",
            "BH",
            "BI",
            "BJ",
            "BL",
            "BM",
            "BN",
            "BO",
            "BQ",
            "BR",
            "BS",
            "BW",
            "BY",
            "BZ",
            "CA",
            "CC",
            "CD",
            "CF",
            "CG",
            "CH",
            "CI",
            "CK",
            "CL",
            "CM",
            "CN",
            "CO",
            "CR",
            "CU",
            "CV",
            "CW",
            "CX",
            "CY",
            "CZ",
            "DE",
            "DJ",
            "DK",
            "DM",
            "DO",
            "DZ",
            "EC",
            "EE",
            "EG",
            "EH",
            "ER",
            "ES",
            "ET",
            "FI",
            "FJ",
            "FO",
            "FR",
            "GA",
            "GB",
            "GD",
            "GE",
            "GF",
            "GG",
            "GH",
            "GI",
            "GL",
            "GM",
            "GN",
            "GP",
            "GQ",
            "GR",
            "GT",
            "GU",
            "GW",
            "GY",
            "HK",
            "HN",
            "HR",
            "HT",
            "HU",
            "IC",
            "ID",
            "IE",
            "IL",
            "IM",
            "IN",
            "IR",
            "IS",
            "IT",
            "JE",
            "JM",
            "JP",
            "KE",
            "KM",
            "KN",
            "KR",
            "KY",
            "KZ",
            "LC",
            "LI",
            "LK",
            "LR",
            "LS",
            "LT",
            "LU",
            "LV",
            "LY",
            "MA",
            "MC",
            "MD",
            "ME",
            "MF",
            "MG",
            "MK",
            "ML",
            "MQ",
            "MR",
            "MS",
            "MT",
            "MU",
            "MW",
            "MX",
            "MY",
            "MZ",
            "NA",
            "NC",
            "NE",
            "NF",
            "NG",
            "NI",
            "NL",
            "NO",
            "NZ",
            "PA",
            "PE",
            "PF",
            "PH",
            "PK",
            "PL",
            "PM",
            "PR",
            "PT",
            "PY",
            "RE",
            "RO",
            "RS",
            "RU",
            "RW",
            "SA",
            "SC",
            "SD",
            "SE",
            "SG",
            "SH",
            "SI",
            "SJ",
            "SK",
            "SL",
            "SM",
            "SN",
            "SO",
            "SR",
            "SS",
            "ST",
            "SV",
            "SX",
            "SZ",
            "TC",
            "TD",
            "TG",
            "TH",
            "TN",
            "TO",
            "TR",
            "TT",
            "TW",
            "TZ",
            "UA",
            "UG",
            "US",
            "UY",
            "UZ",
            "VA",
            "VC",
            "VE",
            "VG",
            "VI",
            "VN",
            "VU",
            "WF",
            "XK",
            "YT",
            "ZA",
            "ZM",
            "ZW"
          ],
          "description": "Country or territory code. GB defaults to England and Wales."
        },
        "subdivision": {
          "description": "date-holidays subdivision code, e.g. CA or US-CA, BY or DE-BY, SCT or GB-SCT.",
          "type": "string",
          "maxLength": 24,
          "pattern": "^[A-Z0-9]+(?:-[A-Z0-9]+){0,2}$"
        },
        "start": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
          "description": "Start instant with a UTC offset."
        },
        "timezone": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "description": "IANA time zone, e.g. America/New_York."
        },
        "cutoff": {
          "type": "string",
          "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$",
          "description": "Daily closing time in the selected time zone (HH:mm)."
        },
        "weekend": {
          "default": [
            6,
            7
          ],
          "description": "Closed weekdays, expressed as ISO numbers (1 = Monday).",
          "maxItems": 6,
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 7
          }
        },
        "closures": {
          "default": [],
          "description": "Additional closed dates in the selected time zone.",
          "maxItems": 366,
          "type": "array",
          "items": {
            "type": "string",
            "format": "date",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
          }
        },
        "hours": {
          "type": "number",
          "minimum": 0,
          "maximum": 8760,
          "description": "Elapsed hours during business windows, rounded to the nearest millisecond."
        },
        "opensAt": {
          "default": "09:00",
          "description": "Daily opening time (HH:mm), before cutoff.",
          "type": "string",
          "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
        }
      },
      "required": [
        "country",
        "start",
        "timezone",
        "cutoff",
        "hours"
      ],
      "additionalProperties": false
    }
  ],
  "examples": [
    {
      "country": "US",
      "subdivision": "US-NY",
      "start": "2026-11-25T21:30:00Z",
      "hours": 2,
      "timezone": "America/New_York",
      "cutoff": "17:00",
      "closures": [
        "2026-11-27"
      ]
    }
  ],
  "type": "object"
}
```

Response:
```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "due": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
      "description": "Deadline as a UTC instant."
    },
    "skipped": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "weekend",
                "public_holiday",
                "custom_closure",
                "cutoff_passed"
              ]
            }
          }
        },
        "required": [
          "date",
          "reasons"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "due",
    "skipped"
  ],
  "additionalProperties": false
}
```
