---
title: Search cost recommendations
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Cloud Cost Management
---

# Search cost recommendations{% #search-cost-recommendations %}
Copy pageCopied
{% tab title="v2" %}
**Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
| Datadog site      | API endpoint                                                   |
| ----------------- | -------------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/cost/recommendations |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/cost/recommendations |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/cost/recommendations      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/cost/recommendations      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/cost/recommendations  |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/cost/recommendations     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/cost/recommendations |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/cost/recommendations |

### Overview

List cost recommendations matching a filter, with pagination and sorting.

OAuth apps require the `cloud_cost_management_read` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#cloud-cost-management) to access this endpoint.



### Arguments

#### Query Strings

| Name        | Type   | Description                                |
| ----------- | ------ | ------------------------------------------ |
| page[size]  | string | Number of results per page (1–10000).      |
| page[token] | string | Pagination token from a previous response. |

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field      | Type     | Description                                                                                   |
| ------------ | ---------- | -------- | --------------------------------------------------------------------------------------------- |
|              | filter     | string   | Filter expression applied to the recommendations.                                             |
|              | sort       | [object] | Ordered list of sort clauses applied to the result set.                                       |
| sort         | expression | string   | Field to sort by (for example, `potential_daily_savings.amount`).                             |
| sort         | order      | string   | Sort direction, either `ASC` or `DESC`.                                                       |
|              | view       | string   | Active view name (for example, `active`, `dismissed`, `open`, `in-progress`, or `completed`). |

{% /tab %}

{% tab title="Example" %}

