# Error Handling - MagicSlides API

> Learn about error handling and troubleshooting in the MagicSlides API.

Source: https://www.magicslides.app/docs-api/errors
Format: Markdown via content negotiation (`Accept: text/markdown`). Site map for agents: https://www.magicslides.app/llms.txt · API: https://www.magicslides.app/openapi.json

---
# Error Handling

The MagicSlides API uses conventional HTTP response codes and provides detailed error messages to indicate the success or failure of requests.

## HTTP Status Codes

Status Code

Description

200 OK

The request was successful

400 Bad Request

The request was invalid or missing required parameters

401 Unauthorized

Invalid or missing access ID

403 Forbidden

The access ID is valid but lacks permission

429 Too Many Requests

Rate limit exceeded

500 Internal Server Error

An error occurred on our servers

## Error Response Format

When an error occurs, the API returns a JSON response with the following structure:

```json
{
  "success": false,
  "error": "A human-readable error message",
  "code": "ERROR_CODE",
  "details": {
    // Additional error details if available
  }
}
```

## Common Error Codes

AUTH\_ERROR

Authentication-related errors

INVALID\_PARAMS

Invalid or missing request parameters

RATE\_LIMIT\_ERROR

Rate limit exceeded

PROCESSING\_ERROR

Error during presentation generation

YOUTUBE\_ERROR

Error accessing or processing YouTube video

SERVER\_ERROR

Internal server error

## Error Examples

### Invalid Parameters

```json
{
  "success": false,
  "error": "Missing required parameter: topic",
  "code": "INVALID_PARAMS",
  "details": {
    "missing": ["topic"]
  }
}
```

### Authentication Error

```json
{
  "success": false,
  "error": "Invalid access ID provided",
  "code": "AUTH_ERROR"
}
```

### Rate Limit Error

```json
{
  "success": false,
  "error": "Rate limit exceeded",
  "code": "RATE_LIMIT_ERROR",
  "reset_at": 1678945200
}
```

## Error Handling Best Practices

-   Always check the success field in the response
-   Implement proper error handling for all API calls
-   Log error details for debugging purposes
-   Implement retries with exponential backoff for recoverable errors
-   Display user-friendly error messages in your application

## Example Implementation

```typescript
import axios, { AxiosError } from 'axios';

interface ApiError {
  success: false;
  error: string;
  code: string;
  details?: Record<string, any>;
}

async function handleApiRequest() {
  try {
    const response = await axios.post(
      'https://magicslides-tools-api.onrender.com/public/api/ppt_from_topic',
      {
        topic: 'AI in Healthcare',
        email: 'user@example.com',
        accessId: 'your-access-id'
      }
    );

    return response.data;
  } catch (error) {
    if (error instanceof AxiosError) {
      const apiError = error.response?.data as ApiError;

      switch (apiError.code) {
        case 'AUTH_ERROR':
          console.error('Authentication failed:', apiError.error);
          // Handle auth error (e.g., redirect to login)
          break;

        case 'RATE_LIMIT_ERROR':
          console.error('Rate limit exceeded:', apiError.error);
          // Implement retry logic
          break;

        case 'INVALID_PARAMS':
          console.error('Invalid parameters:', apiError.details);
          // Handle validation errors
          break;

        default:
          console.error('API error:', apiError.error);
          // Handle other errors
      }
    }

    throw error;
  }
}
```
