The public SDK is split into three dual ESM/CommonJS packages for Node.js 20 and newer.
Constructor options:
| Option | Required | Description |
|---|---|---|
baseUrl |
yes | Absolute Meter HTTP(S) origin |
serviceId |
yes | Tenant-scoped Meter service ID |
serviceApiKey |
for protected methods | Server-side service API key |
fetchImpl |
no | Custom Fetch implementation |
defaultOrigin |
no | Default hosted-session return origin |
timeoutMs |
no | Request timeout, default 15 seconds |
Service and integration methods:
health,listServices,updateServicelistApiKeys,createApiKey,revokeApiKeygetIntegration,updateIntegrationlistAiModelPrices,upsertAiModelPricelistWebhookEndpoints,createWebhookEndpoint,disableWebhookEndpoint,testWebhooks
Customer methods:
upsertCustomer,getCustomerCredits,getCustomerLedgersetCustomerStatus,setAutoRecharge,createCreditAdjustmentcreateTopUp,createPortalSession
Usage methods:
authorize,commit,releasemeterToolCalland its aliaswithUsagelistReservations,releaseExpiredReservations,usage,auditLogs
Operator method:
createOperatorSession
Uses a platform onboarding key to create a new service, its initial API key, and optional gateway integration in one request. This client is intended for a trusted Meter control plane, not provider frontend code.
verifyMeterWebhookSignature verifies the x-meter-signature HMAC against the
raw request body and enforces a timestamp tolerance. It accepts strings or
UTF-8 byte arrays and supports multiple v1 signatures for key rotation.
MeterPublicApiErrorexposesstatus,path, parsedbody, and optionalrequestId.MeterTimeoutErrorexposespathandtimeoutMs.MeterNetworkErrorexposespathandcause.MeterWebhookSignatureErroridentifies malformed, stale, or invalid signatures.
Mutating requests are not automatically retried. Reuse the same idempotency or request ID when retrying after an unknown network outcome.
MeterAiUsageInput records provider, model, uncached input, cached input,
output, reasoning tokens, request count, provider request ID, and either actual
costUsd or versioned MeterAiTokenPricing. calculateMeterAiUsage performs
integer micro-USD calculation. usage() returns model/tool/customer cost
rollups with gross revenue, gross profit, margin, and unpriced-call counts.
paidTool: wraps an arbitrary async tool handler.registerPaidTool: registers a wrapped tool on an MCP-compatible server.meterErrorToMcpResult: converts recognized billing errors into structured MCP errors.
Billing values can be constants or async resolvers based on tool input and MCP extra context. Supported attribution fields are customer, credits, provider, product, request ID, and reservation TTL.
createBuyerPortalHandlercreateBuyerPortalRedirectHandlercreateOperatorConsoleHandlercreateOperatorConsoleRedirectHandlertoExpressHandleraiUsageFromOpenAIaiUsageFromAnthropic
The provider must authenticate users and authorize operators before a session is created. Hosted session origins are bound to the incoming request origin by default and may be overridden explicitly.