Skip to content

Commit

Permalink
feat(examples): switch to query api (#237)
Browse files Browse the repository at this point in the history
Signed-off-by: Márk Sági-Kazár <[email protected]>
Co-authored-by: Márk Sági-Kazár <[email protected]>
  • Loading branch information
hekike and sagikazarmark authored Oct 26, 2023
1 parent af5fee7 commit 7c982b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
5 changes: 2 additions & 3 deletions examples/export-stripe-node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ async function reportUsage(

// Query usage from OpenMeter for billing period
// Change window size if you want to report hourly
const resp = await openmeter.meters.values(meterSlug, {
subject,
const resp = await openmeter.meters.query(meterSlug, {
subject: [subject],
from,
to,
windowSize: WindowSize.DAY
})

// We asked for the whole day with window daily size so we will have only one usage record which is the total for that day
Expand Down
4 changes: 2 additions & 2 deletions examples/ingest-fastify-node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ server.get('/', {
Querystring: { subject?: string; from?: string; to?: string, windowSize?: WindowSize }
}>
) => {
const values = await openmeter.meters.values('m1', {
subject: req.query.subject,
const values = await openmeter.meters.query('m1', {
subject: req.query.subject ? [req.query.subject] : undefined,
from: req.query.from ? new Date(req.query.from) : undefined,
to: req.query.to ? new Date(req.query.to) : undefined,
windowSize: req.query.windowSize
Expand Down
7 changes: 0 additions & 7 deletions examples/ingest-openai-node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ async function query() {
// groupBy: { 'model': 'gpt-4' }
// }
// ]

// If you need the total across all models, you can use the following:
const total = values.reduce(
(total: number, { value }) => total + (value || 0),
0
)
console.log(`Total token usage across all models: ${total}`)
}

main()
Expand Down

0 comments on commit 7c982b8

Please sign in to comment.