Skip to main content
The API uses standard HTTP status codes and returns errors in a consistent JSON format.

Error format

All errors return a JSON body with a message field:
{
  "message": "Error message describing what went wrong"
}
Validation errors include additional detail:
{
  "message": "Validation failed",
  "errors": [
    { "field": "tool", "message": "Required", "code": "invalid_type" }
  ]
}

Status codes

Client errors (4xx)

StatusNameWhen it happens
400Bad RequestInvalid JSON, missing fields, invalid values, unknown fields
401UnauthorizedMissing or invalid API key
402Payment RequiredNot enough credits
403ForbiddenTrying to access another user’s resource
404Not FoundInvalid endpoint, tool, model, or generation ID
429Too Many RequestsRate limit exceeded

Server errors (5xx)

StatusNameWhat to do
500Internal Server ErrorRetry after a few seconds
502Bad GatewayRetry after a few seconds
503Service UnavailableService is temporarily down, retry later

Handling errors

const generate = async (tool, input) => {
  const response = await fetch('https://api.artificialstudio.ai/api/run', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'YOUR_API_KEY'
    },
    body: JSON.stringify({ tool, input })
  });

  if (!response.ok) {
    const error = await response.json();

    switch (response.status) {
      case 401:
        throw new Error('Invalid API key');
      case 402:
        throw new Error('Insufficient credits');
      case 429:
        throw new Error('Rate limit exceeded. Retry later.');
      default:
        throw new Error(error.message || 'Request failed');
    }
  }

  return response.json();
};

Common errors and solutions

Invalid API key (401)

{ "message": "Authorization header is required" }
Check that your API key is correct and included in the Authorization header. Do not use the Bearer prefix.

Insufficient credits (402)

{ "message": "You do not have enough credits to perform this action" }
Add credits at Account Settings.

Tool not found (404)

{ "message": "Tool not found" }
Verify the tool slug. Use GET /api/tools to list available tools.

Rate limit exceeded (429)

{ "message": "Too many API requests, please try again later" }
Wait before retrying. See rate limits for details on your plan’s limits.

Validation error (400)

{
  "message": "Validation failed",
  "errors": [
    { "field": "tool", "message": "Required", "code": "invalid_type" }
  ]
}
Check the required parameters for your tool. The API rejects unknown fields — only send documented parameters.