Errors
All API errors return a consistent JSON object.
Error Format
{
"error": {
"message": "Insufficient balance",
"code": "insufficient_balance",
"status": 402
}
}
HTTP Status Codes
| Status | Meaning |
|---|
| 400 | Bad Request — invalid parameters |
| 401 | Unauthorized — missing or invalid key |
| 402 | Payment Required — insufficient balance |
| 403 | Forbidden — key lacks required permissions |
| 404 | Not Found — resource doesn't exist |
| 409 | Conflict — duplicate resource |
| 429 | Too Many Requests — rate limit exceeded |
| 500 | Internal Server Error |
SDK Error Classes
import { GatewayError, GatewayAuthError, GatewayRateLimitError } from '@assistant-billing/sdk';
| Class | Status | Properties |
|---|
GatewayError | Any | message, status, code?, requestId? |
GatewayAuthError | 401 | message, requestId? |
GatewayRateLimitError | 429 | message, 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);
}
}