API methods cost: 0 (free), 10 (standard), or 100 (resource-intensive) units.
import { SocketSdk } from '@socketsecurity/sdk'
const client = new SocketSdk('your-api-key')
const quota = await client.getQuota()
if (quota.success) {
console.log(`Available: ${quota.data.quota} units`)
}import {
getQuotaCost,
calculateTotalQuotaCost,
hasQuotaForMethods,
getMethodsByQuotaCost
} from '@socketsecurity/sdk'
// Get method cost
getQuotaCost('batchPackageFetch') // 100
getQuotaCost('getOrgAnalytics') // 10
getQuotaCost('getQuota') // 0
// Calculate total
const cost = calculateTotalQuotaCost([
'batchPackageFetch', // 100
'getOrgAnalytics', // 10
'getQuota' // 0
]) // Returns: 110
// Check quota
const canProceed = hasQuotaForMethods(availableQuota, [
'batchPackageFetch',
'createFullScan'
])
// Methods by cost
getMethodsByQuotaCost(0) // Free methods
getMethodsByQuotaCost(10) // Standard methods
getMethodsByQuotaCost(100) // Expensive methodsconst operations = ['batchPackageFetch', 'uploadManifestFiles']
const required = calculateTotalQuotaCost(operations)
const quota = await client.getQuota()
if (!quota.success || !hasQuotaForMethods(quota.data.quota, operations)) {
throw new Error(`Need ${required} units, have ${quota.data.quota}`)
}class QuotaTracker {
private used = 0
async track<T>(methodName: string, op: () => Promise<T>): Promise<T> {
const cost = getQuotaCost(methodName)
const result = await op()
this.used += cost
console.log(`Used ${this.used} units`)
return result
}
}const quota = await client.getQuota()
const batchCost = getQuotaCost('batchPackageFetch')
if (quota.success && quota.data.quota >= batchCost) {
await client.batchPackageFetch({ components })
} else {
// Fall back to individual queries
for (const pkg of packages) {
await client.getScoreByNpmPackage(pkg.name, pkg.version)
}
}For the complete list of API method quota costs, see data/api-method-quota-and-permissions.json.
Summary:
- Free (0): 44 methods including
getQuota,getOrganizations,getEntitlements,createFullScan,getScan,getScanList,getOrgSecurityPolicy,updateOrgSecurityPolicy, repo management, triage, labels, diff scans, exports, and more - Standard (10):
getOrgAnalytics,getRepoAnalytics,getAuditLogEvents,getIssuesByNpmPackage,getScoreByNpmPackage,getOrgAlertFullScans, API token operations - Expensive (100):
batchPackageFetch,batchOrgPackageFetch,batchPackageStream,createDependenciesSnapshot,createScanFromFilepaths,searchDependencies,uploadManifestFiles
- Check quota before expensive operations
- Use batching (100 units for all vs 10 per package)
- Monitor usage with tracker
- Implement fallback strategies