> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lite.sa/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication and environments

> Where to send API requests, how API keys and test mode work, and the retry and size limits every call shares.

Every call from your server to lite uses the same base URL and the same API key header. This page covers what all integrations share: the base URL, API keys, authentication errors, retries and limits.

## Base URL and test mode

| | |
| - | - |
| Base URL | `https://api.lite.sa`, for both test and live |
| Authentication | Your API key in the `x-api-key` header |
| Mode | Set by the key. A key that starts with `sk_sandbox_` works on test data. A key that starts with `sk_live_` moves real money. |

There is no separate sandbox URL and no mode header. To go live, swap the key once your live setup is ready: see [Go live](https://docs.lite.sa/guides/build-your-integration.md#9-go-live).

```bash theme={null}
curl "https://api.lite.sa/checkout-sessions/550e8400-e29b-41d4-a716-446655440000?with_config=false" \
  -H "x-api-key: $LITE_API_KEY"
```

Send only `x-api-key`. The API refuses a dashboard login token (`Authorization: Bearer …`), and it refuses a request that sends both headers.

## API keys

Create keys in the dashboard under **Settings → Developers → API Keys**. Select **Create API Key**, enter a name and a description, then select **Create**.

* **The dashboard shows the key once.** Copy it when it appears and store it on your server. Never put it in a website, an app or version control.
* **A key acts on its own business account** and can do everything the API allows there. Use a separate key for each system, so you can replace one without touching the others.
* **Keys don't expire.** To revoke a key, open it under **Settings → Developers → API Keys** and select **Delete API Key**. It stops working at once. Only the account owner and Admins can delete keys. To rotate a key, create a new one, deploy it, then delete the old one.
* **Leave out `x-business-account-id`.** Without it, the key acts on its own business account. Send it only to act on another business account your key has access to. Any other value returns `403`.

## Authentication errors

A missing or bad key gets `401` from lite's gateway, with a body that differs from the API's other errors:

```json theme={null}
{
  "error": "unauthorized",
  "reason": "MALFORMED_CREDENTIAL",
  "message": "Authentication failed - invalid or missing credentials",
  "correlationId": "7f3c2a9e-4b1d-4c8e-9f6a-2d5e8b1c0a47"
}
```

`reason` tells you what to fix:

| `reason` | Cause |
| - | - |
| `NO_CREDENTIALS` | The request has no `x-api-key` header. |
| `MALFORMED_CREDENTIAL` | The key doesn't start with `sk_live_` or `sk_sandbox_`. |
| `API_KEY_INVALID` | lite doesn't recognize the key, or lite revoked it. |
| `AUTH_TYPE_NOT_ALLOWED` | The request sent `Authorization: Bearer` instead of `x-api-key`. |
| `BOTH_CREDENTIALS` | The request sent both `Authorization` and `x-api-key`. |

If the authentication service is briefly unavailable, the gateway returns `503` with `Retry-After: 5`. Retry after that many seconds.

## Retries and duplicate requests

The create endpoints protect against retries in different ways:

| Endpoint | Header | Behaviour |
| - | - | - |
| `POST /payments` | `x-idempotency-key` | For 120 seconds, a repeat with the same key returns the first response, even if that was an error. lite doesn't compare the request bodies. Without the header, lite uses `order.reference` as the key. |
| `POST /payments/{id}/capture`, `/void`, `/refund` | `x-idempotency-key` | Send a new key for each operation, and the same key when you retry it. |
| `POST /checkout-sessions` | `idempotency-key`, without the `x-` | Only one unexpired session can exist per `order.reference`. See [One session per order](https://docs.lite.sa/guides/hosted-checkout-page.md#one-session-per-order). |

`order.reference` also guards against paying an order twice, with no time limit. If your account already has a payment for the same `order.reference` that isn't `FAILED`, `EXPIRED`, `VOIDED` or `AUTHORIZATION_REVERSED`, `POST /payments` returns that payment instead of creating a new one. Use a unique `order.reference` for each order.

## Limits

| Limit | What you get |
| - | - |
| Too many requests from one IP address in a short time | `429`. Slow down and retry with a growing delay. |
| A request body over 50 KB | `413` |
| Text fields containing markup or code-like text, such as a lone `<`, `<script>`, `select … from` or `../` | `403` with the reason "Forbidden - Security Violation" and an `X-Security-Block` header naming the rule |

The `403` filter reads the whole request body, so it can catch free-text fields such as product names, customer names, addresses and descriptions. Strip markup from them before you send them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.