API for querying billing/usage per app for time period?

I’m looking to get billing info per app from the API, most importantly the metrics I’ll be billed for:

-Outbound data
-Seconds of VM usage (i.e. 2 regions running for a minute would be 120 seconds)
-For a datetime range

Is there any way to get this via API? I see usage AppUsage in the graphql API but it returns an empty usage array when I query like this:

{
  app(name: "nameofapp"){
    name,
    usage {
      totalDataOutGB,
      interval,
      requestsCount,
      ts,
      totalAppExecS
    }
  }
}
2 Likes

I’d also love to see a billing estimate in each Org’s Usage screen in the dashboard, preferably per app.

There isn’t anything specific in the API involving billing. Billing is something of a black box for us, we just feed data to Stripe and it generates invoices. This is obviously not ideal so we hope to improve it, but it’ll be a while.

Fair enough, I’m looking more for the usage stats that go into generating billing. Bandwidth usage and VM usage. The usage query above just returns an empty array right now. Am I querying it wrong?

I see I can get some usage data out of:

{
  organization(name: "orgname"){
    billables(startDate: "2021-05-01", endDate: "2021-06-01"){
      nodes{
        app{
          name
        },
        category,
        product,
        quantity,
        time
      }
    }
  }
}

That returns a listing for every billable product (vm time, bandwidth) for every app in an entire organization. In my use case there will be many apps under one organization, so this isn’t the ideal way I’d want to query this.

It would much nicer if the appUsage field returned the data just for that app, or if there was some way to filter a query like this by app id/name.

organization.billables is the right way to go. We just shipped a change, you can now filter billables by date AND appId.

See if that helps?

1 Like

Is this API still available? I’m not seeing organization.billables in the Graphql docs. If not, what’s the current way to compute usage given a timeframe and app id?

Hi @yroc

The billables query became outdated so we removed it to prevent confusion.

We are currently working on improving visibility for usage data in our new usage pages like Usage Digest and many others announced on #fresh-produce . Feel free to drop in feedback on these topics.