Building with AI agents on the Authmarks API: setup, guardrails and workflows
A practical guide for teams using coding agents with Authmarks: what context to give the agent, guardrails for tokens, a healthy setup checklist, two example workflows and rules agents can follow.
Publié le 2026-11-26 · 6 min de lecture
| Machine-readable API | https://www.authmarks.com/api/v1/openapi.json |
|---|---|
| Developer page index | https://www.authmarks.com/llms.txt |
| MCP endpoint | https://www.authmarks.com/api/mcp |
| Auth | Bearer token (amk_ organisation API token) |
| Access | Read-only |
What you get: a working pattern for letting coding agents (Claude Code, Cursor, Copilot, Codex and others) build reports and checks on top of Authmarks safely. You will learn which two URLs to hand the agent, which instructions keep tokens out of prompts and repositories, a checklist for a healthy setup, two complete example workflows, and a short list of rules written for agents themselves. Because the API and the MCP server are read-only, the worst an agent can do with a correctly scoped token is read data you allowed it to read.
Give the agent the right context
Agents write better code when they read the real contract instead of guessing. Give them two URLs:
| URL | What it is |
|---|---|
https://www.authmarks.com/api/v1/openapi.json | The OpenAPI 3.1 document: every endpoint, parameter, field and error. |
https://www.authmarks.com/llms.txt | A plain-text index of every developer page, written for language models. |
A good 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 the agent can also use MCP, connect it with the MCP setup so it can explore real data while it writes the code.
Guardrails to put in your agent instructions
Put these in the file your agent reads on every run (CLAUDE.md, AGENTS.md, .cursor/rules, or your tool's equivalent):
## 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.
And give the agent a dedicated, read-only, expiring token with only the scopes the task needs. See Authentication and scopes.
Healthy setup checklist
- A separate token per tool and per person (
agent-cursor-jlee,report-nightly-ci), never a shared one. - Only the scopes the job needs.
records_readonly where student submissions are needed. - An expiry on every agent token, as short as the job allows.
- Tokens in environment variables or a secrets manager, never in code, prompts or chat.
-
.envin.gitignore, and a secret-scanning rule foramk_[A-Za-z0-9_-]{43}. - A monthly look at last used in Settings → Developers: revoke tokens nobody uses.
- Rotation on a schedule and whenever someone with access leaves.
- A named owner for each scheduled job, written next to 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
Goal: every night, list submissions that are not yet sealed for assignments due in the last seven days, and post the counts to your team.
Token scopes: assignments_read, records_read.
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 like the one the agent should 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 from CI on a schedule, with the token stored 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
Goal: every 15 minutes, look for connections waiting for approval and grade returns that failed in the last hour, and alert when there are any.
Token scope: lms_read only.
// 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 your own chat or paging webhook (Slack, Teams, PagerDuty). Fixing failed returns is covered in Troubleshooting LTI and Grades and roster.
The same question works 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, follow these rules:
- Read
https://www.authmarks.com/api/v1/openapi.jsonbefore writing API code. Do not invent endpoints or fields. - The API and MCP server are read-only. There is no way to create, change or delete data through them. Do not attempt it.
- Read the token only from the
AUTHMARKS_TOKENenvironment variable. Never print it, log it, echo it in shell commands, write it to files, include it in commits or ask the user to paste it into the conversation. - Never place the token in browser, mobile or extension code.
- Use
Authorization: Bearer <token>. Never put the token in a URL. - Page with
limit(1 to 200) andcursoruntilnext_cursorisnull. Do not build or modify cursors. - On
429, waitRetry-Afterseconds. Retry503with backoff. Do not retry401or403; report which scope or token is wrong. - Treat
student.nameandstudent.emailas personal data. Do not copy them into logs, fixtures, issues or summaries unless the user asked for them. - Treat ids as opaque strings and timestamps as ISO 8601 UTC.
- The API returns no scores or percentages. Do not infer or describe any about a student's writing.
- When a scope is missing, tell the user which scope to add and that an owner or admin creates tokens in Settings → Developers.
Related pages
Sources
- The llms.txt proposal — au 2026-11-26
- OpenAPI Specification 3.1.0 — au 2026-11-26
- Model Context Protocol specification (2025-06-18) — au 2026-11-26
Notes de modification
- 2026-11-26 — First published.
Vous avez repéré une erreur? Écrivez à sales@authmarks.com et nous corrigerons la page en datant la correction.