Error Codes

The API uses standard HTTP status codes to indicate success or failure. All error responses include a JSON body with details.

Error Response Format

JSON
{
  "error": {
    "message": "Invalid API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}

HTTP Status Codes

CodeStatusDescriptionHow to Fix
200
OKRequest succeeded
400
Bad RequestMalformed request body or missing required fieldsCheck request body format and required parameters
401
UnauthorizedInvalid or missing API keyVerify your API key at /settings
402
Insufficient CreditsAccount does not have enough creditsPurchase credits at /billing
404
Not FoundModel or resource not foundCheck the model slug against available models
429
Rate LimitedToo many requests in the time windowWait and retry with backoff. See Rate Limits
500
Server ErrorInternal server errorTry again later. If persistent, contact support

Error Handling in Code

Using the Railwail SDK, all errors are thrown as RailwailError instances with structured properties.

TypeScript
import railwail, { RailwailError } from "railwail";

const rw = railwail("rw_live_xxxxx");

try {
  await rw.run("gpt-4o", "Hello!");
} catch (err) {
  if (err instanceof RailwailError) {
    console.error(err.status);   // HTTP status code
    console.error(err.type);     // Error category
    console.error(err.code);     // Specific error code
    console.error(err.message);  // Human-readable message
  }
}
See the RailwailError reference for more details on error handling in the SDK.