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

# Client API

> The three calls a signed-in person's app can make, the headers they need, CORS, limits and the errors a device can meet.

The client API is what a signed-in person's app calls. It is a separate surface from the one your server uses with a project key.

## The three calls

| Call | Method | Path | What it does |
| - | - | - | - |
| `client.balances` | `GET` | `/v1/client/balances` | The person's balances, one entry per unit. Units at 0 are left out. |
| `client.receipts` | `GET` | `/v1/client/receipts` | The person's own receipts, newest first. |
| `client.send_event` | `POST` | `/v1/client/events` | An event from the app, if the project listed its name. |

Receipts take `limit` (1 to 200), `cursor`, `unit`, `cause` (`spend`, `use`, `send` or `receive`), `since` and `until`. A receipt shows each unit it changed, the change and the balance after. `since` never goes earlier than the point from which the person's receipts are shown: see [Linking people](https://docs.getlurk.com/end-user-auth/linking-people.md#receipts-a-device-sees).

An event has an `event` name, optional `properties` and a required `idempotency_key` (1 to 255 characters) in the body. The same key with the same request returns the first answer and changes nothing. The answer lists the receipts the event made, if any.

## Headers

| Header | Value |
| - | - |
| `Authorization` | `Bearer <the token from your sign-in provider>`. The only credential. |
| `Lurk-Project` | Your project ID, `prj_…`. Required on every call. It is not a secret. Where to find it: [Before you start](https://docs.getlurk.com/end-user-auth/overview.md#before-you-start). |
| `Content-Type` | `application/json` on a POST. |
| `Idempotency-Key` | Optional, on an event only. The body's `idempotency_key` is still required. If you send the header too, Lurk uses the header's key. |
| `traceparent` | Optional. Joins your trace to ours. |

The API address is `https://api.getlurk.com`, for projects made at app.getlurk.com, both Staging and Production. `Lurk-Project` picks the project.

```bash title="Read the balances of the signed-in person" theme={null}
export LURK_API_URL="https://api.getlurk.com"
curl "$LURK_API_URL/v1/client/balances" \
  -H "Authorization: Bearer $SIGN_IN_TOKEN" \
  -H "Lurk-Project: prj_your_project_id"
```

Rules for the credential:

* Only `Authorization: Bearer` is read. Never the query, the body or a cookie.
* A project key (a bearer that starts with `lurk_`) is refused here. So is a request that has a member's session cookie next to a bearer.
* No call names a person. The person comes from the token, and the project from `Lurk-Project`.
* Lurk never sets a cookie on this surface.

## Browsers and CORS

A browser can call the client API from any origin. Lurk echoes the request's `Origin`, and never sends `Access-Control-Allow-Credentials`, because the bearer is the credential and no cookie is used. Preflight requests are answered and are not counted against the limits.

| CORS | Value |
| - | - |
| Methods | `GET`, `POST`, `OPTIONS` |
| Allowed request headers | `Authorization`, `Content-Type`, `Idempotency-Key`, `Lurk-Project`, `traceparent` |
| Exposed response headers | `Request-Id`, `traceparent`, `RateLimit`, `RateLimit-Policy`, `Retry-After` |
| Preflight cached for | 600 seconds |

A request body can be at most 16 KB.

## What an event may carry

* The name must be on the project's list. The list is empty by default, and an owner or admin saves it in the dashboard, under Settings > Sign-in, in **Events people’s apps may send**. Some names can never be on it, such as names for payments or for a chat connector.
* Each name lists the properties it takes, and each has a type and a clamp (text up to a length, a number in a range, or true or false). The list is empty by default, so a device sends the name and nothing else. A property that is not on the list, or a value outside its clamp, refuses the event with 422 `validation_failed`. So does a null, a list or an object. Properties are at most 4,096 bytes in all, and no rule reads them.
* The event is recorded for the signed-in person only, with `untrusted` as its source and the server's clock.
* The project sets a daily cap per person, a daily cap for the project and a limit on new people per hour.

## Limits

Counted by each API instance.

| What | Limit |
| - | - |
| Calls from one address | 300 a minute |
| Refusals to one address (401, 403, and 422 that names a field) | 30 a minute |
| Reads for one person (`client.balances` plus `client.receipts`) | 60 a minute |
| Events for one person | 30 a minute |
| Reads for one project | 6,000 a minute |
| Events for one project | 3,000 a minute |

An IPv6 address counts as its /64. Device traffic has its own limits and does not use up the ones your server's key has. A response carries `RateLimit` headers.

## Errors

Every error has the shape of the [errors page](https://docs.getlurk.com/errors.md).

| Status | Code | When |
| - | - | - |
| 401 | `invalid_key` | Every refusal of the credential: no bearer, a key or a cookie next to it, a token that fails any check, an unknown, paused or archived issuer, an unknown project. The message is always "The sign-in token was not accepted." and never says why. Ask the person to sign in again. |
| 403 | `forbidden` | The person is blocked, or the event name is not one this device may send. |
| 409 | `idempotency_conflict` | The idempotency key was used with a different request. |
| 422 | `validation_failed` | `Lurk-Project` is missing or is not a project ID (the field is named), a field is wrong, or the body is over 16 KB. |
| 429 | `rate_limited` | A limit above, a daily cap, or the new-people limit. Wait `Retry-After` seconds. |
| 503 | `unavailable` | The sign-in could not be checked now, or the provider's keys could not be fetched. Wait `Retry-After` seconds. |

A 401 is the same whether the token is expired, signed by the wrong key or aimed at another audience. To learn which, test the token with the [token test](https://docs.getlurk.com/end-user-auth/linking-people.md#test-a-token) or see [Troubleshooting](https://docs.getlurk.com/end-user-auth/troubleshooting.md).

A 429 and a 503 are safe to retry. For an event, retry with the same `idempotency_key`.

## The client package

`@getlurk/client` is a small typed client for these three calls. It is **not published**. It is a private package in the Lurk repository, and you cannot install it from a registry. Use `fetch` and the table of calls on this page until it is.


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