Skip to content
Start here

Get Spend Policy

client.Billing.SpendPolicies.Get(ctx, policyID, query) (*SpendPolicyGetResponse, error)
GET/accounts/{account_id}/billing/spend-policies/{policy_id}

Returns one spend policy. The ETag response header holds the current version; send it as If-Match on a later update or delete.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
policyID string

The unique identifier of the spend policy.

formatuuid
query SpendPolicyGetParams
AccountID param.Field[string]

Represents a Cloudflare resource identifier tag.

maxLength32
ReturnsExpand Collapse
type SpendPolicyGetResponse struct{…}

A spend policy.

ID string

The unique identifier of the spend policy.

formatuuid
AccountID int64

Internal numeric ID of the account that owns the policy. This is not the account tag used in the path.

formatint64
Action SpendPolicyGetResponseAction

The action taken when the threshold is reached. notification sends an email to notification_email. usage_block blocks further usage of the product until the end of the billing period. Raising the threshold above the current balance, disabling the policy, or deleting it lifts the block early.

One of the following:
const SpendPolicyGetResponseActionNotification SpendPolicyGetResponseAction = "notification"
const SpendPolicyGetResponseActionUsageBlock SpendPolicyGetResponseAction = "usage_block"
Enabled bool

Whether the policy is evaluated.

Name string

Display name of the policy.

NotificationEmail string

Email address that receives notifications. An empty string when none is set.

ProductID SpendPolicyGetResponseProductID

The product the policy applies to: workers or durable_objects. Each product’s balance and policies are separate. Both products support notification and usage_block policies on create and update.

One of the following:
const SpendPolicyGetResponseProductIDWorkers SpendPolicyGetResponseProductID = "workers"
const SpendPolicyGetResponseProductIDDurableObjects SpendPolicyGetResponseProductID = "durable_objects"
ThresholdCents int64

The spend threshold for the current billing period, in US cents.

formatint64
Version int64

Optimistic-concurrency version. It starts at 1 and goes up by one on every update or delete. This value is also returned in ETag.

formatint64
minimum1
CurrentState SpendPolicyGetResponseCurrentStateOptional

Read-only state on list/get responses, evaluated from the latest owning projector snapshot at request time, independently of the API replica. Configuration enabled/version/ETag do not change when a cycle rolls over. Audit history remains unchanged. Missing during a rolling upgrade or on mutation responses; clients must treat missing state as unavailable. Balances are asynchronous estimates, not a synchronous usage read.

BalanceCents int64
formatint64
BillingPeriodEnd Time
formatdate-time
BillingPeriodStart Time
formatdate-time
Enforcement SpendPolicyGetResponseCurrentStateEnforcement

Durable desired cap and delivery bookkeeping for this policy, or null if no owned effect exists. Separate from threshold evaluation: pending/leased/retry can lag the new billing period. Succeeded with equal generations means delivery completed, not an EWC readback.

AppliedGeneration int64
formatint64
DeliveryStatus SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatus
One of the following:
const SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatusPending SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatus = "pending"
const SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatusLeased SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatus = "leased"
const SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatusRetry SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatus = "retry"
const SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatusSucceeded SpendPolicyGetResponseCurrentStateEnforcementDeliveryStatus = "succeeded"
DesiredGeneration int64
formatint64
DesiredState SpendPolicyGetResponseCurrentStateEnforcementDesiredState
One of the following:
const SpendPolicyGetResponseCurrentStateEnforcementDesiredStateActive SpendPolicyGetResponseCurrentStateEnforcementDesiredState = "active"
const SpendPolicyGetResponseCurrentStateEnforcementDesiredStateInactive SpendPolicyGetResponseCurrentStateEnforcementDesiredState = "inactive"
ExpiresAt Time
formatdate-time
EvaluatedAt Time

Evaluation time; not the timestamp of the latest usage event.

formatdate-time
Status SpendPolicyGetResponseCurrentStateStatus

Threshold evaluation, not proof of an edge cap. No current active period yields no_current_period for enabled policies; failed aggregate reads yield unavailable for enabled policies. Disabled policies report disabled. Neither no_current_period nor unavailable implies a zero balance or below-limit state. Operators may disable current-state reads, in which case current_state is omitted.

One of the following:
const SpendPolicyGetResponseCurrentStateStatusDisabled SpendPolicyGetResponseCurrentStateStatus = "disabled"
const SpendPolicyGetResponseCurrentStateStatusNoCurrentPeriod SpendPolicyGetResponseCurrentStateStatus = "no_current_period"
const SpendPolicyGetResponseCurrentStateStatusUnavailable SpendPolicyGetResponseCurrentStateStatus = "unavailable"
const SpendPolicyGetResponseCurrentStateStatusBelowLimit SpendPolicyGetResponseCurrentStateStatus = "below_limit"
const SpendPolicyGetResponseCurrentStateStatusLimitReached SpendPolicyGetResponseCurrentStateStatus = "limit_reached"

Get Spend Policy

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/billing"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  spendPolicy, err := client.Billing.SpendPolicies.Get(
    context.TODO(),
    "6f1c2b8e-3d4a-4f5b-9c6d-7e8f9a0b1c2d",
    billing.SpendPolicyGetParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", spendPolicy.ID)
}
{
  "errors": [
    {
      "message": "message",
      "code": 0
    }
  ],
  "messages": [
    {
      "message": "message",
      "code": 0
    }
  ],
  "result": {
    "id": "6f1c2b8e-3d4a-4f5b-9c6d-7e8f9a0b1c2d",
    "account_id": 1234567,
    "action": "notification",
    "enabled": true,
    "name": "Workers cap",
    "notification_email": "billing@example.com",
    "product_id": "workers",
    "threshold_cents": 100,
    "version": 1,
    "current_state": {
      "balance_cents": 0,
      "billing_period_end": "2019-12-27T18:11:19.117Z",
      "billing_period_start": "2019-12-27T18:11:19.117Z",
      "enforcement": {
        "applied_generation": 0,
        "delivery_status": "pending",
        "desired_generation": 0,
        "desired_state": "active",
        "expires_at": "2019-12-27T18:11:19.117Z"
      },
      "evaluated_at": "2019-12-27T18:11:19.117Z",
      "status": "disabled"
    }
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "message": "message",
      "code": 0
    }
  ],
  "messages": [
    {
      "message": "message",
      "code": 0
    }
  ],
  "result": {
    "id": "6f1c2b8e-3d4a-4f5b-9c6d-7e8f9a0b1c2d",
    "account_id": 1234567,
    "action": "notification",
    "enabled": true,
    "name": "Workers cap",
    "notification_email": "billing@example.com",
    "product_id": "workers",
    "threshold_cents": 100,
    "version": 1,
    "current_state": {
      "balance_cents": 0,
      "billing_period_end": "2019-12-27T18:11:19.117Z",
      "billing_period_start": "2019-12-27T18:11:19.117Z",
      "enforcement": {
        "applied_generation": 0,
        "delivery_status": "pending",
        "desired_generation": 0,
        "desired_state": "active",
        "expires_at": "2019-12-27T18:11:19.117Z"
      },
      "evaluated_at": "2019-12-27T18:11:19.117Z",
      "status": "disabled"
    }
  },
  "success": true
}