Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

Quickstart: your agent acts for one user, with their approval

Go from nothing to a governed action your agent calls for one of your users: the user's own GitHub account, their approval in your app, a per-user limit and a receipt graded confirmed.

In this quickstart your agent opens a GitHub issue for one of your users, in that user’s own GitHub account. The call waits until the user approves it, counts against that user’s daily limit, and comes back with a receipt graded confirmed. The agent never holds the user’s token.

That is the loop every Anlyon call follows, and it removes the work you would otherwise build yourself: per-user OAuth and token storage, a per-user limit counter, an approval backend, and a record of what ran.

Want your coding agent to do the setup? Set up from your agent is the recommended start: one command, anlyon init, signs you in, writes a key to .env, installs the SDK, connects the MCP server and runs a governed call. This page walks through the pieces by hand.

You play two parts: the developer, and Alice, the user your agent acts for. Alice connects her GitHub with a personal access token so you can finish without a browser redirect. Connect users with a connect link shows the sign-in flow your production app uses instead.

What you need

  • An Anlyon workspace at console.anlyon.com.
  • A GitHub account. The GitHub CLI is optional and makes step 2 shorter.
  • Node.js 20 or later, Python 3.10 or later, or curl.

Actions run on a plan. If your workspace has no plan yet, every action call answers 402 PAYMENT_REQUIRED. As a workspace admin, open Settings → Plan & billing and start the trial. See Billing and anlyon.com/pricing.

How the pieces fit

Who Holds Does
Your deploy script An operator key Declares the action, the approval rule and the limit. Once.
Your server An app key that requires an end user Names the user on every call, stores or confirms their connection, relays their approval.
Your agent Nothing but tools Calls open-issue with a title and a body. It has no user field and no token.
Anlyon Alice’s GitHub token Checks the limit, waits for Alice’s yes, adds her token, calls GitHub, reads the issue back.

Step 1: Create two API keys

Open Settings → API Keys in the console. Both keys go in the same environment. Each key is shown once: copy it when it appears.

Create the operator key

Name it quickstart operator. Choose individual scopes: actions:write, secrets:read, policies:write and impact-limits:write. It declares the action and the rules around it. secrets:read is what lets an action reference a credential, here Alice’s GitHub connection. Your agent never runs with this key.

Create the app key

Name it quickstart app. Start from the Standard preset, which holds actions:invoke and actions:read, then add the privileged end-users:write and end-users:approvals. Turn on Require an end user. Every action call made with this key must now name a user, and the key can never fall back to your workspace’s own accounts.

export ANLYON_OPERATOR_KEY=anlyon_live_...
export ANLYON_APP_KEY=anlyon_live_...

Two keys are the point. The key that decides what an action may do and who approves it should not be the key your running app holds.

Step 2: Prepare a repository and Alice’s token

Alice needs a GitHub repository where she can open issues. Use one you own, or create one:

export GH_OWNER=your-github-login
export GH_REPO=anlyon-quickstart
gh repo create "$GH_OWNER/$GH_REPO" --private --add-readme

Now create Alice’s token. In GitHub, open Settings → Developer settings → Personal access tokens → Fine-grained tokens and generate a token for this one repository with Issues: Read and write. GitHub adds Metadata: Read itself. Keep it out of your shell history:

read -rs QUICKSTART_GITHUB_TOKEN
export QUICKSTART_GITHUB_TOKEN

Step 3: Install the SDK

Skip this step if you use curl.

npm install @anlyonhq/sdk
pnpm add @anlyonhq/sdk
pip install anlyon

Step 4: Declare the action, the approval and the limit

Run this once, with the operator key. It declares three things:

  • The action open-issue. It opens one issue in your repository with the calling user’s own GitHub token, {{connection:github}}. It counts one issues per call, and it reads the issue back afterwards to check the title.
  • An approval policy that sends every open-issue call to the user it acts for: decidedBy: "end_user". Your team’s inbox never sees it.
  • A limit of 5 issues a day, counted for each user on their own: scope: "end_user".
import { Client } from '@anlyonhq/sdk';

const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });
const repo = `${process.env.GH_OWNER}/${process.env.GH_REPO}`;