```json
{
  "filter": "string",
  "sort": [
    {
      "expression": "string",
      "order": "string"
    }
  ],
  "view": "string"
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
A page of cost recommendations with pagination metadata.

| Parent field            | Field                   | Type     | Description                                                                 |
| ----------------------- | ----------------------- | -------- | --------------------------------------------------------------------------- |
|                         | data [*required*]  | [object] | The list of cost recommendations on this page.                              |
| data                    | attributes              | object   | Attributes describing a single cost recommendation.                         |
| attributes              | dd_resource_key         | string   | Datadog resource key identifying the recommended resource.                  |
| attributes              | potential_daily_savings | object   | Estimated daily savings if the recommendation is applied.                   |
| potential_daily_savings | amount                  | double   | Numeric amount of the potential daily savings.                              |
| potential_daily_savings | currency                | string   | ISO 4217 currency code for the savings amount.                              |
| attributes              | recommendation_type     | string   | The kind of recommendation (for example, `terminate` or `rightsize`).       |
| attributes              | resource_id             | string   | Cloud provider identifier of the resource.                                  |
| attributes              | resource_type           | string   | Resource type (for example, `aws_ec2_instance`).                            |
| attributes              | tags                    | [string] | Tags attached to the recommended resource.                                  |
| data                    | id                      | string   | Unique identifier for the recommendation.                                   |
| data                    | type [*required*]  | enum     | Recommendation resource type. Allowed enum values: `recommendation`         |
|                         | meta                    | object   | Top-level JSON:API meta object for paginated cost recommendation responses. |
| meta                    | page                    | object   | Pagination metadata for a page of cost recommendations.                     |
| page                    | filter                  | string   | The filter expression that was applied to produce this page.                |
| page                    | next_page_token         | string   | Opaque token used to fetch the next page; absent on the last page.          |
| page                    | page_size               | int32    | Number of items returned in this page (1–10000).                            |
| page                    | page_token              | string   | Pagination token echoed back from the request.                              |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": [
    {
      "attributes": {
        "dd_resource_key": "string",
        "potential_daily_savings": {
          "amount": "number",
          "currency": "string"
        },
        "recommendation_type": "string",
        "resource_id": "string",
        "resource_type": "string",
        "tags": []
      },
      "id": "string",
      "type": "recommendation"
    }
  ],
  "meta": {
    "page": {
      "filter": "string",
      "next_page_token": "string",
      "page_size": "integer",
      "page_token": "string"
    }
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/cost/recommendations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "filter": "@resource_table:aws_ec2_instance",
  "sort": [
    {
      "expression": "potential_daily_savings.amount",
      "order": "DESC"
    }
  ]
}
EOF 
                
##### 

```python
"""
Search cost recommendations returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.cloud_cost_management_api import CloudCostManagementApi
from datadog_api_client.v2.model.recommendations_filter_request import RecommendationsFilterRequest
from datadog_api_client.v2.model.recommendations_filter_request_sort_items import RecommendationsFilterRequestSortItems

body = RecommendationsFilterRequest(
    filter="@resource_table:aws_ec2_instance",
    sort=[
        RecommendationsFilterRequestSortItems(
            expression="potential_daily_savings.amount",
            order="DESC",
        ),
    ],
)

configuration = Configuration()
configuration.unstable_operations["search_cost_recommendations"] = True
with ApiClient(configuration) as api_client:
    api_instance = CloudCostManagementApi(api_client)
    response = api_instance.search_cost_recommendations(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
##### 

```ruby
# Search cost recommendations returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.unstable_operations["v2.search_cost_recommendations".to_sym] = true
end
api_instance = DatadogAPIClient::V2::CloudCostManagementAPI.new

body = DatadogAPIClient::V2::RecommendationsFilterRequest.new({
  filter: "@resource_table:aws_ec2_instance",
  sort: [
    DatadogAPIClient::V2::RecommendationsFilterRequestSortItems.new({
      expression: "potential_daily_savings.amount",
      order: "DESC",
    }),
  ],
})
p api_instance.search_cost_recommendations(body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```go
// Search cost recommendations returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.RecommendationsFilterRequest{
		Filter: datadog.PtrString("@resource_table:aws_ec2_instance"),
		Sort: []datadogV2.RecommendationsFilterRequestSortItems{
			{
				Expression: datadog.PtrString("potential_daily_savings.amount"),
				Order:      datadog.PtrString("DESC"),
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.SearchCostRecommendations", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCloudCostManagementApi(apiClient)
	resp, r, err := api.SearchCostRecommendations(ctx, body, *datadogV2.NewSearchCostRecommendationsOptionalParameters())

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `CloudCostManagementApi.SearchCostRecommendations`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CloudCostManagementApi.SearchCostRecommendations`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
##### 

```java
// Search cost recommendations returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CloudCostManagementApi;
import com.datadog.api.client.v2.model.CostRecommendationArray;
import com.datadog.api.client.v2.model.RecommendationsFilterRequest;
import com.datadog.api.client.v2.model.RecommendationsFilterRequestSortItems;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setUnstableOperationEnabled("v2.searchCostRecommendations", true);
    CloudCostManagementApi apiInstance = new CloudCostManagementApi(defaultClient);

    RecommendationsFilterRequest body =
        new RecommendationsFilterRequest()
            .filter("@resource_table:aws_ec2_instance")
            .sort(
                Collections.singletonList(
                    new RecommendationsFilterRequestSortItems()
                        .expression("potential_daily_savings.amount")
                        .order("DESC")));

    try {
      CostRecommendationArray result = apiInstance.searchCostRecommendations(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CloudCostManagementApi#searchCostRecommendations");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
##### 

```rust
// Search cost recommendations returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;
use datadog_api_client::datadogV2::api_cloud_cost_management::SearchCostRecommendationsOptionalParams;
use datadog_api_client::datadogV2::model::RecommendationsFilterRequest;
use datadog_api_client::datadogV2::model::RecommendationsFilterRequestSortItems;

#[tokio::main]
async fn main() {
    let body = RecommendationsFilterRequest::new()
        .filter("@resource_table:aws_ec2_instance".to_string())
        .sort(vec![RecommendationsFilterRequestSortItems::new()
            .expression("potential_daily_savings.amount".to_string())
            .order("DESC".to_string())]);
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.SearchCostRecommendations", true);
    let api = CloudCostManagementAPI::with_config(configuration);
    let resp = api
        .search_cost_recommendations(body, SearchCostRecommendationsOptionalParams::default())
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
##### 

```typescript
/**
 * Search cost recommendations returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
configuration.unstableOperations["v2.searchCostRecommendations"] = true;
const apiInstance = new v2.CloudCostManagementApi(configuration);

const params: v2.CloudCostManagementApiSearchCostRecommendationsRequest = {
  body: {
    filter: "@resource_table:aws_ec2_instance",
    sort: [
      {
        expression: "potential_daily_savings.amount",
        order: "DESC",
      },
    ],
  },
};

apiInstance
  .searchCostRecommendations(params)
  .then((data: v2.CostRecommendationArray) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"
{% /tab %}
