Developers

Building with AI agents on the Authmarks API: set-up, guardrails and workflows

A practical guide for teams, including university IT services, using coding agents with Authmarks: the context to give the agent, token guardrails, a sound set-up checklist, two worked workflows and rules for agents.

Published 2026-11-26 · 6 min read

Machine-readable APIhttps://www.authmarks.com/api/v1/openapi.json
Developer page indexhttps://www.authmarks.com/llms.txt
MCP endpointhttps://www.authmarks.com/api/mcp
AuthBearer token (amk_ organisation API token)
AccessRead-only

What this page gives you: a proven pattern for letting coding agents (Claude Code, Cursor, Copilot, Codex and others) safely build reports and checks on top of Authmarks. You will see which two URLs to give the agent, which instructions keep tokens out of prompts and repositories, a checklist for a sound set-up, two complete worked workflows, and a short set of rules addressed to agents themselves. As both the API and the MCP server are read-only, the most an agent can do with a properly scoped token is read data you have allowed it to read.

If you work in a UK university's IT services or learning technology team, check your institution's policy on AI tools before pointing an agent at data that includes student details. Under UK GDPR and the Data Protection Act 2018 your institution decides how such personal data may be processed, and Jisc also publishes guidance on AI in education.

Give the agent the right context

Agents write better code when they work from the real contract rather than guessing. Hand them two URLs:

URLWhat you will find there
https://www.authmarks.com/api/v1/openapi.jsonThe OpenAPI 3.1 document: each endpoint, parameter, field and error.
https://www.authmarks.com/llms.txtA plain-text index of all the developer pages, written for language models.

A sensible opening prompt:

We are building an internal report on top of the Authmarks REST API.
Read https://www.authmarks.com/api/v1/openapi.json and https://www.authmarks.com/llms.txt first.
The API is read-only. The token is in the AUTHMARKS_TOKEN environment variable and the
organisation id in AUTHMARKS_ORG. Never print, log or hard-code the token.

If your agent can use MCP as well, connect it by following the MCP setup so that it can explore real data while writing the code.

Guardrails to put in your agent instructions

Add these to the file your agent reads at the start of every run (CLAUDE.md, AGENTS.md, .cursor/rules, or whatever your tool uses):

## Authmarks API rules
- Base URL: https://www.authmarks.com/api/v1/orgs/$AUTHMARKS_ORG. Contract: https://www.authmarks.com/api/v1/openapi.json
- Read the token from the AUTHMARKS_TOKEN environment variable. Never ask for it, print it, log it,
  paste it into a prompt, write it to a file or commit it.
- Never put the token in browser or client-side code.
- The API is read-only (GET/HEAD). Do not write code that expects to change Authmarks data.
- Page with `limit` (max 200) and `next_cursor` until it is null. Never build cursors.
- On 429, wait the Retry-After seconds. Retry 503 with backoff. Do not retry 401/403.
- Treat student names and emails as personal data: do not print them in logs or test fixtures.
- Ids are opaque strings. Timestamps are ISO 8601 UTC.

Then give the agent a dedicated, read-only token with an expiry, holding only the scopes the task needs. See Authentication and scopes.

Healthy setup checklist

  • One token for each tool and each person (agent-cursor-jlee, report-nightly-ci), never a shared token.
  • Only the scopes the job calls for. Grant records_read only where student submissions are actually needed.
  • An expiry on every token an agent uses, as short as the job permits.
  • Tokens kept in environment variables or a secrets manager, never in code, prompts or chat.
  • .env listed in .gitignore, plus a secret-scanning rule for amk_[A-Za-z0-9_-]{43}.
  • A monthly check of last used under Settings → Developers, revoking any token nobody is using.
  • Rotation on a schedule, and whenever someone with access leaves.
  • A named owner for every scheduled job, recorded alongside the job.
  • If you stream the admin audit log to a SIEM, alerts on token creation and revocation (audit stream).

Workflow 1: nightly report of unsealed submissions

Aim: each night, list the submissions not yet sealed for assignments that fell due in the past seven days, and share the counts with your team (for example, a programme team or the module leaders concerned).

Token scopes: assignments_read, records_read.

The prompt for the agent:

Write a Python script, report_unsealed.py, that:
1. Lists all assignments (page through next_cursor, limit=200).
2. Keeps assignments whose due_at is within the last 7 days.
3. For each, lists all submissions and counts sealed vs not sealed.
4. Prints one line per assignment: title, due date, sealed count, unsealed count.
Use requests. Read AUTHMARKS_TOKEN and AUTHMARKS_ORG from the environment.
Honor Retry-After on 429. Do not print student emails.

A script of the kind the agent ought to produce:

import os
import time
from datetime import datetime, timedelta, timezone

import requests

BASE = f"https://www.authmarks.com/api/v1/orgs/{os.environ['AUTHMARKS_ORG']}"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['AUTHMARKS_TOKEN']}"