await ops.actions.create({
  name: 'open-issue',
  description: 'Open one issue in the quickstart repository.',
  method: 'POST',
  urlTemplate: `https://api.github.com/repos/${repo}/issues`,
  headers: {
    // The token of the user the call is made for. Never yours, never the agent's.
    Authorization: 'Bearer {{connection:github}}',
    Accept: 'application/vnd.github+json',
    'X-GitHub-Api-Version': '2022-11-28',
    'User-Agent': 'anlyon-quickstart',
    'Content-Type': 'application/json',
  },
  bodyTemplate: { title: '{{input.title}}', body: '{{input.body}}' },
  inputSchema: {
    type: 'object',
    required: ['title', 'body'],
    additionalProperties: false,
    properties: {
      title: { type: 'string', minLength: 1, maxLength: 256 },
      body: { type: 'string', minLength: 1, maxLength: 20000 },
    },
  },
  impact: { dimension: 'issues', amount: '1', bound: 'exact' },
  verify: {
    url: `https://api.github.com/repos/${repo}/issues/{{response.number}}`,
    status: 200,
    match: [{ path: 'title', equals: '{{input.title}}' }],
  },
});

await ops.approvalPolicies.create({
  name: 'The user approves each issue',
  matchKind: 'action',
  matchActionName: 'open-issue',
  effect: 'require_approval',
  decidedBy: 'end_user',
});

await ops.impactLimits.create({
  name: 'Issues per user per day',
  dimension: 'issues',
  period: 'day',
  amount: 5,
  actionName: 'open-issue',
  scope: 'end_user',
});

console.log('Action, approval policy and limit declared.');
import os
from anlyon import Client

ops = Client(api_key=os.environ["ANLYON_OPERATOR_KEY"])
repo = f"{os.environ['GH_OWNER']}/{os.environ['GH_REPO']}"

ops.actions.create(
    name="open-issue",
    description="Open one issue in the quickstart repository.",
    method="POST",
    url_template=f"https://api.github.com/repos/{repo}/issues",
    headers={
        # The token of the user the call is made for. Never yours, never the agent's.
        "Authorization": "Bearer {{connection:github}}",
        "Accept": "application/vnd.github+json",
        "X-GitHub-Api-Version": "2022-11-28",
        "User-Agent": "anlyon-quickstart",
        "Content-Type": "application/json",
    },
    body_template={"title": "{{input.title}}", "body": "{{input.body}}"},
    input_schema={
        "type": "object",
        "required": ["title", "body"],
        "additionalProperties": False,
        "properties": {
            "title": {"type": "string", "minLength": 1, "maxLength": 256},
            "body": {"type": "string", "minLength": 1, "maxLength": 20000},
        },
    },
    impact={"dimension": "issues", "amount": "1", "bound": "exact"},
    verify={
        "url": f"https://api.github.com/repos/{repo}/issues/{{{{response.number}}}}",
        "status": 200,
        "match": [{"path": "title", "equals": "{{input.title}}"}],
    },
)

ops.approval_policies.create(
    name="The user approves each issue",
    match_kind="action",
    match_action_name="open-issue",
    effect="require_approval",
    decided_by="end_user",
)

ops.impact_limits.create(
    name="Issues per user per day",
    dimension="issues",
    period="day",
    amount=5,
    action_name="open-issue",
    scope="end_user",
)

ops.close()
print("Action, approval policy and limit declared.")
curl --fail-with-body -X POST https://api.anlyon.com/api/v2/actions \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<JSON
{
  "name": "open-issue",
  "description": "Open one issue in the quickstart repository.",
  "method": "POST",
  "urlTemplate": "https://api.github.com/repos/$GH_OWNER/$GH_REPO/issues",
  "headers": {
    "Authorization": "Bearer {{connection:github}}",
    "Accept": "application/vnd.github+json",
    "X-GitHub-Api-Version": "2022-11-28",
    "User-Agent": "anlyon-quickstart",
    "Content-Type": "application/json"
  },
  "bodyTemplate": { "title": "{{input.title}}", "body": "{{input.body}}" },
  "inputSchema": {
    "type": "object",
    "required": ["title", "body"],
    "additionalProperties": false,
    "properties": {
      "title": { "type": "string", "minLength": 1, "maxLength": 256 },
      "body": { "type": "string", "minLength": 1, "maxLength": 20000 }
    }
  },
  "impact": { "dimension": "issues", "amount": "1", "bound": "exact" },
  "verify": {
    "url": "https://api.github.com/repos/$GH_OWNER/$GH_REPO/issues/{{response.number}}",
    "status": 200,
    "match": [{ "path": "title", "equals": "{{input.title}}" }]
  }
}
JSON

