# Nova AI - Error Handling

Learn how to handle errors gracefully when working with the Nova AI API.

## Error Response Format

When an error occurs, the API returns a structured JSON response:

```json
{
  "error": {
    "message": "The model 'invalid-model' does not exist.",
    "type": "invalid_request_error",
    "param": "model",
    "code": "model_not_found"
  }
}
```

### Fields

- **message**: Human-readable description.
- **type**: Error category (e.g., `invalid_request_error`, `authentication_error`).
- **param**: The parameter that caused the error (optional).
- **code**: Specific error code (e.g., `model_not_found`).

---

## HTTP Status Codes

| Status | Description |
|:---|:---|
| **200 OK** | Request successful |
| **400 Bad Request** | malformed request or invalid parameters |
| **401 Unauthorized** | Invalid or missing API key |
| **402 Payment Required** | Insufficient credits |
| **403 Forbidden** | Valid key but insufficient permissions |
| **404 Not Found** | Resource does not exist |
| **429 Too Many Requests** | Rate limit exceeded |
| **500 Server Error** | Unexpected server error |

---

## Common Error Codes

| Code | Description | Fix |
|:---|:---|:---|
| `invalid_api_key` | Invalid/malformed key | Check key format |
| `missing_api_key` | No key provided | Add Authorization header |
| `model_not_found` | Model doesn't exist | Use valid model ID |
| `rate_limit_exceeded` | Too many requests | Wait and retry |
| `insufficient_balance` | Low balance | Top up account |
| `uncensored_policy_required` | Policy not accepted | Accept policy in dashboard |
| `detailed_logging_required` | Logging disabled | Enable detailed logging |

## Handling Errors (JavaScript Example)

```javascript
try {
  const response = await fetch('https://novaaiapi.nabzclan.vip/v1/chat/completions', { ... });
  
  if (!response.ok) {
    const error = (await response.json()).error;
    console.error(`Error ${response.status}: ${error.message}`);
  }
} catch (e) {
  console.error("Network error:", e);
}
```

For full documentation, visit: https://nova-ai.nabzclan.vip/user/developer/docs/errors