Skip to main content

Lelu · Python SDK

Python client for Lelu — the confidence-aware authorization engine for autonomous AI agents.

Author: Abenezer Getachew
Maintainer: Abenezer Getachew

Installation

pip install lelu-agent-auth-sdk

Requires Python 3.11+.

Quick start

Run the local engine once — it self-generates its key and policy in ~/.lelu, no account needed:

npx -y lelu-mcp start

Then create one shared instance and import it everywhere. With no arguments, lelu() discovers that engine automatically:

import asyncio
from lelu import lelu

auth = lelu(actor="invoice_bot")   # zero-config: finds the local engine

async def main():
    result = await auth.authorize(tool="invoice:create")
    if result.decision == "allow":
        ...  # proceed
    elif result.decision == "human_review":
        # Queued for a human. Don't just wait for "approved" and then act —
        # an approval is bound to the request it approved, so pass the same
        # request back and let the engine confirm nothing changed.
        outcome = await auth.wait_and_redeem(result, tool="invoice:create")
        if not outcome.allowed:
            raise PermissionError(outcome.reason)
        ...  # proceed
    else:
        raise PermissionError(result.reason)

asyncio.run(main())

The instance exposes the full client as auth.api (tokens, review queue, audit, policies): await auth.api.mint_token(...).

Option 2: Self-hosted or cloud engine

Point the same factory at any engine with explicit config — or set LELU_BASE_URL / LELU_API_KEY and keep calling lelu() with no arguments:

auth = lelu(
    base_url="https://your-engine.example.com",
    api_key=os.environ["LELU_API_KEY"],
    actor="invoice_bot",
)

LeluClient(...) from earlier versions keeps working unchanged — auth.api is that same client.

Confidence signals

Engines in their default configuration reject bare self-reported confidence numbers (CONFIDENCE_ALLOW_UNVERIFIED=false). Build a ConfidenceSignal from your LLM provider's response with LeluClient.signal_from (.openai, .bedrock, .local; .anthropic always returns None) so the engine extracts the score from the token/entropy data directly:

from lelu import AgentContext, LeluClient, lelu

auth = lelu(actor="invoice_bot")

resp = await openai_client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages,
    logprobs=True,
)
signal = LeluClient.signal_from.openai(resp)  # None if logprobs are absent

result = await auth.authorize(
    tool="refund:process",
    context=AgentContext(confidence_signal=signal) if signal else None,
)

When signal is None (for example, Anthropic models that expose no token log-probs), omit confidence_signal so the engine's MissingSignalMode decides rather than inventing a default score.

Mounting the approval handler (optional)

auth.handler is an ASGI app that exposes the engine's authorize and review queue to your own frontend. It acts with your engine credentials, so it only serves a caller your app has authenticated: without authenticate= it answers 403 for everything except GET /ok.

import os
from lelu import HandlerCaller, lelu

async def authenticate(scope):
    user = scope.get("user")                      # your session / JWT check
    if user is None:
        return None                               # -> 401
    return HandlerCaller(reviewer=user.name if user.is_reviewer else None)

auth = lelu(
    authenticate=authenticate,
    reviewer_key=os.environ["LELU_REVIEWER_KEY"],  # one of the engine's LELU_REVIEWER_KEYS
)
app.mount("/api/lelu", auth.handler)               # FastAPI / Starlette
  • Any authenticated caller may POST /authorize.
  • Only a caller with a reviewer name may list the queue, approve or deny. That name is recorded as the resolver; a resolved_by in the request body is ignored.
  • When the engine sets LELU_REVIEWER_KEYS, approvals need reviewer_key. To approve or deny from your own code, pass it directly: await client.approve_review(review_id, "alice", reviewer_key=...).

API

Method Description
authorize(req) Confidence-aware agent authorization (allow / deny / human_review / compute)
agent_authorize(req) Deprecated — backward-compatible wrapper around authorize()
wait_and_redeem(review, req) After human_review: wait for the reviewer, then redeem the approval against the same request (pass the decision or its review_id, not request_id)
mint_token(req) Mint a JIT-scoped JWT
revoke_token(token_id) Revoke a token immediately
is_healthy() Health-check the engine

License

MIT

Metadata

Release files for lelu-agent-auth-sdk 0.4.44

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lelu-agent-auth-sdk 0.4.44
File Size Uploaded Provenance Actions
lelu_agent_auth_sdk-0.4.44.tar.gz 81.5 kB Without provenance Details for lelu_agent_auth_sdk-0.4.44.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lelu-agent-auth-sdk 0.4.44
File Interpreter ABI Platform Actions
lelu_agent_auth_sdk-0.4.44-py3-none-any.whl Python 3 none any Details for lelu_agent_auth_sdk-0.4.44-py3-none-any.whl

Total release size: 138.7 kB

Release files / lelu_agent_auth_sdk-0.4.44.tar.gz

Download URL lelu_agent_auth_sdk-0.4.44.tar.gz
Size 81.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4a19540c6add69a58c3af4df45532bb2a8ad6f434e1a5fb20fb05d0a82106e59
BLAKE2b-256 checksum
How to use checksums
ac53887cc827ee65cb3ea8f7c7dff0849184b5abd807d88c575593438b3b809d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / lelu_agent_auth_sdk-0.4.44-py3-none-any.whl

Download URL lelu_agent_auth_sdk-0.4.44-py3-none-any.whl
Size 57.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca518906490a6788425aca21cc2c44e6d7f2de8c15c88030942dcd5755292718
BLAKE2b-256 checksum
How to use checksums
92dab65b6eb1d8134d9362486e17db957367f5bcb6db7234a62ca2887909fb27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Security for lelu-agent-auth-sdk 0.4.44

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page