curl --fail-with-body -X POST https://api.anlyon.com/api/v2/approval-policies \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "The user approves each issue", "matchKind": "action", "matchActionName": "open-issue", "effect": "require_approval", "decidedBy": "end_user" }'

curl --fail-with-body -X POST https://api.anlyon.com/api/v2/impact-limits \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Issues per user per day", "dimension": "issues", "period": "day", "amount": 5, "actionName": "open-issue", "scope": "end_user" }'

Save the TypeScript as setup.mts and run npx tsx setup.mts, or save the Python as setup.py and run python setup.py.

The action’s host is fixed at api.github.com, and the catalogue only lets a GitHub token travel to that host, in a header. No input can send Alice’s token anywhere else.

Step 5: Connect Alice’s GitHub

Your server stores Alice’s token as her GitHub connection. Anlyon checks it with GitHub (GET /user), encrypts it and never returns it. From now on, a call made for Alice uses her account.

import { Client } from '@anlyonhq/sdk';

const anlyon = new Client({ apiKey: process.env.ANLYON_APP_KEY! });

// 'alice' is your own id for the user, for example session.user.id.
const { data: connection } = await anlyon.endUsers.setConnection('alice', 'github', {
  token: process.env.QUICKSTART_GITHUB_TOKEN!,
});

console.log('GitHub for alice:', connection!.status);
import os
from anlyon import Client

anlyon = Client(api_key=os.environ["ANLYON_APP_KEY"])

# 'alice' is your own id for the user, for example the id in your session.
connection = anlyon.end_users.set_connection(
    "alice", "github", token=os.environ["QUICKSTART_GITHUB_TOKEN"]
).data

print("GitHub for alice:", connection["status"])
anlyon.close()
curl --fail-with-body -X PUT https://api.anlyon.com/api/v2/end-users/alice/connections/github \
  -H "Authorization: Bearer $ANLYON_APP_KEY" \
  -H "Anlyon-End-User: alice" \
  -H "Content-Type: application/json" \
  -d @- <<JSON
{ "token": "$QUICKSTART_GITHUB_TOKEN" }
JSON

Save it as connect.mts or connect.py and run it. It prints GitHub for alice: active.

Step 6: Let the agent call the action for Alice

This is all the agent side holds: a client bound to Alice by your server, an action name and the input. There is no token, no repository URL and no user field the model could change.

import { Client, EndUserNotConnectedError } from '@anlyonhq/sdk';

const anlyon = new Client({ apiKey: process.env.ANLYON_APP_KEY! });

// Your server names the user. The model never does.
const alice = anlyon.forUser('alice');

try {
  const { data: call } = await alice.actions.invoke('open-issue', {
    title: 'Hello from my agent',
    body: 'Opened by an agent, approved by its user.',
  });
  console.log('Status:', call!.status);
  console.log('Approval:', call!.approvalId);
} catch (error) {
  // Alice has not connected GitHub: show her a Connect button with this link.
  if (error instanceof EndUserNotConnectedError) console.log('Connect first:', error.connectUrl);
  else throw error;
}
import os
from anlyon import Client, EndUserNotConnectedError

anlyon = Client(api_key=os.environ["ANLYON_APP_KEY"])

# Your server names the user. The model never does.
alice = anlyon.for_user("alice")

try:
    call = alice.actions.invoke(
        "open-issue",
        {"title": "Hello from my agent", "body": "Opened by an agent, approved by its user."},
    ).data
    print("Status:", call["status"])
    print("Approval:", call["approvalId"])
except EndUserNotConnectedError as error:
    # Alice has not connected GitHub: show her a Connect button with this link.
    print("Connect first:", error.connect_url)
