import os
from datetime import datetime
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
usage_report = client.cloud.usage_reports.get(
time_from=datetime.fromisoformat("2023-01-01T00:00:00"),
time_to=datetime.fromisoformat("2023-02-01T00:00:00"),
)
print(usage_report.count)package main
import (
"context"
"fmt"
"time"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cloud"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
usageReport, err := client.Cloud.UsageReports.Get(context.TODO(), cloud.UsageReportGetParams{
TimeFrom: time.Now(),
TimeTo: time.Now(),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", usageReport.Count)
}
curl --request POST \
--url https://api.gcore.com/cloud/v1/usage_report \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"limit": 50,
"offset": 0,
"order_by": [
"project.desc"
],
"projects": [
16,
17,
18,
19,
20
],
"regions": [
4,
5
],
"schema_filter": {
"field": "flavor",
"type": "instance",
"values": [
"g1-standard-1-2"
]
},
"tags": {
"condition_type": "OR",
"conditions": [
{
"key": "os_version",
"strict": true,
"value": "22.04"
},
{
"key": "os_version",
"strict": true,
"value": "23.04"
}
]
},
"time_from": "2019-08-01T00:00:00",
"time_to": "2019-09-15T00:00:00",
"types": [
"egress_traffic",
"instance"
]
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
limit: 50,
offset: 0,
order_by: ['project.desc'],
projects: [16, 17, 18, 19, 20],
regions: [4, 5],
schema_filter: {field: 'flavor', type: 'instance', values: ['g1-standard-1-2']},
tags: {
condition_type: 'OR',
conditions: [
{key: 'os_version', strict: true, value: '22.04'},
{key: 'os_version', strict: true, value: '23.04'}
]
},
time_from: '2019-08-01T00:00:00',
time_to: '2019-09-15T00:00:00',
types: ['egress_traffic', 'instance']
})
};
fetch('https://api.gcore.com/cloud/v1/usage_report', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/cloud/v1/usage_report",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'limit' => 50,
'offset' => 0,
'order_by' => [
'project.desc'
],
'projects' => [
16,
17,
18,
19,
20
],
'regions' => [
4,
5
],
'schema_filter' => [
'field' => 'flavor',
'type' => 'instance',
'values' => [
'g1-standard-1-2'
]
],
'tags' => [
'condition_type' => 'OR',
'conditions' => [
[
'key' => 'os_version',
'strict' => true,
'value' => '22.04'
],
[
'key' => 'os_version',
'strict' => true,
'value' => '23.04'
]
]
],
'time_from' => '2019-08-01T00:00:00',
'time_to' => '2019-09-15T00:00:00',
'types' => [
'egress_traffic',
'instance'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.gcore.com/cloud/v1/usage_report")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"limit\": 50,\n \"offset\": 0,\n \"order_by\": [\n \"project.desc\"\n ],\n \"projects\": [\n 16,\n 17,\n 18,\n 19,\n 20\n ],\n \"regions\": [\n 4,\n 5\n ],\n \"schema_filter\": {\n \"field\": \"flavor\",\n \"type\": \"instance\",\n \"values\": [\n \"g1-standard-1-2\"\n ]\n },\n \"tags\": {\n \"condition_type\": \"OR\",\n \"conditions\": [\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"22.04\"\n },\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"23.04\"\n }\n ]\n },\n \"time_from\": \"2019-08-01T00:00:00\",\n \"time_to\": \"2019-09-15T00:00:00\",\n \"types\": [\n \"egress_traffic\",\n \"instance\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/cloud/v1/usage_report")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"limit\": 50,\n \"offset\": 0,\n \"order_by\": [\n \"project.desc\"\n ],\n \"projects\": [\n 16,\n 17,\n 18,\n 19,\n 20\n ],\n \"regions\": [\n 4,\n 5\n ],\n \"schema_filter\": {\n \"field\": \"flavor\",\n \"type\": \"instance\",\n \"values\": [\n \"g1-standard-1-2\"\n ]\n },\n \"tags\": {\n \"condition_type\": \"OR\",\n \"conditions\": [\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"22.04\"\n },\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"23.04\"\n }\n ]\n },\n \"time_from\": \"2019-08-01T00:00:00\",\n \"time_to\": \"2019-09-15T00:00:00\",\n \"types\": [\n \"egress_traffic\",\n \"instance\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"count": 1,
"resources": [
{
"billing_metric_name": "bm3-ai-1xlarge-h100-80-8_min",
"billing_value": 1000,
"billing_value_unit": "minutes",
"first_seen": "2024-07-01T00:00:30Z",
"flavor": "bm3-ai-1xlarge-h100-80-8",
"last_name": "ai_cluster_name",
"last_seen": "2024-07-30T23:59:30Z",
"project_id": 10,
"region": 76,
"region_id": 76,
"tags": [
{
"os_distro": "ubuntu"
},
{
"os_version": "22.04"
}
],
"type": "ai_cluster",
"uuid": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"totals": [
{
"billing_metric_name": "bm3-ai-1xlarge-h100-80-8_min",
"billing_value": 1000,
"billing_value_unit": "minutes",
"flavor": "bm3-ai-1xlarge-h100-80-8",
"region": 76,
"region_id": 76,
"type": "ai_cluster"
}
]
}Get usage statistics report
Data from the past hour may not reflect the full set of statistics. For the most complete and accurate results, we recommend accessing the data at least one hour after the relevant time period. Updates are generally available within a 24-hour window, though timing can vary. Scheduled maintenance or other exceptions may occasionally cause delays beyond 24 hours.
import os
from datetime import datetime
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
usage_report = client.cloud.usage_reports.get(
time_from=datetime.fromisoformat("2023-01-01T00:00:00"),
time_to=datetime.fromisoformat("2023-02-01T00:00:00"),
)
print(usage_report.count)package main
import (
"context"
"fmt"
"time"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cloud"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
usageReport, err := client.Cloud.UsageReports.Get(context.TODO(), cloud.UsageReportGetParams{
TimeFrom: time.Now(),
TimeTo: time.Now(),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", usageReport.Count)
}
curl --request POST \
--url https://api.gcore.com/cloud/v1/usage_report \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"limit": 50,
"offset": 0,
"order_by": [
"project.desc"
],
"projects": [
16,
17,
18,
19,
20
],
"regions": [
4,
5
],
"schema_filter": {
"field": "flavor",
"type": "instance",
"values": [
"g1-standard-1-2"
]
},
"tags": {
"condition_type": "OR",
"conditions": [
{
"key": "os_version",
"strict": true,
"value": "22.04"
},
{
"key": "os_version",
"strict": true,
"value": "23.04"
}
]
},
"time_from": "2019-08-01T00:00:00",
"time_to": "2019-09-15T00:00:00",
"types": [
"egress_traffic",
"instance"
]
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
limit: 50,
offset: 0,
order_by: ['project.desc'],
projects: [16, 17, 18, 19, 20],
regions: [4, 5],
schema_filter: {field: 'flavor', type: 'instance', values: ['g1-standard-1-2']},
tags: {
condition_type: 'OR',
conditions: [
{key: 'os_version', strict: true, value: '22.04'},
{key: 'os_version', strict: true, value: '23.04'}
]
},
time_from: '2019-08-01T00:00:00',
time_to: '2019-09-15T00:00:00',
types: ['egress_traffic', 'instance']
})
};
fetch('https://api.gcore.com/cloud/v1/usage_report', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/cloud/v1/usage_report",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'limit' => 50,
'offset' => 0,
'order_by' => [
'project.desc'
],
'projects' => [
16,
17,
18,
19,
20
],
'regions' => [
4,
5
],
'schema_filter' => [
'field' => 'flavor',
'type' => 'instance',
'values' => [
'g1-standard-1-2'
]
],
'tags' => [
'condition_type' => 'OR',
'conditions' => [
[
'key' => 'os_version',
'strict' => true,
'value' => '22.04'
],
[
'key' => 'os_version',
'strict' => true,
'value' => '23.04'
]
]
],
'time_from' => '2019-08-01T00:00:00',
'time_to' => '2019-09-15T00:00:00',
'types' => [
'egress_traffic',
'instance'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.gcore.com/cloud/v1/usage_report")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"limit\": 50,\n \"offset\": 0,\n \"order_by\": [\n \"project.desc\"\n ],\n \"projects\": [\n 16,\n 17,\n 18,\n 19,\n 20\n ],\n \"regions\": [\n 4,\n 5\n ],\n \"schema_filter\": {\n \"field\": \"flavor\",\n \"type\": \"instance\",\n \"values\": [\n \"g1-standard-1-2\"\n ]\n },\n \"tags\": {\n \"condition_type\": \"OR\",\n \"conditions\": [\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"22.04\"\n },\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"23.04\"\n }\n ]\n },\n \"time_from\": \"2019-08-01T00:00:00\",\n \"time_to\": \"2019-09-15T00:00:00\",\n \"types\": [\n \"egress_traffic\",\n \"instance\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/cloud/v1/usage_report")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"limit\": 50,\n \"offset\": 0,\n \"order_by\": [\n \"project.desc\"\n ],\n \"projects\": [\n 16,\n 17,\n 18,\n 19,\n 20\n ],\n \"regions\": [\n 4,\n 5\n ],\n \"schema_filter\": {\n \"field\": \"flavor\",\n \"type\": \"instance\",\n \"values\": [\n \"g1-standard-1-2\"\n ]\n },\n \"tags\": {\n \"condition_type\": \"OR\",\n \"conditions\": [\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"22.04\"\n },\n {\n \"key\": \"os_version\",\n \"strict\": true,\n \"value\": \"23.04\"\n }\n ]\n },\n \"time_from\": \"2019-08-01T00:00:00\",\n \"time_to\": \"2019-09-15T00:00:00\",\n \"types\": [\n \"egress_traffic\",\n \"instance\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"count": 1,
"resources": [
{
"billing_metric_name": "bm3-ai-1xlarge-h100-80-8_min",
"billing_value": 1000,
"billing_value_unit": "minutes",
"first_seen": "2024-07-01T00:00:30Z",
"flavor": "bm3-ai-1xlarge-h100-80-8",
"last_name": "ai_cluster_name",
"last_seen": "2024-07-30T23:59:30Z",
"project_id": 10,
"region": 76,
"region_id": 76,
"tags": [
{
"os_distro": "ubuntu"
},
{
"os_version": "22.04"
}
],
"type": "ai_cluster",
"uuid": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"totals": [
{
"billing_metric_name": "bm3-ai-1xlarge-h100-80-8_min",
"billing_value": 1000,
"billing_value_unit": "minutes",
"flavor": "bm3-ai-1xlarge-h100-80-8",
"region": 76,
"region_id": 76,
"type": "ai_cluster"
}
]
}Authorizations
API key for authentication. Make sure to include the word apikey, followed by a single space and then your token.
Example: apikey 1234_abcdef
Body
The start date of the report period (ISO 8601). The report starts from the beginning of this day in UTC.
"2023-01-01T00:00:00Z"
The end date of the report period (ISO 8601). The report ends just before the beginning of this day in UTC.
"2023-02-01T00:00:00Z"
Expenses for the last specified day are taken into account. As the default, False.
false
The response resources limit. Defaults to 10.
10
The response resources offset.
x >= 00
List of sorting criteria in 'field.direction' format.
billing_value.asc, billing_value.desc, first_seen.asc, first_seen.desc, last_name.asc, last_name.desc, last_seen.asc, last_seen.desc, project.asc, project.desc, region.asc, region.desc, type.asc, type.desc ["project.asc", "region.desc"]
List of project IDs
[16, 17, 18, 19, 20]
List of region IDs.
[1, 2, 3]
Extended filter for field filtering.
- SchemaFilterSnapshotSerializer
- SchemaFilterInstanceSerializer
- SchemaFilterAiClusterSerializer
- SchemaFilterAiVirtualClusterSerializer
- SchemaFilterBasicVmSerializer
- SchemaFilterBaremetalSerializer
- SchemaFilterVolumeSerializer
- SchemaFilterFileShareSerializer
- SchemaFilterImageSerializer
- SchemaFilterFloatingIpSerializer
- SchemaFilterEgressTrafficSerializer
- SchemaFilterLoadBalancerSerializer
- SchemaFilterExternalIpSerializer
- SchemaFilterBackupSerializer
- SchemaFilterLogIndexSerializer
- SchemaFilterFunctionsSerializer
- SchemaFilterFunctionsCallsSerializer
- SchemaFilterFunctionsTrafficSerializer
- SchemaFilterContainersSerializer
- SchemaFilterInferenceSerializer
- SchemaFilterDBAASPostgreSQLVolumeSerializer
- SchemaFilterDBAASPostgreSQLPublicNetworkSerializer
- SchemaFilterDBAASPostgreSQLCPUSerializer
- SchemaFilterDBAASPostgreSQLMemorySerializer
- SchemaFilterDBAASPostgreSQLPoolerSerializer
Show child attributes
Show child attributes
{
"field": "flavor",
"type": "instance",
"values": ["g1-standard-1-2"]
}
(DEPRECATED Use 'order_by' instead) List of sorting filters (JSON objects) fields: project. directions: asc, desc.
Show child attributes
Show child attributes
Filter by tags
Show child attributes
Show child attributes
{
"condition_type": "OR",
"conditions": [
{
"key": "os_version",
"strict": true,
"value": "22.04"
},
{
"key": "os_version",
"strict": true,
"value": "23.04"
}
]
}
List of resource types to be filtered in the report.
Resource types for prebilling report
ai_cluster, ai_virtual_cluster, backup, baremetal, basic_vm, containers, dbaas_postgresql_connection_pooler, dbaas_postgresql_cpu, dbaas_postgresql_memory, dbaas_postgresql_public_network, dbaas_postgresql_volume, egress_traffic, external_ip, file_share, floatingip, functions, functions_calls, functions_traffic, image, inference, instance, load_balancer, log_index, snapshot, volume ["egress_traffic", "instance"]
Response
OK
Total count of the resources
x >= 01
These properties are common for all individual AI clusters in all cost and usage reports results (but not in totals)
- ResourceAiClusterSerializer
- ResourceAiVirtualClusterSerializer
- ResourceBaremetalSerializer
- ResourceBasicVmSerializer
- ResourceBackupSerializer
- ResourceContainerSerializer
- ResourceEgressTrafficSerializer
- ResourceExternalIpSerializer
- ResourceFileShareSerializer
- ResourceFloatingIpSerializer
- ResourceFunctionsSerializer
- ResourceFunctionCallsSerializer
- ResourceFunctionEgressTrafficSerializer
- ResourceImagesSerializer
- ResourceInferenceSerializer
- ResourceInstanceSerializer
- ResourceLoadBalancerSerializer
- ResourceLogIndexSerializer
- ResourceSnapshotSerializer
- ResourceVolumeSerializer
- ResourceDBAASPostgreSQLPoolerSerializer
- ResourceDBAASPostgreSQLMemorySerializer
- ResourceDBAASPostgreSQLPublicNetworkSerializer
- ResourceDBAASPostgreSQLCPUSerializer
- ResourceDBAASPostgreSQLVolumeSerializer
Show child attributes
Show child attributes
- TotalAiClusterReportItemSerializer
- TotalAiVirtualClusterReportItemSerializer
- TotalBaremetalReportItemSerializer
- TotalBasicVmReportItemSerializer
- TotalContainerReportItemSerializer
- TotalEgressTrafficReportItemSerializer
- TotalExternalIpReportItemSerializer
- TotalFileShareReportItemSerializer
- TotalFloatingIpReportItemSerializer
- TotalFunctionsReportItemSerializer
- TotalFunctionCallsReportItemSerializer
- TotalFunctionEgressTrafficReportItemSerializer
- TotalImagesReportItemSerializer
- TotalInferenceReportItemSerializer
- TotalInstanceReportItemSerializer
- TotalLoadBalancerReportItemSerializer
- TotalLogIndexReportItemSerializer
- TotalSnapshotReportItemSerializer
- TotalVolumeReportItemSerializer
- TotalDBAASPostgreSQLPoolerReportItemSerializer
- TotalDBAASPostgreSQLMemoryReportItemSerializer
- TotalDBAASPostgreSQLPublicNetworkReportItemSerializer
- TotalDBAASPostgreSQLCPUReportItemSerializer
- TotalDBAASPostgreSQLVolumeReportItemSerializer
Show child attributes
Show child attributes
Was this page helpful?