Meter Errors

Solenoid Meter returns structured JSON errors with machine-readable codes and human-readable messages.

See Error Format for the shared error schema.

Error Code Reference

CodeHTTPCauseFix
validation_error400Invalid request body or parametersCheck the fields object for specific failures (negative amounts, missing fields)
unauthorized401Missing or invalid API keyAdd a valid Authorization: Bearer sm_xxx header
forbidden403Authenticated but not authorized for this meterVerify you own the meter and your key has the required scopes
not_found404Meter does not exist or invalid routeVerify the meter ID; multi-tenant meters are created on first use
meter.insufficient_balance402Balance too low for the requested deductionRefill the meter or reduce the deduction amount
meter.balance_overflow400Refill would exceed the max balance (2^53 - 1)Reset the meter or split across multiple meters
rate_limit_exceeded429Too many requests in the current windowBack off with exponential retry; consider batching operations

Handling Key Errors

Insufficient balance (402): Surface this to end users and prompt for a top-up. Check balance with GET /v1/meter/:meterId/balance before expensive operations.

Rate limiting (429): Batch high-frequency operations. Buffer usage locally and flush every 1-60 seconds. Use exponential backoff on retries.

Balance overflow (400): The max balance is 2^53 - 1 (JavaScript safe integer). If you approach this limit, use multiple meters for different resources or reset the meter periodically.

Best Practices

  • Use integers for all amounts. If you need cents, store as cents (not dollars) to avoid rounding drift.
  • Trust atomic operations. Do not check-then-deduct. Call deduct directly and handle insufficient_balance on failure.
  • Batch high-volume events. Accumulate usage locally and flush to Meter periodically to reduce API calls.
  • Log request IDs. Every response includes X-Request-Id for debugging with Solenoid support.

For step-by-step debugging, see Troubleshooting.