# Examples

> Every page of these docs is also plain Markdown, listed at https://subliss.app/developers/llms.txt for AI tools.

Requests for the jobs people do most with the Subliss API. Put your own key where they say `sbl_your_key`, or keep it in an environment variable called `SUBLISS_KEY` for the JavaScript ones.

## Check a key works

```bash
curl https://api.subliss.app/v1/me \
  -H "Authorization: Bearer sbl_your_key"
```

## The newest subliminals in a category

```bash
curl "https://api.subliss.app/v1/tracks?category=healing&limit=5" \
  -H "Authorization: Bearer sbl_your_key"
```

The category can be a key or a label from `GET /categories`, so `healing` and `Healing` both work.

## Every subliminal by one creator

Read one page at a time until `next_offset` is `null`:

```js
const all = [];
let offset = 0;
while (offset !== null) {
  const res = await fetch(
    `https://api.subliss.app/v1/tracks?creator=maya&limit=100&offset=${offset}`,
    { headers: { Authorization: `Bearer ${process.env.SUBLISS_KEY}` } },
  );
  const page = await res.json();
  all.push(...page.tracks);
  offset = page.next_offset;
}
```

## New subliminals since your last check

Send the `published_at` of the newest subliminal you have, and drop any `id` you already hold:

```js
async function newSince(lastSeen, seenIds) {
  const url = new URL('https://api.subliss.app/v1/tracks');
  url.searchParams.set('published_after', lastSeen);
  url.searchParams.set('limit', '100');
  const res = await fetch(url, {
    headers: { Authorization: `Bearer ${process.env.SUBLISS_KEY}` },
  });
  const { tracks } = await res.json();
  return tracks.filter((track) => !seenIds.has(track.id));
}
```

## Waiting when you reach the limit

A key can make 60 requests a minute. This waits for the seconds in `Retry-After` and tries again:

```js
async function getWithRetry(url) {
  for (;;) {
    const res = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.SUBLISS_KEY}` },
    });
    if (res.status !== 429) return res;
    const seconds = Number(res.headers.get('Retry-After') ?? 60);
    await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
  }
}
```

## Every endpoint and code

[Endpoints](https://subliss.app/developers/endpoints.md) lists every parameter and field, and [Errors](https://subliss.app/developers/errors.md) lists every code.
