VrexAPI Docs

Error Codes

Complete reference of API error codes and their meanings. All errors follow a consistent response shape.

Error Format

Every error response from the API includes an error object with a machine-readable code and a human-readable message. Always branch on code — messages may change between releases.

400Example validation error
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Field 'voice_id' is required"
  }
}

Error Code Reference

CodeHTTPDescription
INVALID_JSON400Request body is not valid JSON
VALIDATION_ERROR400Input validation failed
TEXT_TOO_LONG400Text exceeds maximum length for endpoint
UNAUTHORIZED401Missing or invalid API key
KEY_EXPIRED401API key has expired
KEY_REVOKED401API key has been revoked
INSUFFICIENT_BALANCE402Not enough balance for this request (TTS / music)
INSUFFICIENT_BALANCE_FOR_IMAGE402Not enough balance for an image generation
INSUFFICIENT_BALANCE_FOR_VIDEO402Not enough balance for a video generation
FORBIDDEN403Insufficient permissions
NOT_FOUND404Requested resource not found
RATE_LIMITED429Rate limit exceeded
ENGINE_ERROR502TTS engine unavailable or failed
SERVICE_UNAVAILABLE503Service temporarily unavailable

Handling Errors

Use the code field for programmatic branching. Treat 5xx errors as transient and retry with exponential backoff.

async function synthesize(text, voiceId) {
  try {
    const response = await fetch("https://getvrex.com/api/v1/tts", {
      method: "POST",
      headers: {
        "Authorization": "Bearer sk-...",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ text, voice_id: voiceId, format: "mp3" }),
    });

    if (!response.ok) {
      const { error } = await response.json();
      // Use error.code for programmatic handling
      if (error.code === "INSUFFICIENT_BALANCE") {
        throw new Error("Out of balance — please top up your account");
      }
      if (error.code === "RATE_LIMITED") {
        const retryAfter = response.headers.get("Retry-After");
        throw new Error(`Rate limited. Retry in ${retryAfter}s`);
      }
      throw new Error(error.message);
    }

    return response.arrayBuffer();
  } catch (err) {
    console.error("TTS request failed:", err);
    throw err;
  }
}
API Documentation — Vrex