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

Getting started

Define one governed action, invoke it from your agent with no credential, approve it, and read its receipt.

Your agent needs to do real things: refund an order, open an issue, send an email from a user’s own account. The usual way is to give the agent’s process an API key. Then a prompt injection, a bad tool call or a retry loop can use that key for anything it allows, as often as it likes, and afterwards you have a log line at best.

Anlyon moves the call out of your agent’s process. You define the call once as an action. The agent names the action and passes input. Anlyon adds the credential at dispatch, checks the limit, waits for an approval when a policy asks for one, sends the request, and returns a receipt with a grade. The agent never holds the credential.

This guide takes you from an empty file to an agent that issues a Stripe refund it cannot send on its own. It takes about ten minutes.

How it works

Without Anlyon   agent  ->  an API key in your process  ->  Stripe
With Anlyon      agent  ->  "refund-order" + input  ->  Anlyon (credential, limit, approval)  ->  Stripe
  • Credentials the model never sees. The action names a vaulted secret. The vault never returns a value, and a secret can only go to the hosts you bind it to.
  • A limit on what calls change. A limit caps money, emails or any unit you count, per day, per month or in total, shared by every agent and key in the environment, or per end user.
  • A person in front of risky calls. A policy holds a call for your team, or for the user the call acts for, before anything is sent.
  • A receipt for every call. The grade says what is known: confirmed, acknowledged, unknown, failed, refused, denied or pending.

The same calls work with your company’s own accounts and with your users’ own accounts. To act for your users, read Act for your users after this page.

Before you start

  • An Anlyon account. Sign in at console.anlyon.com.
  • A Stripe secret or restricted key, and the id of the Stripe account it belongs to (acct_...).
  • Node.js 18 or later, or Python 3.10 or later. Or just curl.

Step 1: Create two API keys

You create two keys because the key that decides where a credential may go should not be the key a model drives.

Open API keys

In the console, open Settings → API keys and pick one environment. A key belongs to exactly one environment, so a staging key cannot reach production data.

Create an operator key

Give it secrets:write, secrets:read and actions:write. It stores the Stripe key and defines the action. secrets:read lets it name a secret in an action, never read its value. Both secrets:* scopes are privileged: no key gets them unless you choose them. Keep this key in your deploy tooling, not in your agent.

Create an agent key

In the same environment, create a second key with actions:invoke, actions:read and approvals:read. All three are in the default set. This key can call actions. It cannot change them, read a credential or decide an approval.

Each key is shown once. It looks like anlyon_live_ followed by 32 characters. Put them in ANLYON_OPERATOR_KEY and ANLYON_AGENT_KEY, and your Stripe key in STRIPE_KEY.

Step 2: Define the action and invoke it

The operator half runs once: it stores the Stripe key and defines refund-order with Anlyon’s Stripe refund adapter. The agent half is one call with the agent key.

requiresApproval: true holds every call for a person, so nothing reaches Stripe until someone approves it. mode is live or test and must match the key: a sk_live_ or rk_live_ key needs live, a sk_test_ or rk_test_ key needs test. A mismatch is refused before anything is sent.

TypeScript

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

// Operator: run once, from your deploy tooling. The only place the Stripe key appears.
const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });

await ops.secrets.put('STRIPE_KEY', { value: process.env.STRIPE_KEY!, allowedHosts: ['api.stripe.com'] });

await ops.actions.create({
  name: 'refund-order',
  description: 'Refund part or all of a Stripe payment.',
  adapter: {
    type: 'stripe.refund',
    config: { account: 'acct_1Nxyz', mode: 'test', currency: 'usd' },
    credentialSecret: 'STRIPE_KEY',
  },
  requiresApproval: true,
});

// Agent: no URL, no header, no Stripe key.
const anlyon = new Client({ apiKey: process.env.ANLYON_AGENT_KEY! });

const { data } = await anlyon.actions.invoke('refund-order', {
  paymentIntent: 'pi_3P9xQk',
  amount: 12000, // 120.00 USD, in minor units
  currency: 'usd',
});

