# Cost API V1

Finout Cost API enables you to query and analyze costs using user-defined [Finout Views](/cross-platform-features/list-of-cross-platform-features/saved-views.md). You can easily get a list of your views and retrieve the costs for a specified view. You can query the costs for any date range of up to 90 days specified in UTC timestamps. The results are returned in JSON format for easy processing.

{% hint style="info" %}
**Note**: Only cost data is returned when querying a view via the Cost API.
{% endhint %}

## <mark style="color:green;">`GET`</mark>`/Views`

**Description**

Gets a list of all your account views. For more information on views, see [Finout Views.](/cross-platform-features/list-of-cross-platform-features/saved-views.md)

{% hint style="success" %}
**Prerequisites**

* [Generate a Client ID and Secret Key](/api/finout-api/generate-an-api-token.md) from Finout to add in Headers.&#x20;
* You must create a view in the MegaBill before querying the GET view. There is currently no 'Create View' API option.
  {% endhint %}

**Request**\
&#x20;\
`https://app.finout.io/v1/view`

**Response**

{% tabs %}
{% tab title="200" %}
{% code lineNumbers="true" %}

```json
{
    "data": [
        {
            "name": "Cost Ratio - Weightings by Group Name",
            "id": "25568bb9-7d9b-4b72-9361-07abcb4e5f29"
        },
        {
            "name": "Shared Services - Support, Marketplace, Security",
            "id": "08252cda-3f70-4779-822c-cf4bdf65cc28"
        },

        {
            "name": "K8s by App_Component",
            "id": "f76be053-1138-431f-a6e1-9f6d1852398b"
        }
    ],
    "requestId": "05ac7c0f-2e85-4af0-8ef7-3ace11e420d7"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

Returns a JSON object with the following properties:

* *name*: The names of your account's views.
* *id*: The unique identifier of your account's views.

## <mark style="color:green;">`POST`</mark> `/Query by view`

**Description**

Return all costs for a specified view and date range for up to 90 days. For more information on views, see [Finout Views](/cross-platform-features/list-of-cross-platform-features/saved-views.md).

{% hint style="success" %}
**Prerequisites**

* [Generate a Client ID and Secret Key](/api/finout-api/generate-an-api-token.md) from Finout to add in Headers.&#x20;

* You must first GET the view you want to query

* Add the GET view ID to the body of the POST query.\
  Example:

  ```json
  ​{
  "viewId": "6244e453-e8b8-4f1f-9a96-4ba1ae5d48f7"
  }
  ```

* You must either specify dates or delete them completely. The query won't work when blank dates are still present.\
  Example:

  ```json
  ​​{
       "viewId": "",
       "date": {
           "unixTimeMillSecondsStart": 1719824738,
           "unixTimeMillSecondsEnd": 1719911138
       },
       "costType": "netAmortizedCost"
     }
  ```

{% endhint %}

**Request**

`https://app.finout.io/v1/cost/query-by-view`

{% tabs %}
{% tab title="Request Query  Example" %}
{% code lineNumbers="true" %}

