# Add the Arena54 directory to this project

Goal: Show games made in Africa, and the people who make them, in this project, read from the Arena54 directory API.

You are a coding agent working inside my project. Do the work. Do not ask me anything you can find out by reading the project. Do not invent an endpoint, a field or an error code that is not written below.

## 1. Look at the project first

- Find the framework and language, how the project is run and tested, and the page or screen that should list games or creators, and the server code that can fetch for it.
- Find how the project reads configuration and environment variables, and which files git ignores.
- Any backend will do. Use the HTTP client the project already has. If the project has no server code at all, stop and tell me: this key must not reach a browser.
- Tell me in two or three lines what you found and what you will change, then carry on.

## 2. The contract

Base URL: `https://developers.arena54.com/api/v1` (called $BASE below).

Every answer is JSON in one envelope:

```json
{ "success": true, "data": …, "meta": { "request_id": "req_…", "mode": "test" } }
{ "success": false, "error": { "code": "…", "message": "…" }, "meta": { "request_id": "req_…", "mode": "test" } }
```

Branch on `error.code`. Show `error.message` to a person; it is written for them. Log `meta.request_id` with any failure.

A list also carries `meta.total` and `meta.next_cursor`: send that back as `cursor` for the next page; null means the end. `limit` is 1 to 100, 20 by default; a value outside that is ignored. A filter value the directory does not know returns an empty list with 200, and a cursor it cannot read returns the first page. When a key is not accepted, `meta.mode` is null.

Calls. You need only the ones the steps name; the rest are here in case the page needs them:

- GET /games: Published games, featured first, then newest.
    - genre: A genre key from /genres.
    - platform: A platform key, such as android, ios, web, windows.
    - set_in: A city slug the game is set in, such as ibadan. Where the game happens, which may differ from where its maker is.
    - country: Two-letter country code of the maker.
    - stage: in_development, early_access or released.
    - creator: The maker’s handle.
    - q: Words to find in the title, pitch or maker’s name.
    - limit: Rows per page, 1 to 100. Default 20.
    - cursor: The next_cursor from the page before.
- GET /games/{slug}: One game, with its description, screenshots, links and credits.
    - slug: The game’s slug, from a list row.
- GET /creators: Studios and people: developers, artists, composers.
    - kind: studio or person.
    - role: A role key, such as developer, artist, composer.
    - country: Two-letter country code.
    - city: A city slug from /cities.
    - q: Words to find in the name, handle, pitch or city.
    - limit: Rows per page, 1 to 100. Default 20.
    - cursor: The next_cursor from the page before.
- GET /creators/{handle}: One creator, with their bio, links and games.
    - handle: The creator’s handle, from a list row.
- GET /countries: Countries that have listings, with how many creators and games each has.
    - empty: true also returns countries with no listings yet, so you get all 54.
    - limit: Rows per page, 1 to 100. Default 20.
    - cursor: The next_cursor from the page before.
- GET /countries/{code}: One country and its cities.
    - code: Two-letter country code.
- GET /cities: Cities that have creators, biggest first.
    - country: Two-letter country code.
    - limit: Rows per page, 1 to 100. Default 20.
    - cursor: The next_cursor from the page before.
- GET /genres: Every genre key and name, with how many games carry it.
- GET /events: Jams, meetups, tournaments, showcases and conferences.
    - kind: jam, meetup, tournament, showcase or conference.
    - country: Two-letter country code.
    - upcoming: true returns only events that have not started.
    - limit: Rows per page, 1 to 100. Default 20.
    - cursor: The next_cursor from the page before.
- GET /search: Games, creators and countries matching a word. At least two characters.
    - q: What to look for.

One row of `data` from /games, exactly as a test key returns it:

```json
{
  "slug": "sample-danfo-dash",
  "title": "Sample Danfo Dash",
  "tagline": "Sample data: not a real game",
  "cover_url": null,
  "genres": [
    "racing",
    "arcade"
  ],
  "platforms": [
    "android",
    "ios"
  ],
  "set_in": [
    "lagos"
  ],
  "stage": "released",
  "release_year": 2025,
  "featured": false,
  "creator": {
    "handle": "sample-baobab-games",
    "name": "Baobab Sample Games"
  },
  "country_code": "NG",
  "city": "Lagos",
  "url": "https://arena54.com/g/sample-danfo-dash",
  "created_at": "2025-06-01T09:00:00.000Z"
}
```

