There are two types of budgets: average daily budgets and campaign total
budgets. You can create either type using
[`CampaignBudgetService`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudgetService).

> [!IMPORTANT]
> **Key Point:** In the Google Ads API, an average daily budget is [shareable](https://developers.google.com/google-ads/api/docs/campaigns/budgets/share-budgets) (`explicitly_shared = true`) by default unless you explicitly set `explicitly_shared` to `false` to restrict the budget to a single campaign.

## Create an average daily budget

This is the average amount you're willing to spend per day for a campaign.
You can set an average daily budget with the
[`amount_micros`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget#amount_micros) field of
[`CampaignBudget`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget). The budget
[`period`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget#period) defaults to
[`DAILY`](https://developers.google.com/google-ads/api/reference/rpc/v26/BudgetPeriodEnum.BudgetPeriod#daily).

Because [`explicitly_shared`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget#explicitly_shared)
defaults to `true` if omitted in a `create` operation, you must explicitly set
`explicitly_shared` to `false` to create a single-campaign non-shared budget, as
shown in the following example:


### Java

```java
private static String addCampaignBudget(GoogleAdsClient googleAdsClient, long customerId) {
  CampaignBudget budget =
      CampaignBudget.newBuilder()
          .setName("Interplanetary Cruise Budget #" + getPrintableDateTime())
          .setDeliveryMethod(BudgetDeliveryMethod.STANDARD)
          .setAmountMicros(500_000)
          .build();

  CampaignBudgetOperation op = CampaignBudgetOperation.newBuilder().setCreate(budget).build();

  try (CampaignBudgetServiceClient campaignBudgetServiceClient =
      googleAdsClient.getLatestVersion().createCampaignBudgetServiceClient()) {
    MutateCampaignBudgetsResponse response =
        campaignBudgetServiceClient.mutateCampaignBudgets(
            Long.toString(customerId), ImmutableList.of(op));
    String budgetResourceName = response.getResults(0).getResourceName();
    System.out.printf("Added budget: %s%n", budgetResourceName);
    return budgetResourceName;
  }
}
      
```

### C#

```c#
private static string CreateBudget(GoogleAdsClient client, long customerId)
{
    // Get the BudgetService.
    CampaignBudgetServiceClient budgetService = client.GetService(
        Services.V26.CampaignBudgetService);

    // Create the campaign budget.
    CampaignBudget budget = new CampaignBudget()
    {
        Name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
        DeliveryMethod = BudgetDeliveryMethod.Standard,
        AmountMicros = 500000
    };

    // Create the operation.
    CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation()
    {
        Create = budget
    };

    // Create the campaign budget.
    MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets(
        customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation });
    return response.Results[0].ResourceName;
}
      
```

### PHP

```php
private static function addCampaignBudget(GoogleAdsClient $googleAdsClient, int $customerId)
{
    // Creates a campaign budget.
    $budget = new CampaignBudget([
        'name' => 'Interplanetary Cruise Budget #' . Helper::getPrintableDatetime(),
        'delivery_method' => BudgetDeliveryMethod::STANDARD,
        'amount_micros' => 500000
    ]);

    // Creates a campaign budget operation.
    $campaignBudgetOperation = new CampaignBudgetOperation();
    $campaignBudgetOperation->setCreate($budget);

    // Issues a mutate request.
    $campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient();
    $response = $campaignBudgetServiceClient->mutateCampaignBudgets(
        MutateCampaignBudgetsRequest::build($customerId, [$campaignBudgetOperation])
    );

    /** @var CampaignBudget $addedBudget */
    $addedBudget = $response->getResults()[0];
    printf("Added budget named '%s'%s", $addedBudget->getResourceName(), PHP_EOL);

    return $addedBudget->getResourceName();
}
      
```

### Python

```python
# Create a budget, which can be shared by multiple campaigns.
campaign_budget_operation: CampaignBudgetOperation = client.get_type(
    "CampaignBudgetOperation"
)
campaign_budget: CampaignBudget = campaign_budget_operation.create
campaign_budget.name = f"Interplanetary Budget {uuid.uuid4()}"
campaign_budget.delivery_method = (
    client.enums.BudgetDeliveryMethodEnum.STANDARD
)
campaign_budget.amount_micros = 500000

# Add budget.
campaign_budget_response: MutateCampaignBudgetsResponse
try:
    budget_operations: List[CampaignBudgetOperation] = [
        campaign_budget_operation
    ]
    campaign_budget_response = (
        campaign_budget_service.mutate_campaign_budgets(
            customer_id=customer_id,
            operations=budget_operations,
        )
    )
except GoogleAdsException as ex:
    handle_googleads_exception(ex)
      
```

### Ruby

```ruby
# Create a budget, which can be shared by multiple campaigns.
campaign_budget = client.resource.campaign_budget do |cb|
  cb.name = "Interplanetary Budget #{(Time.new.to_f * 1000).to_i}"
  cb.delivery_method = :STANDARD
  cb.amount_micros = 500000
end

operation = client.operation.create_resource.campaign_budget(campaign_budget)

# Add budget.
return_budget = client.service.campaign_budget.mutate_campaign_budgets(
  customer_id: customer_id,
  operations: [operation],
)
      
```

### Perl

```perl
# Create a campaign budget, which can be shared by multiple campaigns.
my $campaign_budget =
  Google::Ads::GoogleAds::V26::Resources::CampaignBudget->new({
    name           => "Interplanetary budget #" . uniqid(),
    deliveryMethod => STANDARD,
    amountMicros   => 500000
  });

# Create a campaign budget operation.
my $campaign_budget_operation =
  Google::Ads::GoogleAds::V26::Services::CampaignBudgetService::CampaignBudgetOperation
  ->new({create => $campaign_budget});

# Add the campaign budget.
my $campaign_budgets_response = $api_client->CampaignBudgetService()->mutate({
    customerId => $customer_id,
    operations => [$campaign_budget_operation]});
      
```

### curl

> [!NOTE]
> **Note:** While a direct REST code sample for this step isn't provided here, you can achieve this using a manual REST request.   
>
> Refer to the Google Ads API REST interface documentation and the method-specific reference pages. You will need to construct the JSON payload based on the proto definitions.   
>
> Key Resources:
>
> - [Using REST](https://developers.google.com/google-ads/api/rest/overview)
> - [REST Interface Structure](https://developers.google.com/google-ads/api/rest/design/overview)
> - [JSON Field Mappings](https://developers.google.com/google-ads/api/rest/design/json-mappings)
> - Consult the [REST API Reference](https://developers.google.com/google-ads/api/reference/rpc/latest/overview) for the specific service and method.

<br />

## Create a campaign total budget

This is the total amount you're willing to spend over the entire duration of
the campaign. To create a campaign total budget, set the budget
[`period`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget#period) to
[`CUSTOM_PERIOD`](https://developers.google.com/google-ads/api/reference/rpc/v26/BudgetPeriodEnum.BudgetPeriod#custom_period)
and set
[`total_amount_micros`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget#total_amount_micros).
Campaign total budgets cannot be shared across campaigns, so you must set
[`explicitly_shared`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignBudget#explicitly_shared) to `false`
when creating a budget with a `period` of `CUSTOM_PERIOD`.

> [!IMPORTANT]
> **Important:** For Demand Gen, Performance Max, Search, Standard Shopping, and YouTube campaigns, you can only set a campaign total budget for campaigns with a set start and end date. Specify the campaign's start and end dates using [`Campaign.start_date_time`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign#start_date_time) and [`Campaign.end_date_time`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign#end_date_time) (`yyyy-MM-dd HH:mm:ss` format; omitting `end_date_time` results in `CampaignError.END_DATE_TIME_REQUIRED_FOR_TOTAL_BUDGET`). You can't change the budget type after a campaign is created.

When coding, the fields are the same as for an average daily budget,
except for `period` and `total_amount_micros`.

## Campaign budget recommendations

The Google Ads API provides several
[recommendation](https://support.google.com/google-ads/answer/3448398) types to
help you optimize your campaign budgets:

- [`CAMPAIGN_BUDGET`](https://developers.google.com/google-ads/api/reference/rpc/v26/Recommendation#campaign_budget_recommendation)
  suggests a new budget amount for budget-constrained campaigns.

- [`MOVE_UNUSED_BUDGET`](https://developers.google.com/google-ads/api/reference/rpc/v26/Recommendation#move_unused_budget_recommendation)
  highlights opportunities to reallocate excess budget from one campaign to
  another budget-constrained campaign.

- [`MARGINAL_ROI_CAMPAIGN_BUDGET`](https://developers.google.com/google-ads/api/reference/rpc/v26/Recommendation#marginal_roi_campaign_budget_recommendation)
  suggests a new budget amount for campaigns whose ROI is predicted to
  increase with a budget adjustment.

- [`FORECASTING_CAMPAIGN_BUDGET`](https://developers.google.com/google-ads/api/reference/rpc/v26/Recommendation#forecasting_campaign_budget_recommendation)
  suggests a new budget amount for campaigns that are expected to become
  budget-constrained in the future.

For additional recommendation types and guidance on working with recommendations
in the Google Ads API, visit the
[Optimization score and recommendations](https://developers.google.com/google-ads/api/docs/recommendations) guide.