# xbrl.history

Trace every SEC EDGAR filing version of one XBRL concept by exact fiscal dates and unit, including unchanged repeats and source filings.

- REST: `POST https://api.kanagu.dev/v1/xbrl/history`
- MCP tool: `xbrl.history` at https://api.kanagu.dev/mcp
- Price: $0.08 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

- `cik` (string | integer (1 to 9999999999), required): SEC Central Index Key, with or without leading zeros.
- `concept` (object, required)
- `concept.taxonomy` (string, required): SEC taxonomy, e.g. us-gaap.
- `concept.tag` (string, required): Case-sensitive XBRL concept tag.

## Response

- `cik` (string, required): Ten-digit SEC Central Index Key.
- `source` (string (uri), required): SEC EDGAR XBRL API documentation.
- `concept` (object, required)
- `concept.taxonomy` (string, required): SEC taxonomy, e.g. us-gaap.
- `concept.tag` (string, required): Case-sensitive XBRL concept tag.
- `series` (array of object, required)
- `series[].period` (object, required)
- `series[].period.start` (string (date)): First day of a duration fact. Omit for an instant fact.
- `series[].period.end` (string (date), required): Last day of a duration fact or date of an instant fact.
- `series[].unit` (string, required)
- `series[].versions` (array of object, required)

## Example

```sh
curl https://api.kanagu.dev/v1/xbrl/history \
  -H "Authorization: Bearer $KANAGU_KEY" \
  -H "Content-Type: application/json" \
  -d '{"cik":"0000789019","concept":{"taxonomy":"us-gaap","tag":"NetIncomeLoss"}}'
```

```ts
const res = await fetch("https://api.kanagu.dev/v1/xbrl/history", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KANAGU_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "cik": "0000789019",
    "concept": {
      "taxonomy": "us-gaap",
      "tag": "NetIncomeLoss"
    }
  }),
});
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",
  "type": "object",
  "properties": {
    "cik": {
      "description": "SEC Central Index Key, with or without leading zeros.",
      "anyOf": [
        {
          "type": "string",
          "pattern": "^\\d{1,10}$"
        },
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 9999999999
        }
      ]
    },
    "concept": {
      "type": "object",
      "properties": {
        "taxonomy": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,19}$",
          "description": "SEC taxonomy, e.g. us-gaap."
        },
        "tag": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,254}$",
          "description": "Case-sensitive XBRL concept tag."
        }
      },
      "required": [
        "taxonomy",
        "tag"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "cik",
    "concept"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "cik": "0000789019",
      "concept": {
        "taxonomy": "us-gaap",
        "tag": "NetIncomeLoss"
      }
    }
  ]
}
```

