Developer Resources / Agents & MCP / Admin API and agents

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#

  1. Claude on the web or in Claude Desktop. Add GameLayer as a connector and sign in. No code or keys. See Connect Claude.
  2. 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.
  3. 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 APIAdmin API
Base URLhttps://api.gamelayer.co/api/v0https://api.gamelayer.co/admin/v0
Authenticationapi-key header with the Account API keyAuthorization: Bearer glak.… with an Agent Key, or a dashboard sign-in
ReferenceGameLayer APIAdmin 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.

SettingValues
Scopesconfig:read (read anything), config:write (create, update, plan and apply changesets), config:delete (delete and restore). Give a key only what it needs.
Expiry1 to 365 days
RotationRotate issues a new secret. The old one keeps working for 0 to 24 hours, so you can swap it without downtime.
Limit10 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:

HTTP
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.

RouteWhat it gives
GET /admin/v0/llms.txtA short index of every operation an Agent Key can call
GET /admin/v0/guideThe 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|patchThe JSON Schema of each write
GET /admin/v0/openapi.jsonThe 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.

  1. Read what exists. For example, GET /admin/v0/missions?account=<account>&view=summary gives each element's ID, name, revision and the IDs it refers to, 100 a page. Follow nextCursor until it's null.
  2. Plan. POST /admin/v0/changesets/plan checks every operation as if all were applied, and writes nothing. A mission can refer to an event created in the same changeset.
  3. Review. Show the plan to a person and wait for their confirmation. GameLayer's Claude prompts always do this.
  4. Apply. Send the same body with a changesetId you choose to POST /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
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
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, patch and delete. All except create take the element's id and the expectedRevision you read.
  • A lost response is safe to retry. Send the same changesetId and body again. An applied changeset returns its stored result with X-Idempotent-Replay: true and isn't applied twice.
  • A changed body needs a new changesetId. They're unique per account, across every key.
  • 409 CHANGESET_CONFLICT means an element changed after you read it, and nothing was applied. Read it again, plan again, and apply with a new changesetId.

Single changes#

ToSend
CreatePOST /admin/v0/<type> with the complete element. You choose the id.
ReadGET /admin/v0/<type>/<account>/<id>. The answer carries ETag: "<revision>".
ReplacePUT /admin/v0/<type> with the complete element and If-Match: "<revision>"
Change partPATCH /admin/v0/<type>/<account>/<id> with Content-Type: application/merge-patch+json and If-Match
DeleteDELETE /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_CONFLICT and currentRevision, and nothing is written.
  • Dry run: add ?dryRun=true to 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, priorValues holds each changed field's previous value, so you can write it back.
  • POST /admin/v0/<type>/<account>/<id>/restore brings back a deleted element. It needs config:delete. Leaderboards and prizes can't be restored.

Errors and limits#

Every error has the same shape:

JSON
{ "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.

LimitValue
Reads600 a minute per key
Writes120 a minute per key. Each operation in an applied changeset counts as one write; a plan counts as one.
Changeset applies20 a minute per key
Operations per changeset50

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:

ToolHTTP equivalentScope
get_contextGET /contextconfig:read
get_guideGET /guideconfig:read
get_schemaGET /schemas/<type>config:read
list_elementsGET /<type>config:read
get_elementGET /<type>/<account>/<id>config:read
get_changesetGET /changesets/<changesetId>config:read
list_auditGET /auditconfig:read
create_elementPOST /<type>config:write
update_elementPUT /<type>config:write
patch_elementPATCH /<type>/<account>/<id>config:write
plan_changesetPOST /changesets/planconfig:write
apply_changesetPOST /changesets/applyconfig:write
delete_elementDELETE /<type>/<account>/<id>config:delete
restore_elementPOST /<type>/<account>/<id>/restoreconfig:delete

The server also offers two prompts:

  • plan_campaign takes a goal, plans the whole campaign as one changeset, and applies it only after you confirm.
  • review_account reports problems in the setup, such as expired elements or missions pointing at missing ones. It changes nothing.