Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/reference/qcloud_serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A space is hosted in a single cloud region and scales its search workers
automatically, so there are no nodes, packages or disks to size. Use the
commands in this group to manage spaces together with their API keys and
backups, to explore the regions spaces can be created in, and to inspect the
account's serverless quota.
account's serverless quota and billed usage.

### Examples

Expand All @@ -22,6 +22,9 @@ qcloud serverless cloud-region list
# Show how many spaces the account can still create
qcloud serverless quota

# Show the billed serverless usage of the current month per space
qcloud serverless usage

# List all serverless spaces
qcloud serverless space list

Expand Down Expand Up @@ -54,4 +57,5 @@ qcloud serverless space create --cloud-region eu-central-1 --wait
* [qcloud serverless cloud-region](qcloud_serverless_cloud-region.md) - Explore cloud regions for serverless spaces
* [qcloud serverless quota](qcloud_serverless_quota.md) - Show the serverless quota of the account
* [qcloud serverless space](qcloud_serverless_space.md) - Manage serverless spaces
* [qcloud serverless usage](qcloud_serverless_usage.md) - Show the billed serverless usage per space

72 changes: 72 additions & 0 deletions docs/reference/qcloud_serverless_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## qcloud serverless usage

Show the billed serverless usage per space

### Synopsis

Show the billed serverless usage of the current account per space and billable item.

Each row is one billable item of one space in one calendar month, as named on
the invoice (for example "Serverless Updated Data (GiB)"), with the quantity
consumed, the charge, the discount and the net charge. The net total of all
rows is shown below the table. Prepaid credits drawn for the period are not
subtracted.

By default, the period is the current calendar month (UTC) up to now. Use
--month for a whole calendar month, or --since and --until for any other
period. When only --until is given, the period starts on the first day of its
month. Usage is reported per calendar month, so a period that starts or ends
within a month only includes the usage metered in that part of the month.

For a parent billing account, the usage of all child accounts is included and
an ACCOUNT column is shown. Cluster usage and the prepaid credits drawn are
left out, also from --json. The API key needs the read:payment_information
permission.

```
qcloud serverless usage [flags]
```

### Examples

```
# Show the serverless usage of the current month so far
qcloud serverless usage

# Show the usage of October 2026
qcloud serverless usage --month 2026-10

# Show the usage of one space during the third quarter of 2026
qcloud serverless usage --space 0e7a3c1d-5f2b-4c8e-9a6d-1b2c3d4e5f60 --since 2026-07-01 --until 2026-09-30

# Export the usage as JSON
qcloud serverless usage --month 2026-10 --json
```

### Options

```
-h, --help[=true|false] help for usage
--month string Calendar month in YYYY-MM format (UTC); cannot be combined with --since or --until
-s, --since string Start of the period (RFC3339, YYYY-MM-DD, or a duration ago such as 24h or 7d; default: first day of the month of --until)
--space string Only include the space with this ID
-u, --until string End of the period, exclusive (RFC3339, YYYY-MM-DD for the end of that day, or a duration ago such as 1h; default: now)
```

### Options inherited from parent commands

```
--account-id string Qdrant Cloud Account ID (env: QDRANT_CLOUD_ACCOUNT_ID)
--api-key string Management API Key (env: QDRANT_CLOUD_API_KEY)
-c, --config string Config file path (env: QDRANT_CLOUD_CONFIG, default ~/.config/qcloud/config.yaml)
--console-url string Qdrant Cloud web console base URL (env: QDRANT_CLOUD_CONSOLE_URL, default https://cloud.qdrant.io)
--context string Override the active context (env: QDRANT_CLOUD_CONTEXT)
--debug[=true|false] Enable debug logging to stderr
--endpoint string gRPC API endpoint (env: QDRANT_CLOUD_ENDPOINT, default grpc.cloud.qdrant.io:443)
--json[=true|false] Output as JSON
```

### SEE ALSO

* [qcloud serverless](qcloud_serverless.md) - Manage Qdrant Cloud Serverless resources

24 changes: 24 additions & 0 deletions internal/cmd/output/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ func USDMillicents(v uint64) string {
return fmt.Sprintf("$%s.%02d", humanize.Comma(int64(cents/100)), cents%100) //nolint:gosec // dollars fit in int64
}

// Millicents formats an amount in millicents (1/1000 of the currency's minor
// unit) in the given ISO 4217 currency. USD and an empty currency are shown as
// dollars (e.g. "$1,234.56"); other currencies as the amount followed by the
// code (e.g. "1,234.56 EUR"). Fractions of a cent are rounded down, and a
// negative amount gets a leading minus sign.
func Millicents(v int64, currency string) string {
abs := uint64(v) //nolint:gosec // v is non-negative here, negated below otherwise
if v < 0 {
abs = uint64(-v) //nolint:gosec // -v is positive
}

cents := abs / 1000
sign := ""
if v < 0 && cents > 0 {
sign = "-"
}

if currency == "" || currency == "USD" {
return sign + USDMillicents(abs)
}

return fmt.Sprintf("%s%s.%02d %s", sign, humanize.Comma(int64(cents/100)), cents%100, currency) //nolint:gosec // amounts fit in int64
}

// Rate formats a per-second rate with two decimals (e.g. "1.25/s").
func Rate(v float64) string {
return strconv.FormatFloat(v, 'f', 2, 64) + "/s"
Expand Down
17 changes: 17 additions & 0 deletions internal/cmd/output/money_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ func TestUSDMillicents(t *testing.T) {
assert.Equal(t, want, output.USDMillicents(in), "%d", in)
}
}

func TestMillicents(t *testing.T) {
for _, tc := range []struct {
in int64
currency string
want string
}{
{0, "USD", "$0.00"},
{1_234_567 * 1_000, "USD", "$12,345.67"},
{50 * output.MillicentsPerUSD, "", "$50.00"},
{-1_500 * 1_000, "USD", "-$15.00"},
{1_234_567 * 1_000, "EUR", "12,345.67 EUR"},
{-999, "EUR", "0.00 EUR"},
} {
assert.Equal(t, tc.want, output.Millicents(tc.in, tc.currency), "%d %s", tc.in, tc.currency)
}
}
7 changes: 6 additions & 1 deletion internal/cmd/serverless/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/qdrant/qcloud-cli/internal/cmd/serverless/cloudregion"
"github.com/qdrant/qcloud-cli/internal/cmd/serverless/quota"
"github.com/qdrant/qcloud-cli/internal/cmd/serverless/space"
"github.com/qdrant/qcloud-cli/internal/cmd/serverless/usage"
"github.com/qdrant/qcloud-cli/internal/state"
)

Expand All @@ -21,13 +22,16 @@ A space is hosted in a single cloud region and scales its search workers
automatically, so there are no nodes, packages or disks to size. Use the
commands in this group to manage spaces together with their API keys and
backups, to explore the regions spaces can be created in, and to inspect the
account's serverless quota.`,
account's serverless quota and billed usage.`,
Example: `# List the regions in which spaces can be created
qcloud serverless cloud-region list

# Show how many spaces the account can still create
qcloud serverless quota

# Show the billed serverless usage of the current month per space
qcloud serverless usage

# List all serverless spaces
qcloud serverless space list

Expand All @@ -39,6 +43,7 @@ qcloud serverless space create --cloud-region eu-central-1 --wait`,
space.NewCommand(s),
cloudregion.NewCommand(s),
quota.NewCommand(s),
usage.NewCommand(s),
)
return cmd
}
Loading