A row from /genres is `{ key, name, games }`. A row from /countries is `{ code, name, slug, region, creators, games }`.

Keys:

- A test key starts `a54_test_`, works at once and returns sample rows. Build with this one.
- A live key starts `a54_live_` and returns the real directory. It needs approval; swapping it in changes nothing else.
- Send it as `Authorization: Bearer <key>`. Read it from the environment variable `ARENA54_API_KEY`, on the server only. Never put it in client code, in a game build, or in a commit.

Limits: an accepted call answers with `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (seconds) and `X-Arena54-Plan`. A refusal may carry none of them; a 429 carries `Retry-After` in seconds. Live keys only: `X-Quota-Limit` and `X-Quota-Remaining`.

Refusals:

- 401 missing_key: There is no Authorization header, or what follows “Bearer” is not shaped like an Arena54 key.
- 401 invalid_key: The key is shaped like one but is unknown, revoked, or past its grace period after a rotation.
- 404 not_found: No endpoint, game, creator or country lives at that address.
- 403 plan_required: The key’s plan does not include this endpoint. The message names the plan that does.
- 429 rate_limited: The key has made too many calls this minute. Retry-After says how long to wait.
- 429 quota_exceeded: The key’s plan has used its calls for the day or the month. Retry-After says how long until it resets.
- 503 api_unavailable: The API is switched off for a while. Try again later.

## 3. Do this, in order

1. If the project already has an Arena54 client or key variable, reuse it. Otherwise add ARENA54_API_KEY to the project’s environment example file with an empty value, and read it only in server code, loaded the way the project already loads its environment.
2. Write one small server-side client: a function that takes a path and query, sends the key, returns `data` and `meta` on success, and throws an error carrying `error.code`, `error.message` and the Retry-After header on failure.
3. Use it to fetch the first page of /games and render title, tagline, genres, platforms, the creator’s name and the game’s `url` as a link. Make the page size a setting, 12 by default.
4. Add paging with `meta.next_cursor`: a “More” control that sends it back as `cursor`. A plain link to the next page is enough. Stop when it is null.
5. Add one filter the page needs (genre or country), using the keys /genres or /countries return. Many genres have no games yet; show the count or hide the empty ones.
6. Cache answers for at least 60 seconds on the server, so a busy page does not spend the minute’s calls. Keep the last good answer after that too, to show when a call is refused.

## 4. Prove it works

Set `BASE=https://developers.arena54.com/api/v1` and `ARENA54_API_KEY` to my test key. If I have not given you a key, ask me for a TEST key once, and for nothing else.

- Run: `curl "$BASE/games?limit=2" -H "Authorization: Bearer $ARENA54_API_KEY"`. Expect HTTP 200, `"success": true`, two rows whose titles start with “Sample”, and `"mode": "test"`.
- Run the same call with no header. Expect HTTP 401 and `"code": "missing_key"`.
- Open the page in the project. It shows the sample games. A test key has only 5 sample games, so set the page size to 2 to see “More” work through three pages.

Show me the output of each check.

## 5. Rules you must not break

- The key never reaches a browser, a game build or a commit.
- On 401, show that the key is wrong or missing. Do not retry automatically.
- On 403 `plan_required`, show the message; it names the plan that includes the call. Do not retry.
- On 429, wait for `Retry-After` seconds before the next call, and never retry in a tight loop.
- On 429 or 503, show a “try again later” line and keep showing the last good answer, even past its cache time.
- Show only what the API returned. Do not make up games, people or ranks.

## 6. Done when

- The key is read from the environment on the server and appears in no client bundle and no commit.
- The page lists games with paging and one filter.
- A 401, 403, 429 and 503 each show a plain message and never a stack trace.
- The two curl checks give the answers above.

Then give me a short list of the files you changed and anything I must do by hand.

For a person, not needed for this task: https://developers.arena54.com/docs/reference · This prompt: https://developers.arena54.com/prompts/directory.server.md
