# Authentication - MagicSlides API

> Learn how to authenticate with the MagicSlides API using your access ID.

Source: https://www.magicslides.app/docs-api/auth
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

---
# Authentication

The MagicSlides API supports two authentication methods: API key authentication (recommended) and email/accessId authentication (for backward compatibility).

## API Key Authentication (Recommended)

API key authentication is the recommended method for all new integrations. It provides better security and easier management.

### Getting Your API Key

1.  Log in to your MagicSlides dashboard
2.  Navigate to `/dashboard/settings`
3.  Generate a new API key
4.  Copy your API key (format: `ms-api-{base64-encoded-payload}.{secret}`)

### Using Your API Key

Include your API key in the request body using the `apiKey` parameter.

```json
{
  "apiKey": "ms-api-your-api-key-here",
  "topic": "Artificial Intelligence",
  "template": "bullet-point1",
  "slideCount": 10
}
```

## Email and AccessId (Backward Compatibility)

For backward compatibility, you can still use email and accessId authentication. However, we recommend migrating to API key authentication.

### Getting Your Access ID

You can find your access ID in your MagicSlides dashboard under API Settings.

### Using Email and AccessId

Include both `email` and `accessId` in the request body.

```json
{
  "topic": "Artificial Intelligence",
  "email": "your-email@example.com",
  "accessId": "your-access-id-here"
}
```

## Authentication Priority

If both `apiKey` and `email`/`accessId` are provided, the API key will be used.

## Security Best Practices

-   Keep your API key and access ID secure and never share them publicly
-   Use environment variables to store credentials in your applications
-   Never commit API keys or access IDs to version control
-   Rotate your API keys periodically for enhanced security
-   Monitor your API usage regularly for any unauthorized access
-   Use API key authentication for better security and tracking

## Error Handling

If authentication fails, the API will return a 401 Unauthorized response:

```json
{
  "status": "failed",
  "message": "Invalid API key",
  "error": {
    "field": "apiKey",
    "message": "Invalid API key",
    "code": "AUTH_ERROR"
  }
}
```

For deprecated endpoints, the error format may use `success: false` instead of `status: "failed"`.
