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

# Authentication

> Authenticate End Close API requests with your environment's secret API key in the X-API-Key header, and keep the key safe.

The End Close API authenticates every request with a secret API key sent in the `X-API-Key` header. The key also selects the environment: a Sandbox key reads and writes Sandbox data, and a Production key reads and writes Production data.

## Find your API key

Open the [End Close app](https://app.endclose.com) and go to **Settings > API keys**. Each environment has one key; switch environment to see the other.

| Environment | Key prefix |
| - | - |
| Sandbox | `sk_test_` |
| Production | `sk_live_` |

Build and test against Sandbox, then swap in the Production key when you go live.

> [!WARNING]
>
> API keys are secrets. Keep them out of client-side code, public repositories and anything else you share. Load them from an environment variable or a secrets manager.

## Send the key with each request

Put the key in the `X-API-Key` header. The examples read it from an `ENDCLOSE_API_KEY` environment variable.

```bash cURL theme={"dark"}
curl https://api.endclose.com/v1/reconciliations \
  -H "X-API-Key: $ENDCLOSE_API_KEY"
```

```javascript JavaScript theme={"dark"}
const response = await fetch("https://api.endclose.com/v1/reconciliations", {
  headers: { "X-API-Key": process.env.ENDCLOSE_API_KEY },
});
const body = await response.json();
```

```python Python theme={"dark"}
import os
import requests

response = requests.get(
    "https://api.endclose.com/v1/reconciliations",
    headers={"X-API-Key": os.environ["ENDCLOSE_API_KEY"]},
)
body = response.json()
```

```ruby Ruby theme={"dark"}
require "net/http"
require "json"

uri = URI("https://api.endclose.com/v1/reconciliations")
request = Net::HTTP::Get.new(uri)
request["X-API-Key"] = ENV.fetch("ENDCLOSE_API_KEY")

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
body = JSON.parse(response.body)
```

For requests with a body, also send `Content-Type: application/json`.

## Authentication errors

A request without a valid key gets `401 Unauthorized` and a JSON body with a `message`:

| Situation | Status | `message` |
| - | - | - |
| No `X-API-Key` header | `401` | `API Key header not provided.` |
| The key doesn't exist | `401` | `API Key invalid` |

Some endpoints that manage agents return `403 Forbidden` when called with a key other than your environment's API key. See [Errors](https://endclose.com/docs/api-reference/errors.md) for every status code.

## Related

> [card] [End Close API](https://endclose.com/docs/api-reference/overview.md)
>
> Base URL, environments and conventions.

> [card] [Errors](https://endclose.com/docs/api-reference/errors.md)
>
> Error responses and when to retry.


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