Admin API and AI agents
The Admin API creates and changes the events, missions, achievements and other elements that the GameLayer API uses. You can let Claude build a campaign, connect your own agent, or script changes. Every change is checked and audited, and shows in the dashboard straight away.
Ways to build#
- Claude on the web or in Claude Desktop. Add GameLayer as a connector and sign in. No code or keys. See Connect Claude.
- Claude Code, or any MCP client. GameLayer's MCP server is at
https://api.gamelayer.co/mcp. It accepts a sign-in or an Agent Key. See Connect Claude. - Your own agent or script over HTTP. Create an Agent Key and call the Admin API. The rest of this page covers this.
Each way follows the same rules, limits and audit log.
| GameLayer API | Admin API | |
|---|---|---|
| Base URL | https://api.gamelayer.co/api/v0 | https://api.gamelayer.co/admin/v0 |
| Authentication | api-key header with the Account API key | Authorization: Bearer glak.… with an Agent Key, or a dashboard sign-in |
| Reference | GameLayer API | Admin API |
The Account API key can't reach the Admin API, and an Agent Key can't call the GameLayer API.
Before you start#
- Agent access must be on for the account. GameLayer turns it on. Until then, the dashboard's Agent Keys section says Agent access is not enabled for this account. Contact GameLayer.
- You must be an account admin. Only account admins can create Agent Keys and approve Claude connections.
Agent Keys#
Create a key in the dashboard: open the account, go to Agent Keys and click Create key.
| Setting | Values |
|---|---|
| Scopes | config:read (read anything), config:write (create, update, plan and apply changesets), config:delete (delete and restore). Give a key only what it needs. |
| Expiry | 1 to 365 days |
| Rotation | Rotate issues a new secret. The old one keeps working for 0 to 24 hours, so you can swap it without downtime. |
| Limit | 10 active keys per account, Claude connections included |
A key looks like glak.<keyId>.<secret>, and the dashboard shows it once. Send it on every request:
Authorization: Bearer glak.<keyId>.<secret>A key belongs to one account. Any other account value is refused with 403 ACCOUNT_MISMATCH.
Store keys as server-side secrets, never in client code or a repository, and never log them. Revoke a key on the Agent Keys page as soon as you no longer need it; revoking takes effect within 60 seconds. Turning off agent access for the account stops every key and Claude connection within 60 seconds.
Discovery#
An agent can find everything on this page through the API itself. Every discovery route takes an Agent Key.
| Route | What it gives |
|---|---|
GET /admin/v0/llms.txt | A short index of every operation an Agent Key can call |
GET /admin/v0/guide | The agent guide: reading and writing safely, errors, limits, and how each element type behaves for players |
GET /admin/v0/context?account=<account> | The account's element limits and usage, its languages, and the key's scopes and expiry |
GET /admin/v0/schemas/<type>?mode=create|update|patch | The JSON Schema of each write |
GET /admin/v0/openapi.json | The full OpenAPI spec. Operations an Agent Key can call are marked x-agent-access: true. |
The element types are events, achievements, levels, quizzes, surveys, streaks, missions, leaderboards and prizes.
To generate a client without a key, use the public spec: Admin API reference, or download admin-api-spec.json.
For your own agent, a good system prompt is: "Before changing anything, read /admin/v0/guide and /admin/v0/context. Fetch the schema of each type before writing it."
Plan, review, apply#
Build a campaign as one changeset: up to 50 operations, checked as a whole and applied all or nothing.
- Read what exists. For example,
GET /admin/v0/missions?account=<account>&view=summarygives each element's ID, name, revision and the IDs it refers to, 100 a page. FollownextCursoruntil it'snull. - Plan.
POST /admin/v0/changesets/planchecks every operation as if all were applied, and writes nothing. A mission can refer to an event created in the same changeset. - Review. Show the plan to a person and wait for their confirmation. GameLayer's Claude prompts always do this.
- Apply. Send the same body with a
changesetIdyou choose toPOST /admin/v0/changesets/apply. Every operation is written in one transaction, or none.
Example#
Plan an achievement and an event that adds steps to it:
curl -s https://api.gamelayer.co/admin/v0/changesets/plan \
-H "Authorization: Bearer $GL_AGENT_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "Ten-workout badge",
"operations": [
{ "op": "create", "type": "achievements",
"data": { "id": "ten-workouts", "name": "Ten workouts", "steps": 10,
"requirement": {}, "reward": { "points": 100 } } },
{ "op": "create", "type": "events",
"data": { "id": "workout-done", "name": "Workout done",
"reward": { "points": 10, "achievements": [ { "id": "ten-workouts", "steps": 1 } ] } } }
]
}'The answer says whether the plan is valid. Each operation comes back with its errors (at paths such as /operations/1/data/reward), a diff and a one-line summary. Fix every error and plan again until valid is true. Then apply the same body with a changesetId:
curl -s https://api.gamelayer.co/admin/v0/changesets/apply \
-H "Authorization: Bearer $GL_AGENT_KEY" \
-H "Content-Type: application/json" \
-d '{ "changesetId": "ten-workout-badge-1", "description": "Ten-workout badge", "operations": [ … ] }'Once it's applied, your app can complete workout-done through the GameLayer API. After ten completions, the player completes Ten workouts.
Changeset rules#
- Operations are
create,update,patchanddelete. All exceptcreatetake the element'sidand theexpectedRevisionyou read. - A lost response is safe to retry. Send the same
changesetIdand body again. An applied changeset returns its stored result withX-Idempotent-Replay: trueand isn't applied twice. - A changed body needs a new
changesetId. They're unique per account, across every key. 409 CHANGESET_CONFLICTmeans an element changed after you read it, and nothing was applied. Read it again, plan again, and apply with a newchangesetId.
Single changes#
| To | Send |
|---|---|
| Create | POST /admin/v0/<type> with the complete element. You choose the id. |
| Read | GET /admin/v0/<type>/<account>/<id>. The answer carries ETag: "<revision>". |
| Replace | PUT /admin/v0/<type> with the complete element and If-Match: "<revision>" |
| Change part | PATCH /admin/v0/<type>/<account>/<id> with Content-Type: application/merge-patch+json and If-Match |
| Delete | DELETE /admin/v0/<type>/<account>/<id> with If-Match (needs config:delete) |
- Conflicts: if the element changed since you read it, a write is refused with
409 REVISION_CONFLICTandcurrentRevision, and nothing is written. - Dry run: add
?dryRun=trueto any write. Every check runs and nothing is written. - References: deleting an element that others refer to is refused with
409 ELEMENT_REFERENCED, which lists them.
Undo and history#
GET /admin/v0/audit?account=<account>&elementType=<type>&elementId=<id>lists every change, newest first, with who made it. For an update,priorValuesholds each changed field's previous value, so you can write it back.POST /admin/v0/<type>/<account>/<id>/restorebrings back a deleted element. It needsconfig:delete. Leaderboards and prizes can't be restored.
Errors and limits#
Every error has the same shape:
{ "error": "…", "errorCode": 0, "code": "…", "details": [ { "path": "…", "source": "…", "code": "…", "message": "…", "hint": "…" } ], "requestId": "…" }code names the problem, path points into your body, and hint says what to do. A write reports every problem it finds at once.
| Limit | Value |
|---|---|
| Reads | 600 a minute per key |
| Writes | 120 a minute per key. Each operation in an applied changeset counts as one write; a plan counts as one. |
| Changeset applies | 20 a minute per key |
| Operations per changeset | 50 |
Over a limit you get 429 with Retry-After. Wait that long, then retry. A successful write may carry an X-Agent-Warnings header: AGENT_KEY_EXPIRING means rotate the key soon.
What agents can't do#
Agent Keys can only change the game's configuration. These aren't available to them:
- players, teams and rules
- translations and voucher codes
- mystery boxes and raffles
- account settings and Agent Keys
An agent also can't delete or restore leaderboards and prizes, create voucher prizes, or change an existing level's ordinal. Use the dashboard for these.
MCP tools#
Over MCP, the same operations come as 14 tools:
| Tool | HTTP equivalent | Scope |
|---|---|---|
get_context | GET /context | config:read |
get_guide | GET /guide | config:read |
get_schema | GET /schemas/<type> | config:read |
list_elements | GET /<type> | config:read |
get_element | GET /<type>/<account>/<id> | config:read |
get_changeset | GET /changesets/<changesetId> | config:read |
list_audit | GET /audit | config:read |
create_element | POST /<type> | config:write |
update_element | PUT /<type> | config:write |
patch_element | PATCH /<type>/<account>/<id> | config:write |
plan_changeset | POST /changesets/plan | config:write |
apply_changeset | POST /changesets/apply | config:write |
delete_element | DELETE /<type>/<account>/<id> | config:delete |
restore_element | POST /<type>/<account>/<id>/restore | config:delete |
The server also offers two prompts:
plan_campaigntakes a goal, plans the whole campaign as one changeset, and applies it only after you confirm.review_accountreports problems in the setup, such as expired elements or missions pointing at missing ones. It changes nothing.