Response:
```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "cik": {
      "type": "string",
      "description": "Ten-digit SEC Central Index Key."
    },
    "source": {
      "type": "string",
      "format": "uri",
      "description": "SEC EDGAR XBRL API documentation."
    },
    "concept": {
      "type": "object",
      "properties": {
        "taxonomy": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,19}$",
          "description": "SEC taxonomy, e.g. us-gaap."
        },
        "tag": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,254}$",
          "description": "Case-sensitive XBRL concept tag."
        }
      },
      "required": [
        "taxonomy",
        "tag"
      ],
      "additionalProperties": false
    },
    "series": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "period": {
            "type": "object",
            "properties": {
              "start": {
                "description": "First day of a duration fact. Omit for an instant fact.",
                "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])))$"
              },
              "end": {
                "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])))$",
                "description": "Last day of a duration fact or date of an instant fact."
              }
            },
            "required": [
              "end"
            ],
            "additionalProperties": false
          },
          "unit": {
            "type": "string"
          },
          "versions": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "reported"
                    },
                    "filed": {
                      "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])))$"
                    },
                    "fact": {
                      "type": "object",
                      "properties": {
                        "cik": {
                          "type": "string"
                        },
                        "taxonomy": {
                          "type": "string",
                          "pattern": "^[a-z][a-z0-9-]{0,19}$",
                          "description": "SEC taxonomy, e.g. us-gaap."
                        },
                        "tag": {
                          "type": "string",
                          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,254}$",
                          "description": "Case-sensitive XBRL concept tag."
                        },
                        "start": {
                          "description": "First day of a duration fact. Omit for an instant fact.",
                          "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])))$"
                        },
                        "end": {
                          "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])))$",
                          "description": "Last day of a duration fact or date of an instant fact."
                        },
                        "unit": {
                          "type": "string"
                        },
                        "value": {
                          "type": "number"
                        },
                        "fiscalYear": {
                          "description": "Fiscal year of the filing, as supplied by SEC EDGAR.",
                          "anyOf": [
                            {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "fiscalPeriod": {
                          "description": "Fiscal period of the filing, as supplied by SEC EDGAR.",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "form": {
                          "type": "string"
                        },
                        "filed": {
                          "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])))$"
                        },
                        "accession": {
                          "type": "string",
                          "pattern": "^\\d{10}-\\d{2}-\\d{6}$"
                        },
                        "frame": {
                          "description": "Current SEC calendar frame metadata, when present.",
                          "type": "string"
                        },
                        "acceptedAt": {
                          "description": "SEC submission acceptance time, used to order same-day filings.",
                          "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)))$"
                        },
                        "filingUrl": {
                          "type": "string",
                          "format": "uri"
                        }
                      },
                      "required": [
                        "cik",
                        "taxonomy",
                        "tag",
                        "end",
                        "unit",
                        "value",
                        "form",
                        "filed",
                        "accession",
                        "filingUrl"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "status",
                    "filed",
                    "fact"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "needs_review"
                    },
                    "filed": {
                      "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])))$"
                    },
                    "candidates": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "cik": {
                            "type": "string"
                          },
                          "taxonomy": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9-]{0,19}$",
                            "description": "SEC taxonomy, e.g. us-gaap."
                          },
                          "tag": {
                            "type": "string",
                            "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,254}$",
                            "description": "Case-sensitive XBRL concept tag."
                          },
                          "start": {
                            "description": "First day of a duration fact. Omit for an instant fact.",
                            "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])))$"
                          },
                          "end": {
                            "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])))$",
                            "description": "Last day of a duration fact or date of an instant fact."
                          },
                          "unit": {
                            "type": "string"
                          },
                          "value": {
                            "type": "number"
                          },
                          "fiscalYear": {
                            "description": "Fiscal year of the filing, as supplied by SEC EDGAR.",
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "fiscalPeriod": {
                            "description": "Fiscal period of the filing, as supplied by SEC EDGAR.",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "form": {
                            "type": "string"
                          },
                          "filed": {
                            "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])))$"
                          },
                          "accession": {
                            "type": "string",
                            "pattern": "^\\d{10}-\\d{2}-\\d{6}$"
                          },
                          "frame": {
                            "description": "Current SEC calendar frame metadata, when present.",
                            "type": "string"
                          },
                          "acceptedAt": {
                            "description": "SEC submission acceptance time, used to order same-day filings.",
                            "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)))$"
                          },
                          "filingUrl": {
                            "type": "string",
                            "format": "uri"
                          }
                        },
                        "required": [
                          "cik",
                          "taxonomy",
                          "tag",
                          "end",
                          "unit",
                          "value",
                          "form",
                          "filed",
                          "accession",
                          "filingUrl"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Conflicting facts or filings whose order could not be determined."
                    }
                  },
                  "required": [
                    "status",
                    "filed",
                    "candidates"
                  ],
                  "additionalProperties": false
                }
              ]
            }
          }
        },
        "required": [
          "period",
          "unit",
          "versions"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "cik",
    "source",
    "concept",
    "series"
  ],
  "additionalProperties": false
}
```