console.log(data!.pendingApproval ? `Parked for a human: ${data!.approvalId}` : `Receipt grade: ${data!.grade}`);

Python

pip install anlyon
import os
from anlyon import Client

# Operator: run this once. The only place your credential appears.
ops = Client(api_key=os.environ["ANLYON_OPERATOR_KEY"])

ops.secrets.put("STRIPE_KEY", value=os.environ["STRIPE_KEY"], allowed_hosts=["api.stripe.com"])

ops.actions.create(
    name="refund-order",
    description="Refund part or all of a Stripe payment.",
    adapter={
        "type": "stripe.refund",
        "config": {"account": "acct_1Nxyz", "mode": "test", "currency": "usd"},
        "credentialSecret": "STRIPE_KEY",
    },
    requires_approval=True,
)

# Agent: no URL, no header, no key.
anlyon = Client(api_key=os.environ["ANLYON_AGENT_KEY"])

result = anlyon.actions.invoke(
    "refund-order", {"paymentIntent": "pi_3P9xQk", "amount": 12000, "currency": "usd"}
)

if result.data["pendingApproval"]:
    print("Parked for a human:", result.data["approvalId"])
else:
    print("Receipt grade:", result.data["grade"])

cURL

Once the action exists, the agent half is one request. Notice what is not in it: no URL, no header, no Stripe key.

curl --fail-with-body -X POST https://api.anlyon.com/api/v2/actions/refund-order/invoke \
  -H "Authorization: Bearer $ANLYON_AGENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "paymentIntent": "pi_3P9xQk",
      "amount": 12000,
      "currency": "usd"
    }
  }'

The operator half over HTTP is two requests:

curl -X PUT https://api.anlyon.com/api/v2/secrets/STRIPE_KEY \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d "{ \"value\": \"$STRIPE_KEY\", \"allowedHosts\": [\"api.stripe.com\"] }"

curl -X POST https://api.anlyon.com/api/v2/actions \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "refund-order",
    "description": "Refund part or all of a Stripe payment.",
    "adapter": {
      "type": "stripe.refund",
      "config": { "account": "acct_1Nxyz", "mode": "test", "currency": "usd" },
      "credentialSecret": "STRIPE_KEY"
    },
    "requiresApproval": true
  }'

What comes back

The call parks instead of running. The response is HTTP 202:

{
  "success": true,
  "data": {
    "id": "inv_01JABCDEF",
    "actionName": "refund-order",
    "status": "pending_approval",
    "pendingApproval": true,
    "approvalId": "apr_01JABCDEF",
    "effectId": "eff_01JABCDEF",
    "grade": "pending"
  }
}

The block shows the fields this guide uses. The full invocation is in the API reference.

Step 3: Approve it

Open Controls → Approvals in the console. The approval shows the exact refund: the Stripe account, the payment intent, the amount and its impact. Approve it, and Anlyon checks the account, sends the refund with the vaulted key and records the outcome. Nothing else can send it: the agent key has no Stripe key and no way to decide.

To decide from code, use a third key with approvals:decide. That scope is privileged, and the key that requested an approval can never decide it.

const reviewer = new Client({ apiKey: process.env.ANLYON_REVIEWER_KEY! });

const { data: decided } = await reviewer.approvals.approve('apr_01JABCDEF', { note: 'Checked the order.' });
console.log(decided!.invocation?.status, decided!.invocation?.effectId);
curl -X POST https://api.anlyon.com/api/v2/approvals/apr_01JABCDEF/approve \
  -H "Authorization: Bearer $ANLYON_REVIEWER_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "note": "Checked the order." }'
reviewer = Client(api_key=os.environ["ANLYON_REVIEWER_KEY"])

decided = reviewer.approvals.approve("apr_01JABCDEF", note="Checked the order.").data
print(decided["invocation"]["status"], decided["invocation"]["effectId"])

