---
title: Create or replace a budget's custom forecast
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Cloud Cost Management
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Create or replace a budget's custom forecast{% #create-or-replace-a-budgets-custom-forecast %}
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 | PUT https://api.ap1.datadoghq.com/api/v2/cost/budget/custom-forecast |
| ap2.datadoghq.com | PUT https://api.ap2.datadoghq.com/api/v2/cost/budget/custom-forecast |
| app.datadoghq.eu  | PUT https://api.datadoghq.eu/api/v2/cost/budget/custom-forecast      |
| app.ddog-gov.com  | PUT https://api.ddog-gov.com/api/v2/cost/budget/custom-forecast      |
| us2.ddog-gov.com  | PUT https://api.us2.ddog-gov.com/api/v2/cost/budget/custom-forecast  |
| uk1.datadoghq.com | PUT https://api.uk1.datadoghq.com/api/v2/cost/budget/custom-forecast |
| app.datadoghq.com | PUT https://api.datadoghq.com/api/v2/cost/budget/custom-forecast     |
| us3.datadoghq.com | PUT https://api.us3.datadoghq.com/api/v2/cost/budget/custom-forecast |
| us5.datadoghq.com | PUT https://api.us5.datadoghq.com/api/v2/cost/budget/custom-forecast |

### Overview

Create or replace the custom forecast for an existing budget. Pass an empty `entries` list to delete the custom forecast for the budget.

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field                         | Type     | Description                                                                                                 |
| ------------ | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------- |
|              | data [*required*]        | object   | Custom forecast resource wrapper in an upsert request.                                                      |
| data         | attributes [*required*]  | object   | Attributes of a custom forecast upsert request.                                                             |
| attributes   | budget_uid [*required*]  | string   | The UUID of the budget that this custom forecast belongs to.                                                |
| attributes   | entries [*required*]     | [object] | Monthly custom forecast entries. An empty list deletes any existing custom forecast for the budget.         |
| entries      | amount [*required*]      | double   | Forecast amount for the month.                                                                              |
| entries      | month [*required*]       | int64    | Month the custom forecast entry applies to, in `YYYYMM` format.                                             |
| entries      | tag_filters [*required*] | [object] | Tag filters that scope this custom forecast entry to specific resources.                                    |
| tag_filters  | tag_key [*required*]     | string   | The tag key to filter on.                                                                                   |
| tag_filters  | tag_value [*required*]   | string   | The tag value to filter on.                                                                                 |
| data         | id                            | string   | Unused on upsert; the resource is keyed by `budget_uid`. Send an empty string.                              |
| data         | type [*required*]        | enum     | The type of the custom forecast resource. Must be `custom_forecast`. Allowed enum values: `custom_forecast` |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "budget_uid": "00000000-0000-0000-0000-000000000001",
      "entries": [
        {
          "amount": 400,
          "month": 202501,
          "tag_filters": [
            {
              "tag_key": "service",
              "tag_value": "ec2"
            }
          ]
        }
      ]
    },
    "id": "",
    "type": "custom_forecast"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Response object containing the custom forecast for a budget.

| Parent field | Field                         | Type     | Description                                                                                                 |
| ------------ | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------- |
|              | data [*required*]        | object   | Custom forecast resource wrapper in a response.                                                             |
| data         | attributes [*required*]  | object   | Attributes of a custom forecast.                                                                            |
| attributes   | budget_uid [*required*]  | string   | The UUID of the budget that this custom forecast belongs to.                                                |
| attributes   | created_at [*required*]  | int64    | Timestamp the custom forecast was created, in Unix milliseconds.                                            |
| attributes   | created_by [*required*]  | string   | The id of the user that created the custom forecast.                                                        |
| attributes   | entries [*required*]     | [object] | Monthly custom forecast entries.                                                                            |
| entries      | amount [*required*]      | double   | Forecast amount for the month.                                                                              |
| entries      | month [*required*]       | int64    | Month the custom forecast entry applies to, in `YYYYMM` format.                                             |
| entries      | tag_filters [*required*] | [object] | Tag filters that scope this custom forecast entry to specific resources.                                    |
| tag_filters  | tag_key [*required*]     | string   | The tag key to filter on.                                                                                   |
| tag_filters  | tag_value [*required*]   | string   | The tag value to filter on.                                                                                 |
| attributes   | updated_at [*required*]  | int64    | Timestamp the custom forecast was last updated, in Unix milliseconds.                                       |
| attributes   | updated_by [*required*]  | string   | The id of the user that last updated the custom forecast.                                                   |
| data         | id [*required*]          | string   | The unique identifier of the custom forecast.                                                               |
| data         | type [*required*]        | enum     | The type of the custom forecast resource. Must be `custom_forecast`. Allowed enum values: `custom_forecast` |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "budget_uid": "00000000-0000-0000-0000-000000000001",
      "created_at": 1738258683590,
      "created_by": "00000000-0a0a-0a0a-aaa0-00000000000a",
      "entries": [
        {
          "amount": 400,
          "month": 202501,
          "tag_filters": [
            {
              "tag_key": "service",
              "tag_value": "ec2"
            }
          ]
        }
      ],
      "updated_at": 1738258683590,
      "updated_by": "00000000-0a0a-0a0a-aaa0-00000000000a"
    },
    "id": "11111111-1111-1111-1111-111111111111",
    "type": "custom_forecast"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% 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 %}