```json
{
    "viewId": "{VIEW_ID}",
    "date": {
        "unixTimeMillSecondsStart": 1719824738000,
        "unixTimeMillSecondsEnd": 1719911138000
    },
    "costType": "netAmortizedCost"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

*Body of Request*

| Parameter                  | Type    | Description                                                                                                                                                                                                                      |
| -------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *viewId*                   | string  | The ID of the view that the user queries                                                                                                                                                                                         |
| *date*                     | object  | “unixTimeMillSecondsStart” and “unixTimeMillSecondsEnd” keys                                                                                                                                                                     |
| *unixTimeMillSecondsStart* | Numeric | Start Date represented in Unix Epoch time                                                                                                                                                                                        |
| *unixTimeMillSecondsEnd*   | Numeric | End Date represented in Unix Epoch time                                                                                                                                                                                          |
| *costType*                 | String  | <p>Types of costs:<br>- blendedCost<br>- unblendedCost<br>- netUnblendedCost<br>- amortizedCost<br>- netAmortizedCost<br>See <a href="/pages/OEfnnJiZIGHN5YYp6pXZ">Cost and Usage Types</a> for an explanation of each cost.</p> |

**Response without X-Axis**

{% hint style="info" %}
**Note**: When using a `groupBy` in a Cost API query, the response returns up to **10,000 distinct groups per day**. If the number of distinct group values exceeds this limit, the remaining values are aggregated into an **"Others"** bucket.
{% endhint %}

{% tabs %}
{% tab title="Without group by" %}
{% code lineNumbers="true" %}

```json
{
    "data": [
        {
            "name": "Total",
            "dateRange": {
                "from": 1719792000000,
                "to": 1719878400000
            },
            "data": [
                {
                    "time": 1719792000000,
                    "cost": 4146.056203015
                }
            ]
        }
    ],
    "request": {
        "viewId": "58682b6c-6eed-4ed2-b649-3e3a180925b0",
        "date": {
            "unixTimeMillSecondsStart": 1719824738000,
            "unixTimeMillSecondsEnd": 1719911138000
        },
        "costType": "netAmortizedCost"
    },
    "requestId": "6ed650ca-9ea5-42f5-97eb-4b1f61cd6ac3"
}
```

{% endcode %}
{% endtab %}

{% tab title="With group by" %}

```json
{
    "data": [
        {
            "name": "Total",
            "dateRange": {
                "from": 1719792000000,
                "to": 1719878400000
            },
            "data": [
                {
                    "time": 1719792000000,
                    "cost": 44006.42380397946
                },
                {
                    "time": 1719878400000,
                    "cost": 42154.99796678599
                }
            ]
        },
        {
            "name": "pci-log-aggregator-service",
            "dateRange": {
                "from": 1719792000000,
                "to": 1719878400000
            },
            "data": [
                {
                    "time": 1719792000000,
                    "cost": 0
                },
                {
                    "time": 1719878400000,
                    "cost": 0.000005058602781953021
                }
            ]
        },
        {
            "name": "N/A",
            "dateRange": {
                "from": 1719792000000,
                "to": 1719878400000
            },
            "data": [
                {
                    "time": 1719792000000,
                    "cost": 31755.53133870504
                },
                {
                    "time": 1719878400000,
                    "cost": 31044.301095328592
                }
            ]
        }
    ],
    "request": {
        "viewId": "b17c9716-31dc-4520-adf8-6d9cd7c00776",
        "date": {
            "unixTimeMillSecondsStart": 1719824738000,
            "unixTimeMillSecondsEnd": 1719911138000
        },
        "costType": "netAmortizedCost"
    },
    "requestId": "9ca086f1-2694-4e58-9169-53641dde812b"
}
```

{% endtab %}

{% tab title="With multiple group bys" %}

```json
{
    "data": [
        {
            "name": "Total",
            "data": [
                {
                    "cost": 35.141480533889705,
                    "xAxis": "AmazonApiGateway"
                },
                {
                    "cost": 735.4910603379998,
                    "xAxis": "AmazonAthena"
                },
                {
                    "cost": 0.17100154299599998,
                    "xAxis": "AmazonBedrock"
                },
                {
                    "cost": 13.104441239756799,
                    "xAxis": "AmazonCloudFront"
                },
                {
                    "cost": 17516.513630484496,
                    "xAxis": "AmazonCloudWatch"
                },
                {
                    "cost": 258.2377045992,
                    "xAxis": "AmazonCodeWhisperer"
                },
                {
                    "cost": 0.06181462439999998,
                    "xAxis": "PaymentCryptography"
                }
            ]
        },
        {
            "name": "Services: AmazonEC2, Sub Service: EC2 - Compute, Regions: us-east-1",
            "data": [
                {
                    "cost": 950696.43372226,
                    "xAxis": "AmazonEC2"
                }
            ]
        },
        {
            "name": "Services: AmazonEC2, Sub Service: EC2 - Compute, Regions: eu-west-2",
            "data": [
                {
                    "cost": 209588.0638128479,
                    "xAxis": "AmazonEC2"
                }
            ]
        },
        {
            "name": "Services: AmazonRDS, Sub Service: RIFee, Regions: us-east-1",
            "data": [
                {
                    "cost": 0,
                    "xAxis": "AmazonRDS"
                }
            ]
        }
    ],
    "request": {
        "viewId": "9b155171-e0cb-458d-b1b1-ef5660e3b070",
        "costType": "netAmortizedCost"
    },
    "requestId": "1f064a04-f513-4f03-89b1-ad7a0f4cc6e8"
}
```

{% endtab %}
{% endtabs %}

**Response with X-Axis**

{% hint style="info" %}
**Note**: When using a `groupBy` in a Cost API query, the response returns up to **10,000 distinct groups per day**. If the number of distinct group values exceeds this limit, the remaining values are aggregated into an **"Others"** bucket.
{% endhint %}

{% tabs %}
{% tab title="X-Axis without group by " %}

```json
{
    "data": [
        {
            "name": "Total",
            "data": [
                {
                    "cost": 816.3798754186101,
                    "xAxis": "ap-northeast-1"
                },
                {
                    "cost": 16.122873119388935,
                    "xAxis": "ap-northeast-2"
                },
                {
                    "cost": 0.578173890734156,
                    "xAxis": "ap-northeast-3"
                },
                {
                    "cost": 3.447814177025843,
                    "xAxis": "ap-south-1"
                },
                {
                    "cost": 1.0833228981371137,
                    "xAxis": "ap-southeast-1"
                },
                {
                    "cost": 1326.9919779724503,
                    "xAxis": "ap-southeast-2"
                },
                {
                    "cost": 1091.2001295606847,
                    "xAxis": "ca-central-1"
                },
                {
                    "cost": 10864.315413267484,
                    "xAxis": "eu-central-1"
                },
                {
                    "cost": 0.680978558571026,
                    "xAxis": "eu-north-1"
                },
                {
                    "cost": 152.0044725767814,
                    "xAxis": "eu-west-1"
                },
                {
                    "cost": 7.653599999999999e-8,
                    "xAxis": "us-west-2"
                }
            ]
        }
    ],
    "request": {
        "viewId": "8be1c2f8-ee6e-4467-bef0-6955ff791cd2",
        "date": {
            "unixTimeMillSecondsStart": 1719824738000,
            "unixTimeMillSecondsEnd": 1719911138000
        },
        "costType": "netAmortizedCost"
    },
    "requestId": "2bbb87e7-b5fc-4e42-9eae-36c88fee8f34"
}
```

{% endtab %}

{% tab title="X-Axis with group by " %}

```json
{
    "data": [
        {
            "name": "Total",
            "data": [
                {
                    "cost": 10371.369576679925,
                    "xAxis": "App3"
                },
                {
                    "cost": 48189.45149797842,
                    "xAxis": "Untagged"
                }
            ]
        },
        {
            "name": "kubernetes",
            "data": [
                {
                    "cost": 10371.369576679925,
                    "xAxis": "App3"
                },
                {
                    "cost": 48189.45149797842,
                    "xAxis": "Untagged"
                }
            ]
        }
    ],
    "request": {
        "viewId": "4dce56d3-6344-47e4-a8d6-1c97d32582e9",
        "date": {
            "unixTimeMillSecondsStart": 1719824738000,
            "unixTimeMillSecondsEnd": 1719911138000
        },
        "costType": "netAmortizedCost"
    },
    "requestId": "989f62b1-08cd-431f-8896-6592d9016f47"
}
```

{% endtab %}

{% tab title="X-Axis with multiple group bys" %}

```json
{
    "data": [
        {
            "name": "Total",
            "data": [
                {
                    "cost": 2.5923965193981995,
                    "xAxis": "af-south-1"
                },
                {
                    "cost": 2.570799688168401,
                    "xAxis": "ap-east-1"
                },
                {
                    "cost": 7570.763087864667,
                    "xAxis": "ap-northeast-1"
                },
                {
                    "cost": 25.80399803553131,
                    "xAxis": "ap-northeast-2"
                },
                {
                    "cost": 3.702669410262598,
                    "xAxis": "ap-northeast-3"
                },
                 {
                    "cost": 331.89587825059306,
                    "xAxis": "us-west-2"
                }
            ]
        },
        {
            "name": "Services: AmazonEC2, Sub Service: EC2 - Compute, Regions: us-east-1",
            "data": [
                {
                    "cost": 950696.4337222597,
                    "xAxis": "us-east-1"
                }
            ]
        },
        {
            "name": "Services: AmazonEC2, Sub Service: EC2 - Compute, Regions: eu-west-2",
            "data": [
                {
                    "cost": 209588.06381284795,
                    "xAxis": "eu-west-2"
                }
            ]
        },
         {
            "name": "Services: AmazonRDS, Sub Service: RIFee, Regions: us-east-1",
            "data": [
                {
                    "cost": 0,
                    "xAxis": "us-east-1"
                }
            ]
        }
    ],
    "request": {
        "viewId": "982a069c-e1f6-4b09-968d-507e3b270a1f",
        "costType": "netAmortizedCost"
    },
    "requestId": "6d9c2942-6171-49c6-aab1-d51ef182c7c6"
}

```

{% endtab %}
{% endtabs %}

## Errors

|     |                    |
| --- | ------------------ |
| 400 | Bad Request        |
| 401 | Unauthorized       |
| 429 | Too many requests  |
| 503 | Server unavailable |
| 504 | Gateway Timeout    |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.finout.io/api/finout-api/cost-api-v1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