Step 4: Read the receipt

The effect is the receipt: the outcome, the grade, and the evidence behind the grade.

const { data: effect } = await anlyon.actions.effect('eff_01JABCDEF');
console.log(effect!.outcome, effect!.grade, effect!.providerReference);
curl https://api.anlyon.com/api/v2/actions/effects/eff_01JABCDEF \
  -H "Authorization: Bearer $ANLYON_AGENT_KEY"
effect = anlyon.actions.effect("eff_01JABCDEF").data
print(effect["outcome"], effect["grade"], effect["providerReference"])
{ "stage": "settled", "outcome": "succeeded", "grade": "confirmed", "verification": "provider", "providerReference": "re_3Pq..." }

confirmed means Stripe’s own record of the refund matched. unknown means the request may have reached Stripe and Anlyon could not confirm it: Anlyon does not send it again, and it reads Stripe back to settle it. See Receipts and grades and Agent payment retries.

Every call is also listed with its status, version and decision:

curl https://api.anlyon.com/api/v2/actions/invocations?action=refund-order \
  -H "Authorization: Bearer $ANLYON_AGENT_KEY"

Step 5: Act for one of your users

When the agent works for a signed-in user of your product, your server names that user. The model never does, and tool schemas carry no user field.

const user = anlyon.forUser(session.user.id);

const { data } = await user.actions.invoke('refund-order', {
  paymentIntent: 'pi_3P9xQk',
  amount: 12000,
  currency: 'usd',
});
curl -X POST https://api.anlyon.com/api/v2/actions/refund-order/invoke \
  -H "Authorization: Bearer $ANLYON_AGENT_KEY" \
  -H "Anlyon-End-User: user_123" \
  -H "Content-Type: application/json" \
  -d '{ "input": { "paymentIntent": "pi_3P9xQk", "amount": 12000, "currency": "usd" } }'
user = anlyon.for_user(session_user_id)

result = user.actions.invoke(
    "refund-order", {"paymentIntent": "pi_3P9xQk", "amount": 12000, "currency": "usd"}
)

The call is recorded against that user. A limit created with scope: "end_user" counts each user on their own, and a policy with decidedBy: "end_user" sends the approval to that user, in your app, instead of your team. An action that sends {{connection:<integration>}} uses that user’s own connected account, so the agent acts in their Gmail or HubSpot, not yours. Act for your users builds this end to end.

Handle errors

What you see Why What to do
401 The key is wrong, revoked or from another deployment. Check the key. Each key is shown once; create a new one if it is lost.
403 The key lacks a scope, for example the agent key calling actions.create. Use the operator key for setup, or add the scope the message names.
400 on invoke: the action “refuses a credential that is not a Stripe test key” The Stripe key does not match the action’s mode. Use live with a live key and test with a test key.
400 on invoke The input does not match the action’s input schema, for example a paymentIntent that is not pi_.... Fix the input. Nothing was recorded or sent.
400 END_USER_REQUIRED The key was created with Require an end user and the call named none. Call through forUser(id) or send Anlyon-End-User.
409 END_USER_NOT_CONNECTED The user has not connected the integration the action uses. Send them to connectUrl from the error, then call again.
grade: "refused" with HTTP 200 A limit had no room, or a check failed before dispatch. Nothing was sent. Read error. See When the limit is hit.
402 PAYMENT_REQUIRED or 429 QUOTA_EXCEEDED The workspace has no plan, or is past its action allowance. See Billing and pricing.
429 RATE_LIMIT_EXCEEDED Too many requests this minute, or this hour. Wait for Retry-After and retry. Read X-RateLimit-Remaining.

Authentication

Every request carries an API key as a bearer token. The key resolves its environment, so there is nothing else to pass.

Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The SDKs send it for you. See Authentication and API keys.

Rate limits

Requests are counted per workspace in one-minute windows. The allowance depends on your plan: see pricing. Each response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Past the limit the API answers 429.

Next steps

Support

Was this page helpful?