{% tab title="404" %}
Not Found
{% 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 %}

{% 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 PUT "https://api.datadoghq.com/api/v2/cost/budget/custom-forecast" \
-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
{
  "data": {
    "attributes": {
      "budget_uid": "00000000-0000-0000-0000-000000000001",
      "entries": [
        {
          "amount": 400,
          "month": 202501,
          "tag_filters": [
            {
              "tag_key": "service",
              "tag_value": "ec2"
            }
          ]
        },
        {
          "amount": 450,
          "month": 202502,
          "tag_filters": [
            {
              "tag_key": "service",
              "tag_value": "ec2"
            }
          ]
        }
      ]
    },
    "id": "",
    "type": "custom_forecast"
  }
}
EOF 
                
##### 

```python
"""
Create or replace a budget's custom forecast 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.custom_forecast_entry import CustomForecastEntry
from datadog_api_client.v2.model.custom_forecast_entry_tag_filter import CustomForecastEntryTagFilter
from datadog_api_client.v2.model.custom_forecast_type import CustomForecastType
from datadog_api_client.v2.model.custom_forecast_upsert_request import CustomForecastUpsertRequest
from datadog_api_client.v2.model.custom_forecast_upsert_request_data import CustomForecastUpsertRequestData
from datadog_api_client.v2.model.custom_forecast_upsert_request_data_attributes import (
    CustomForecastUpsertRequestDataAttributes,
)

body = CustomForecastUpsertRequest(
    data=CustomForecastUpsertRequestData(
        attributes=CustomForecastUpsertRequestDataAttributes(
            budget_uid="00000000-0000-0000-0000-000000000001",
            entries=[
                CustomForecastEntry(
                    amount=400.0,
                    month=202501,
                    tag_filters=[
                        CustomForecastEntryTagFilter(
                            tag_key="service",
                            tag_value="ec2",
                        ),
                    ],
                ),
            ],
        ),
        id="",
        type=CustomForecastType.CUSTOM_FORECAST,
    ),
)

configuration = Configuration()
configuration.unstable_operations["upsert_custom_forecast"] = True
with ApiClient(configuration) as api_client:
    api_instance = CloudCostManagementApi(api_client)
    response = api_instance.upsert_custom_forecast(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
# Create or replace a budget's custom forecast returns "OK" response

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

body = DatadogAPIClient::V2::CustomForecastUpsertRequest.new({
  data: DatadogAPIClient::V2::CustomForecastUpsertRequestData.new({
    attributes: DatadogAPIClient::V2::CustomForecastUpsertRequestDataAttributes.new({
      budget_uid: "00000000-0000-0000-0000-000000000001",
      entries: [
        DatadogAPIClient::V2::CustomForecastEntry.new({
          amount: 400,
          month: 202501,
          tag_filters: [
            DatadogAPIClient::V2::CustomForecastEntryTagFilter.new({
              tag_key: "service",
              tag_value: "ec2",
            }),
          ],
        }),
      ],
    }),
    id: "",
    type: DatadogAPIClient::V2::CustomForecastType::CUSTOM_FORECAST,
  }),
})
p api_instance.upsert_custom_forecast(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
// Create or replace a budget's custom forecast 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.CustomForecastUpsertRequest{
		Data: datadogV2.CustomForecastUpsertRequestData{
			Attributes: datadogV2.CustomForecastUpsertRequestDataAttributes{
				BudgetUid: "00000000-0000-0000-0000-000000000001",
				Entries: []datadogV2.CustomForecastEntry{
					{
						Amount: 400,
						Month:  202501,
						TagFilters: []datadogV2.CustomForecastEntryTagFilter{
							{
								TagKey:   "service",
								TagValue: "ec2",
							},
						},
					},
				},
			},
			Id:   datadog.PtrString(""),
			Type: datadogV2.CUSTOMFORECASTTYPE_CUSTOM_FORECAST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.UpsertCustomForecast", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCloudCostManagementApi(apiClient)
	resp, r, err := api.UpsertCustomForecast(ctx, body)

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CloudCostManagementApi.UpsertCustomForecast`:\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
// Create or replace a budget's custom forecast 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.CustomForecastEntry;
import com.datadog.api.client.v2.model.CustomForecastEntryTagFilter;
import com.datadog.api.client.v2.model.CustomForecastResponse;
import com.datadog.api.client.v2.model.CustomForecastType;
import com.datadog.api.client.v2.model.CustomForecastUpsertRequest;
import com.datadog.api.client.v2.model.CustomForecastUpsertRequestData;
import com.datadog.api.client.v2.model.CustomForecastUpsertRequestDataAttributes;
import java.util.Collections;

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

    CustomForecastUpsertRequest body =
        new CustomForecastUpsertRequest()
            .data(
                new CustomForecastUpsertRequestData()
                    .attributes(
                        new CustomForecastUpsertRequestDataAttributes()
                            .budgetUid("00000000-0000-0000-0000-000000000001")
                            .entries(
                                Collections.singletonList(
                                    new CustomForecastEntry()
                                        .amount(400.0)
                                        .month(202501L)
                                        .tagFilters(
                                            Collections.singletonList(
                                                new CustomForecastEntryTagFilter()
                                                    .tagKey("service")
                                                    .tagValue("ec2"))))))
                    .id("")
                    .type(CustomForecastType.CUSTOM_FORECAST));

    try {
      CustomForecastResponse result = apiInstance.upsertCustomForecast(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CloudCostManagementApi#upsertCustomForecast");
      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
// Create or replace a budget's custom forecast returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;
use datadog_api_client::datadogV2::model::CustomForecastEntry;
use datadog_api_client::datadogV2::model::CustomForecastEntryTagFilter;
use datadog_api_client::datadogV2::model::CustomForecastType;
use datadog_api_client::datadogV2::model::CustomForecastUpsertRequest;
use datadog_api_client::datadogV2::model::CustomForecastUpsertRequestData;
use datadog_api_client::datadogV2::model::CustomForecastUpsertRequestDataAttributes;

#[tokio::main]
async fn main() {
    let body = CustomForecastUpsertRequest::new(
        CustomForecastUpsertRequestData::new(
            CustomForecastUpsertRequestDataAttributes::new(
                "00000000-0000-0000-0000-000000000001".to_string(),
                vec![CustomForecastEntry::new(
                    400.0,
                    202501,
                    vec![CustomForecastEntryTagFilter::new(
                        "service".to_string(),
                        "ec2".to_string(),
                    )],
                )],
            ),
            CustomForecastType::CUSTOM_FORECAST,
        )
        .id("".to_string()),
    );
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.UpsertCustomForecast", true);
    let api = CloudCostManagementAPI::with_config(configuration);
    let resp = api.upsert_custom_forecast(body).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
/**
 * Create or replace a budget's custom forecast returns "OK" response
 */

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

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

const params: v2.CloudCostManagementApiUpsertCustomForecastRequest = {
  body: {
    data: {
      attributes: {
        budgetUid: "00000000-0000-0000-0000-000000000001",
        entries: [
          {
            amount: 400,
            month: 202501,
            tagFilters: [
              {
                tagKey: "service",
                tagValue: "ec2",
              },
            ],
          },
        ],
      },
      id: "",
      type: "custom_forecast",
    },
  },
};

apiInstance
  .upsertCustomForecast(params)
  .then((data: v2.CustomForecastResponse) => {
    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 %}