def pages(path):
    cursor = None
    while True:
        response = session.get(f"{BASE}{path}", params={"limit": 200, "cursor": cursor}, timeout=30)
        if response.status_code == 429:
            time.sleep(int(response.headers.get("Retry-After", "60")))
            continue
        response.raise_for_status()
        body = response.json()
        yield from body["data"]
        cursor = body["next_cursor"]
        if not cursor:
            return


def parse(ts):
    return datetime.fromisoformat(ts.replace("Z", "+00:00")) if ts else None


now = datetime.now(timezone.utc)
for assignment in pages("/assignments"):
    due = parse(assignment["due_at"])
    if due is None or not (now - timedelta(days=7) <= due <= now):
        continue
    sealed = unsealed = 0
    for submission in pages(f"/assignments/{assignment['id']}/submissions"):
        if submission["sealed"]:
            sealed += 1
        else:
            unsealed += 1
    print(f"{assignment['title']}\tdue {due:%Y-%m-%d}\tsealed {sealed}\tunsealed {unsealed}")

Run it on a schedule from CI, with the token held as an encrypted CI secret:

# .github/workflows/authmarks-nightly.yml
on:
  schedule: [{ cron: "0 6 * * *" }]
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pip install requests && python report_unsealed.py
        env:
          AUTHMARKS_TOKEN: ${{ secrets.AUTHMARKS_TOKEN }}
          AUTHMARKS_ORG: ${{ vars.AUTHMARKS_ORG }}

Workflow 2: LMS health check that alerts on failed grade returns

Aim: every 15 minutes, look for connections awaiting approval and for grade returns that failed within the past hour, and raise an alert if there are any. For a VLE team this is a simple way to spot a broken link to Moodle, Canvas or Brightspace before lecturers notice missing marks.

Token scope: lms_read and nothing else.

// lms-health.mjs  (Node.js 18+)
const BASE = `https://www.authmarks.com/api/v1/orgs/${process.env.AUTHMARKS_ORG}`;
const headers = { Authorization: `Bearer ${process.env.AUTHMARKS_TOKEN}` };
const since = Date.now() - 60 * 60 * 1000;

async function get(path) {
  const response = await fetch(`${BASE}${path}`, { headers });
  if (!response.ok) {
    throw new Error(`${path}: HTTP ${response.status}`);
  }
  return response.json();
}

const problems = [];
const connections = await get("/lms-connections");

for (const connection of connections.data) {
  if (connection.status === "pending") {
    problems.push(`${connection.label}: waiting for approval since ${connection.created_at}`);
  }
  if (connection.status !== "active") continue;

  // Do not assume an order: filter by time on every page.
  let cursor = null;
  do {
    const query = new URLSearchParams({ limit: "200" });
    if (cursor) query.set("cursor", cursor);
    const page = await get(`/lms-connections/${connection.id}/grade-returns?${query}`);
    for (const ret of page.data) {
      if (ret.status === "failed" && Date.parse(ret.created_at) >= since) {
        problems.push(`${connection.label}: grade return ${ret.id} failed at ${ret.created_at}`);
      }
    }
    cursor = page.next_cursor;
  } while (cursor);
}

if (problems.length > 0) {
  await fetch(process.env.ALERT_WEBHOOK_URL, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ text: `Authmarks LMS health:\n${problems.join("\n")}` }),
  });
  process.exitCode = 1;
}

ALERT_WEBHOOK_URL is a chat or paging webhook of your own (Slack, Teams, PagerDuty). How to fix failed returns is explained in Troubleshooting LTI and Grades and roster.

You can ask the same question interactively through MCP: "List grade returns that failed in the last hour for every active connection."

For agents: rules to follow

If you are an AI agent working with Authmarks, keep to these rules:

  1. Read https://www.authmarks.com/api/v1/openapi.json before you write any API code. Do not make up endpoints or fields.
  2. The API and the MCP server are read-only. Nothing can be created, changed or deleted through them, so do not try.
  3. Take the token only from the AUTHMARKS_TOKEN environment variable. Never print it, log it, echo it in shell commands, write it to a file, include it in a commit or ask the user to paste it into the conversation.
  4. Never put the token into browser, mobile or extension code.
  5. Send Authorization: Bearer <token>. Never put the token in a URL.
  6. Page using limit (1 to 200) and cursor until next_cursor is null. Never construct or alter cursors.
  7. On a 429, wait the number of seconds in Retry-After. Retry a 503 with backoff. Do not retry a 401 or 403; tell the user which scope or token is at fault.
  8. Handle student.name and student.email as personal data. Do not copy them into logs, fixtures, issues or summaries unless the user has asked for them.
  9. Treat ids as opaque strings and timestamps as ISO 8601 in UTC.
  10. The API returns no scores or percentages. Do not infer or describe any about a student's writing.
  11. If a scope is missing, tell the user which scope to add, and that tokens are created by an owner or admin under Settings → Developers.

Sources

Change notes

  • 2026-11-26 — First published.

Spotted an error? Email sales@authmarks.com and we will correct the page and date the correction.