# Lỗi và giới hạn yêu cầu

> Hướng dẫn này chưa được dịch. Phiên bản tiếng Anh được hiển thị bên dưới. [Đọc bản gốc tiếng Anh](https://docs.helixvoice.net/en/api/errors/)

Handle HTTP errors, key permissions, and layered request budgets.

The developer API uses HTTP status codes. Successful JSON requests return `data`; deletions return 204 without a body. Audio downloads return WAV bytes.

## Check responses

This JavaScript example runs on your server, with the key stored in the server environment:

```js
const response = await fetch("https://api.helixvoice.net/v1/voices", {
  redirect: "error",
  headers: { Authorization: `Bearer ${process.env.HELIXVOICE_API_KEY}` },
});
if (!response.ok) throw new Error(`Voice API failed: ${response.status}`);
const { data: voices } = await response.json();
```

A backend error has this shape:

```json
{
  "error": {
    "code": "invalid_api_key",
    "message": "A valid, unexpired API key is required.",
    "requestId": "request-id"
  }
}
```

Gateway errors may use HTML or another format. Check status and Content-Type before parsing JSON or saving WAV bytes. Anonymous preview errors use a separate response format.

## Common HTTP statuses

| Status          | Code                  | Action                                                         |
| --------------- | --------------------- | -------------------------------------------------------------- |
| 400 / 413 / 415 | `invalid_request`     | Correct the JSON, fields, language, file size, or Content-Type |
| 401             | `invalid_api_key`     | Supply a valid, unexpired, unrevoked production key            |
| 403             | `insufficient_scope`  | Obtain a key with the required scope                           |
| 404             | `not_found`           | Check the endpoint, ownership, retention, or deletion          |
| 405             | `method_not_allowed`  | Use the documented HTTP method                                 |
| 429             | `rate_limit_exceeded` | Honor `Retry-After` and check all applicable budgets           |
| 502 / 503 / 504 | `service_unavailable` | Handle temporary unavailability and avoid duplicate work       |
| 500             | `internal_error`      | Keep the request ID and contact your service administrator     |

## Understand the limits

Each key has a fixed UTC minute request limit and a fixed UTC day request limit. Every authorized request reaching an endpoint counts, including lists, downloads, cached generation requests, and requests that subsequently fail input validation or upstream processing. Missing/invalid keys, insufficient permissions, and requests rejected by the key limit do not consume another key budget. A minute or daily key limit returns 429 and `Retry-After`.

Key limits are additional to the existing account speech-operation and shared service limits. Creating multiple keys cannot bypass account or global budgets. Account daily reset follows the service's configured timezone, which can differ from the key's UTC reset.

Generation, transcription, and voice creation share the account operation budget; failed upstream attempts also count. Listing, downloading, and deleting do not consume that operation budget, but still count as key requests. Cached generation requests count toward request rates. Shared concurrency can produce 429 while other budgets remain.

Anonymous previews have a separate shared quota.

## Retry deliberately

Wait for `Retry-After` when present. Use bounded backoff for temporary failures. Do not automatically retry 400, 401, or 403. Generation and voice creation do not provide an idempotency-key contract; retries can repeat work and consume quota.

## Request identifiers

Keep `X-Request-ID`, or `error.requestId` for backend errors, along with the timestamp, endpoint, and status. Do not share API keys or private recordings in diagnostic messages.
