Try the demo

Blog

Make your app ready for agents

Four steps to accept AI agents in an existing API. List your routes, write the sentences, wrap the app and use what it verified.

Agents can already reach your app, by scraping it or by borrowing a customer's login. Accepting them on your terms takes four steps. The example uses Python; SDKs also exist for JavaScript, Go, Java, C#, PHP, Ruby and Rust.

1. List what an agent may call

One line per route. Say what it does and how serious it is.

routes = [
    route("GET", "/plans", level=0, summary="Plans and prices"),
    route("GET", "/account", "account:read", level=1),
    route("POST", "/plans/{plan}/subscribe", "billing:subscribe", cls="write-hard",
          level=1, resource="plan:{plan}", amount_field="/monthly_total"),
]

Routes you do not list keep your own authentication. Read Choosing a level before this step.

2. Write the sentences

templates = {
    "account:read": "See your account and usage",
    "billing:subscribe": "Subscribe to {scope} for {amount.max} {amount.currency} per month",
}

Only enforced values can fill the blanks. If a sentence is hard to write, the action is probably two actions.

3. Wrap the app

aby = AllowedBy(origin="https://beacon.example", node="https://node.example.org",
                org={"legal_name": "Beacon Labs SAS", "country": "FR"},
                routes=routes, templates=templates)
app = aby.wsgi(app)

The wrapper answers the 401, checks every listed route before your code runs, and publishes your rules at /.well-known/allowedby and as OpenAPI 3.1. An agent given only your address can find its way.

4. Use what it verified

Your handler receives a context: the agent, its operator, the level, and an identifier for the person that is stable in your app and different elsewhere. Store it as you would a user id.

Before production

If you run more than one instance, share the replay store, for example with Redis. Serve over https. Choose which nodes you trust. The packages are not on public registries yet and the specifications are a draft, so today this is for a pilot. Talk to us if you want one.

Next postWho allowed this?