Get cost across multi-org account.
Cost by org data for a given month becomes available no later than the 16th of the following month.
Note: This endpoint has been deprecated. Please use the new endpoint
/historical_cost
instead.
# Required query arguments exportstart_month="CHANGE_ME" # Use a Personal Access Token or Service Access Token exportDD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
"""
Get cost across multi-org account returns "OK" response
"""fromdatetimeimportdatetimefromdateutil.relativedeltaimportrelativedeltafromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.usage_metering_apiimportUsageMeteringApiconfiguration=Configuration()configuration.access_token=environ["DD_BEARER_TOKEN"]withApiClient(configuration)asapi_client:api_instance=UsageMeteringApi(api_client)response=api_instance.get_cost_by_org(start_month=(datetime.now()+relativedelta(days=-3)),)print(response)
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"python3"example.py"
# Get cost across multi-org account returns "OK" responserequire"datadog_api_client"DatadogAPIClient.configuredo|config|config.access_token=ENV["DD_BEARER_TOKEN"]endapi_instance=DatadogAPIClient::V2::UsageMeteringAPI.newpapi_instance.get_cost_by_org((Time.now+-3*86400))
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"rb"example.rb"
// Get cost across multi-org account returns "OK" responsepackagemainimport("context""encoding/json""fmt""os""time""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){ctx:=datadog.NewDefaultContext(context.Background())ctx=context.WithValue(ctx,datadog.ContextAccessToken,os.Getenv("DD_BEARER_TOKEN"))configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewUsageMeteringApi(apiClient)resp,r,err:=api.GetCostByOrg(ctx,time.Now().AddDate(0,0,-3),*datadogV2.NewGetCostByOrgOptionalParameters())iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `UsageMeteringApi.GetCostByOrg`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `UsageMeteringApi.GetCostByOrg`:\n%s\n",responseContent)}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"go run"main.go"
// Get cost across multi-org account returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.UsageMeteringApi;importcom.datadog.api.client.v2.model.CostByOrgResponse;importjava.time.OffsetDateTime;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));UsageMeteringApiapiInstance=newUsageMeteringApi(defaultClient);try{CostByOrgResponseresult=apiInstance.getCostByOrg(OffsetDateTime.now().plusDays(-3));System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling UsageMeteringApi#getCostByOrg");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"java"Example.java"
// Get cost across multi-org account returns "OK" response
usechrono::{DateTime,Utc};usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_usage_metering::GetCostByOrgOptionalParams;usedatadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI;#[tokio::main]asyncfnmain(){letconfiguration=datadog::Configuration::new();letapi=UsageMeteringAPI::with_config(configuration);letresp=api.get_cost_by_org(DateTime::parse_from_rfc3339("2021-11-08T11:11:11+00:00").expect("Failed to parse datetime").with_timezone(&Utc),GetCostByOrgOptionalParams::default(),).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Get cost across multi-org account returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration({authMethods:{AuthZ:{accessToken: process.env.DD_BEARER_TOKENasstring,},},});constapiInstance=newv2.UsageMeteringApi(configuration);constparams: v2.UsageMeteringApiGetCostByOrgRequest={startMonth: newDate(newDate().getTime()+-3*86400*1000),};apiInstance.getCostByOrg(params).then((data: v2.CostByOrgResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"tsc"example.ts"
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.