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

# Authenticate

> Get an access token and authenticate API requests.

## Before you begin

You need your OAuth client ID and client secret.
The API base URL is `https://api.kapa.energy`.

## Get an access token

Set `KAPA_CLIENT_ID` and `KAPA_CLIENT_SECRET` in your environment, then send a client credentials request:

```bash theme={null}
curl --request POST 'https://api.kapa.energy/token' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode "client_id=$KAPA_CLIENT_ID" \
  --data-urlencode "client_secret=$KAPA_CLIENT_SECRET"
```

The response includes `access_token`, `token_type`, and `expires_in`.
Set `KAPA_ACCESS_TOKEN` to the returned access token. Request a new token when it expires.

## Authenticate requests

Send `Authorization: Bearer <access_token>` with every request except `POST /token`.
Use the token to [read battery information](https://docs.kapa.energy/connect/index.md).

## Errors

Token requests return OAuth errors as JSON. A `400` response indicates an invalid token
request, such as an unsupported grant type. A `401` response with `invalid_client`
indicates an unknown client or an incorrect secret.

Other API endpoints return `401` with the Problem Details code `unauthorized` when
your token is missing, invalid, or expired. Request a new token when it expires.


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