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

# API

Access Ledger Analytics, our state-of-the-art insurance data science models and data structures,
via convenient API endpoints.

## API keys

To access our API endpoints,
first email `analytics@ledgerinvesting.com`.
On receipt of your email, we will send you an invite
link to sign up to our platform where you
can create and manage API keys.

## Base endpoint

The base URL for all these endpoints is:

```console Base endpoint theme={null}
https://ldgr.app/analytics
```

## Authentication and access

Triangles and models are only accessible by users within the same organization.
Users cannot access objects from other organizations, but all users
within the same organization can access the same objects.

## Companion Python package

For ease of use, we have a companion [LedgerAnalytics Python package](https://ledger-investing-ledger-analytics.readthedocs-hosted.com/en/latest/)
and associated documentation. The latter contains more technical details
about modeling configuration and rationale.

## Triangle endpoints

### List all triangles

| Name        | Method | Description                                                                                                                               |
| ----------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `/triangle` | `GET`  | List all triangles a user can access within their organization. Returns all relevant data for triangles, including name and internal ids. |

### Create or update a triangle

| Name        | Method | Description                              |
| ----------- | ------ | ---------------------------------------- |
| `/triangle` | `POST` | Create a named triangle in the database. |

| Parameter       | Type    | Required | Description                                                                                                                                                                                                                                                                                                |
| --------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `triangle_name` | string  | yes      | The name of the triangle.                                                                                                                                                                                                                                                                                  |
| `triangle_data` | JSON    | yes      | The triangle data. See our Python package [Bermuda](https://github.com/LedgerInvesting/bermuda-ledger) for more information about the correct dictionary/JSON format. The easiest option is to generate the JSON by saving the results of the `.to_dict()` method called on a Bermuda `Triangle` instance. |
| `overwrite`     | boolean | no       | If a triangle already exists in the database, you must force it's re-creation by setting `overwrite=true`                                                                                                                                                                                                  |

### Delete a triangle

| Name             | Method   | Description                                              |
| ---------------- | -------- | -------------------------------------------------------- |
| `/triangle/{id}` | `DELETE` | Delete a triangle in the database using the triangle id. |

## Model endpoints

The LedgerAnalytics API has a number of loss development, tail development, and loss ratio forecasting
models available for use. Each model type has it's own endpoint for basic
CRUD operations. The specific endpoints are:

* `/development-model`
* `/tail-model`
* `/forecast-model`

For the different types of endpoints below, substitute `{model}` for any of the
four specific endpoints above.

### Create or update a model

This endpoint fits the specific model to a triangle of data already
in the database.

| Name       | Method | Description                              |
| ---------- | ------ | ---------------------------------------- |
| `/{model}` | `POST` | Create a named triangle in the database. |

| Parameter       | Type    | Required | Description                                                                                                                                                                                                                                                            |
| --------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `triangle_name` | string  | yes      | The name of a triangle present in the database.                                                                                                                                                                                                                        |
| `model_name`    | string  | yes      | The user's chosen name of the model.                                                                                                                                                                                                                                   |
| `model_type`    | string  | yes      | The specific type of model. For full information about model types, see the [Model types](##model-types) section.                                                                                                                                                      |
| `model_config`  | JSON    | yes      | Configuration parameters for the model. See the User Guide sections for our companion Python [LedgerAnalytics](https://github.com/LedgerInvesting/ledger-analytics) package for a full description of each model's technical explanation and configuration parameters. |
| `overwrite`     | boolean | no       | Set `overwrite=true` to overwrite a previously fit model. Defaults to `false` to avoid unintended overwrites.                                                                                                                                                          |

### List fitted models

| Name       | Method | Description                                                                              |
| ---------- | ------ | ---------------------------------------------------------------------------------------- |
| `/{model}` | `GET`  | List all created models, returning key information such as model names and internal ids. |

### Predict from a model

Take a fitted model and produce predictions on a new triangle.

| Name                    | Method | Description                                                                                    |
| ----------------------- | ------ | ---------------------------------------------------------------------------------------------- |
| `/{model}/{id}/predict` | `POST` | Makes predictions using a fitted model and stores the triangle of predictions in the database. |

| Parameter        | Type   | Required | Description                                                                                                                                                                                                                                                                    |
| ---------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `triangle_name`  | string | yes      | The name of the triangle to predict from. Many of insurance development and forecast models are auto-regressive and require an initial triangle to start predicting from.                                                                                                      |
| `predict_config` | JSON   | yes      | Configuration parameters for the model. See the User Guide sections for our companion Python [LedgerAnalytics](https://github.com/LedgerInvesting/ledger-analytics) package for a full description of each model's technical explanation and predict configuration parameters. |

### Delete a model

| Name            | Method   | Description            |
| --------------- | -------- | ---------------------- |
| `/{model}/{id}` | `DELETE` | Delete a fitted model. |

### Terminate a running model

Our models run on remote cloud compute infrastructure. This endpoint
allows users to terminate the remote process during model fit time.

| Name                      | Method | Description                         |
| ------------------------- | ------ | ----------------------------------- |
| `/{model}/{id}/terminate` | `POST` | Terminate a remotely running model. |

### Model types

| Model               | Types                                                                                               | Reference                                                                                                                                 |
| ------------------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `development-model` | - `ChainLadder`<br />- `TraditionalChainLadder`<br />- `MeyersCRC`<br />- `GMCL`<br />- `ManualATA` | See the [detailed documentation](https://ledger-investing-ledger-analytics.readthedocs-hosted.com/en/latest/user-guide/development.html). |
| `tail-model`        | - `GeneralizedBondy`<br />- `Sherman`<br />- `ClassicalPowerTransform`                              | See the [detailed documentation](https://ledger-investing-ledger-analytics.readthedocs-hosted.com/en/latest/user-guide/tail.html)         |
| `forecast-model`    | - `AR1`<br />- `SSM`<br />- `TraditionalGCC`                                                        | See the [detailed documentation](https://ledger-investing-ledger-analytics.readthedocs-hosted.com/en/latest/user-guide/forecast.html).    |
