Query Usage and Credits

Project: Query Usage and Credits

User Intent

"I want to check my project usage and remaining credits"

Operation

  • SDK Method: graphlit.queryProjectUsage() or graphlit.queryProjectCredits()

  • GraphQL: queryProjectUsage or queryProjectCredits query

  • Entity Type: Project

  • Common Use Cases: Monitor usage, check credits, track API consumption, billing analysis

TypeScript (Canonical)

import { Graphlit } from 'graphlit-client';
import { Types } from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

// Query usage for date range
const startDate = new Date('2024-01-01');
const endDate = new Date();

const usageResponse = await graphlit.queryProjectUsage(
  startDate,
  endDate
);

console.log('=== PROJECT USAGE ===');
console.log(`Period: ${startDate.toLocaleDateString()} - ${endDate.toLocaleDateString()}`);
console.log(`\nAPI Calls: ${usageResponse.usage?.length || 0} records`);

// Show usage breakdown
usageResponse.usage?.forEach(record => {
  console.log(`\n${record.date}:`);
  console.log(`  Tokens: ${record.tokens || 0}`);
  console.log(`  Storage: ${record.storage || 0} bytes`);
});

// Query remaining credits
const creditsResponse = await graphlit.queryProjectCredits();

console.log('\n=== CREDITS ===');
console.log(`Remaining: $${creditsResponse.credits?.remaining || 0}`);
console.log(`Total: $${creditsResponse.credits?.total || 0}`);
console.log(`Used: $${(creditsResponse.credits?.total || 0) - (creditsResponse.credits?.remaining || 0)}`);

Query usage (snake_case)

start_date = datetime(2024, 1, 1) end_date = datetime.now()

usage_response = await graphlit.queryProjectUsage( start_date=start_date, end_date=end_date )

print("=== PROJECT USAGE ===") print(f"API Calls: {len(usage_response.usage or [])}")

Query credits

credits_response = await graphlit.queryProjectCredits()

print("\n=== CREDITS ===") print(f"Remaining: ${credits_response.credits.remaining or 0}") print(f"Total: ${credits_response.credits.total or 0}")

Parameters

queryProjectUsage

  • startDate (Date): Start of date range

  • endDate (Date): End of date range

queryProjectCredits

  • No parameters required

Response

queryProjectUsage

queryProjectCredits

Developer Hints

Usage Tracking

Important: Usage is tracked by date. Query specific date ranges for analysis.

Credit Monitoring

Usage Analysis

Variations

1. Check Current Credits

Get credit balance:

2. Current Month Usage

This month's usage:

3. Last 30 Days Usage

Recent usage:

4. Yearly Usage Report

Full year analysis:

5. Usage Alert System

Monitor and alert:

6. Monthly Cost Report

Generate cost report:

Common Issues

Issue: No usage data returned Solution: Check date range is correct. Usage may not be recorded for future dates or very old dates.

Issue: Credits show zero Solution: Add credits to your project in the Graphlit Developer Portal.

Issue: Usage seems incomplete Solution: Usage is recorded periodically. Recent usage may not appear immediately.

Production Example

Usage monitoring dashboard:

Last updated

Was this helpful?