finally:
    anlyon.close()
curl --fail-with-body -X POST https://api.anlyon.com/api/v2/actions/open-issue/invoke \
  -H "Authorization: Bearer $ANLYON_APP_KEY" \
  -H "Anlyon-End-User: alice" \
  -H "Content-Type: application/json" \
  -d '{ "input": { "title": "Hello from my agent", "body": "Opened by an agent, approved by its user." } }'

Save it as agent.mts or agent.py and run it. Nothing reaches GitHub yet. The call is parked for Alice:

{
  "id": "inv_01JABCDEF",
  "actionName": "open-issue",
  "status": "pending_approval",
  "pendingApproval": true,
  "approvalId": "apr_01JABCDEF",
  "endUserId": "alice"
}

In a real agent, the call is a tool. With the Vercel AI SDK, anlyonTools({ client: anlyon.forUser(userId) }) turns each action into a tool whose schema has no user field, and a missing connection comes back as a connect_required result instead of an error. See Act for your users.

Step 7: Alice approves, and the issue opens

Your app shows Alice her pending approval: the exact title and body the agent wants to send. When she clicks Approve, your server relays her decision. Approving runs the parked call, with the request exactly as she saw it. Then read the receipt.

import { Client } from '@anlyonhq/sdk';

const anlyon = new Client({ apiKey: process.env.ANLYON_APP_KEY! });

// What Alice sees in your app: her own pending approvals, and nobody else's.
const { data: pending } = await anlyon.endUsers.approvals.list('alice', { status: 'pending' });
const approval = pending![0]!;
console.log('Waiting on alice:', approval.id);

// Alice clicked Approve.
const { data: decision } = await anlyon.endUsers.approvals.decide('alice', approval.id, { decision: 'approve' });
const effectId = decision!.invocation!.effectId!;

const { data: receipt } = await anlyon.forUser('alice').actions.effect(effectId);
console.log('Outcome:', receipt!.outcome);
console.log('Grade:', receipt!.grade);
import os
from anlyon import Client

anlyon = Client(api_key=os.environ["ANLYON_APP_KEY"])

# What Alice sees in your app: her own pending approvals, and nobody else's.
pending = anlyon.end_users.approvals.list("alice", status="pending").data
approval = pending[0]
print("Waiting on alice:", approval["id"])

# Alice clicked Approve.
decision = anlyon.end_users.approvals.decide("alice", approval["id"], decision="approve").data
effect_id = decision["invocation"]["effectId"]

receipt = anlyon.for_user("alice").actions.effect(effect_id).data
print("Outcome:", receipt["outcome"])
print("Grade:", receipt["grade"])
anlyon.close()
curl --fail-with-body "https://api.anlyon.com/api/v2/end-users/alice/approvals?status=pending" \
  -H "Authorization: Bearer $ANLYON_APP_KEY" \
  -H "Anlyon-End-User: alice"

curl --fail-with-body -X POST "https://api.anlyon.com/api/v2/end-users/alice/approvals/$APPROVAL_ID/decide" \
  -H "Authorization: Bearer $ANLYON_APP_KEY" \
  -H "Anlyon-End-User: alice" \
  -H "Content-Type: application/json" \
  -d '{ "decision": "approve" }'

Save it as approve.mts or approve.py and run it. With curl, set APPROVAL_ID to the approvalId from step 6 first. The decision answers with the approval and the invocation that ran:

{
  "approval": { "id": "apr_01JABCDEF", "status": "approved" },
  "invocation": { "id": "inv_01JABCDEF", "status": "succeeded", "effectId": "eff_01JABCDEF", "endUserId": "alice" }
}

Read the receipt by its effectId:

curl --fail-with-body "https://api.anlyon.com/api/v2/actions/effects/$EFFECT_ID" \
  -H "Authorization: Bearer $ANLYON_APP_KEY" \
  -H "Anlyon-End-User: alice"

These are the fields that carry the receipt:

{
  "stage": "settled",
  "outcome": "succeeded",
  "grade": "confirmed",
  "verification": "provider",
  "endUserId": "alice",
  "impact": [{ "dimension": "issues", "amount": 1, "bound": "exact" }]
}

