Assistant Billing

Errors

All API errors return a consistent JSON object.

Error Format

{
  "error": {
    "message": "Insufficient balance",
    "code": "insufficient_balance",
    "status": 402
  }
}

HTTP Status Codes

StatusMeaning
400Bad Request — invalid parameters
401Unauthorized — missing or invalid key
402Payment Required — insufficient balance
403Forbidden — key lacks required permissions
404Not Found — resource doesn't exist
409Conflict — duplicate resource
429Too Many Requests — rate limit exceeded
500Internal Server Error

SDK Error Classes

import { GatewayError, GatewayAuthError, GatewayRateLimitError } from '@assistant-billing/sdk';
ClassStatusProperties
GatewayErrorAnymessage, status, code?, requestId?
GatewayAuthError401message, requestId?
GatewayRateLimitError429message, requestId?, retryAfterMs?

Handle Errors

import { GatewayError, GatewayAuthError, GatewayRateLimitError } from '@assistant-billing/sdk';
 
try {
  const res = await gateway.chat.completions.create({ ... });
} catch (err) {
  if (err instanceof GatewayRateLimitError) {
    // Retry after err.retryAfterMs
  } else if (err instanceof GatewayAuthError) {
    // Invalid or expired key
  } else if (err instanceof GatewayError) {
    console.error(err.status, err.message, err.code);
  }
}