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
| Code | Status | Description | How to Fix |
|---|---|---|---|
200 | OK | Request succeeded | — |
400 | Bad Request | Malformed request body or missing required fields | Check request body format and required parameters |
401 | Unauthorized | Invalid or missing API key | Verify your API key at /settings |
402 | Insufficient Credits | Account does not have enough credits | Purchase credits at /billing |
404 | Not Found | Model or resource not found | Check the model slug against available models |
429 | Rate Limited | Too many requests in the time window | Wait and retry with backoff. See Rate Limits |
500 | Server Error | Internal server error | Try 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.