confirmed means Anlyon read the issue back from GitHub after opening it, and its title matched. Open the repository’s Issues tab: the issue is there, opened by Alice’s account. A receipt is a database record with provider evidence. See Receipts and grades.

What you just built

  • The agent acted in Alice’s account and never held her token. Anlyon added it at the moment of the call, and only to api.github.com.
  • Nothing ran without Alice’s yes. The approval carried the exact request, and that exact request is what ran.
  • Alice has her own limit. Her sixth issue today is refused before it reaches GitHub. Other users keep their own 5.
  • You hold a receipt filed under Alice, graded by a read-back of GitHub’s own record.

Try the edges

Try this What comes back What to do
Run step 6 with forUser('bob'), a user with no connection 409 END_USER_NOT_CONNECTED. The SDK throws EndUserNotConnectedError. Its connectUrl is a link that works once, for 10 minutes, or null when the environment has no default redirect URL. Show the user a Connect button with that link, or make one with createConnectLink. Nothing was sent.
Call the action with the app key and no Anlyon-End-User header 400 END_USER_REQUIRED, because the key requires an end user. Always build the client with forUser() on your server.
Deny in step 7: { decision: 'deny' } The approval is denied and the invocation denied. Nothing reaches GitHub. Tell the agent the user said no. Do not retry.
Run steps 6 and 7 six times in one day for Alice The limit is reserved after the approval, just before dispatch. The sixth approval succeeds, and its invocation comes back status: "failed" with impact_limit_exceeded in error. Its receipt is graded refused. Nothing reaches GitHub. Wait for the next day, or raise the limit with an operator key. See When the limit is hit.
Leave an approval undecided It expires after 24 hours by default, and the call never runs. Change the window in Workspace defaults. See When approval expires or changes.
Decide another user’s approval: decide('bob', aliceApprovalId, …) 404. A user can only see and decide their own approvals. Always take the user id from your session.
Revoke the token on GitHub GitHub refuses calls made with it. Anlyon checks each user’s key once a day, marks a refused key for a reconnect, and from then on a call answers 409 END_USER_RECONNECT_REQUIRED (EndUserReconnectRequiredError in the SDK) before anything is sent. Ask the user to connect again with a connect link.
The key lacks a scope 403 AUTHORIZATION_ERROR, naming the missing scope. Create a key with that scope. Scopes are fixed when a key is created.

In production your users sign in to GitHub themselves. Your server makes a connect link, the user signs in on GitHub, and your callback confirms the connection for the user in your session. Set a default redirect URL first, in Integrations → Connect settings.

import { parseConnectRedirect } from '@anlyonhq/sdk';

// 1. A Connect GitHub button sends the user here. The link works once, for 10 minutes.
const { data: link } = await anlyon.endUsers.createConnectLink({
  endUserId: session.user.id,
  integration: 'github',
  redirectUrl: 'https://app.example.com/connections/callback',
});
// Redirect the browser to link!.url

// 2. Your callback route. Confirm with the user from your own session, never one read from the URL.
const result = parseConnectRedirect(request.url);
if (result?.status === 'pending_confirmation' && result.flowId) {
  await anlyon.endUsers.confirmConnection(session.user.id, result.flowId);
}

The confirmation stops a forwarded link from attaching someone else’s account to your user: a flow started for another user answers 403 END_USER_MISMATCH and connects nothing. Act for your users builds the whole app, and Components gives you prebuilt connect buttons and an approval inbox for React.

Clean up

Archive the action, delete the policy and the limit, and erase Alice. Erasing removes her connection, her limit counters and her pending approvals, and replaces her id in the kept records with a one-way hash.

curl -X DELETE https://api.anlyon.com/api/v2/end-users/alice \
  -H "Authorization: Bearer $ANLYON_APP_KEY" \
  -H "Anlyon-End-User: alice"
curl -X DELETE https://api.anlyon.com/api/v2/actions/open-issue \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY"

Delete the policy and archive the limit in the console under Controls, then revoke the token on GitHub. Deleting an action archives it and keeps its name, so creating open-issue again in the same environment answers 409 CONFLICT. To run the quickstart again, give the action a new name.

Next steps

Was this page helpful?