> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentonboard.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Flask

> Authenticate AI agents in Flask APIs using @require_agent_token and verify RS256 tokens locally against public JWKS keys.

`agentonboard-sdk[flask]` provides `@require_agent_token` for Flask routes. It reads `Authorization: Bearer <token>`, verifies the `RS256` signature against public JWKS keys, resolves your user record, and returns `(jsonify({...}), status)` on failure.

## Copy-paste agent prompt

```text theme={null}
Integrate AgentOnboard into this Flask repository.

1. Inspect the codebase and install `agentonboard-sdk[flask]`.
2. Read these docs before editing:
   - https://docs.agentonboard.xyz/flask.md
   - https://docs.agentonboard.xyz/verify.md
   - https://docs.agentonboard.xyz/accounts.md
   - https://docs.agentonboard.xyz/auth-md.md
3. Ask me three questions before writing code:
   - Which database or user model should the `resolver` query?
   - Should unknown emails return `403 ACCOUNT_REQUIRED` (reject) or create an account on `POST /api/signup`?
   - What is the production Domain hostname (e.g. `notes.com` or `api.notes.com`)?
4. Implement the integration following these invariants:
   - Use `@require_agent_token` from `agentonboard.frameworks.flask`.
   - Hardcode `audience` to the normalized production Domain.
   - Normalize emails consistently in lowercase (`identity.email.strip().lower()`) before querying your database.
   - Serve the discovery file at both `/auth.md` and `/.well-known/auth.md` with matching `## Audience` and `403` instructions.
5. Verify against localhost by minting a test token with `POST https://agentonboard.xyz/api/v1/token/exchange` and testing `403 ACCOUNT_REQUIRED`, `200 OK`, and `401 INVALID_SIGNATURE`.
```

***

## 1. Install the Python SDK

> [tab] pip
>
> ```bash theme={null}
> pip install "agentonboard-sdk[flask]"
> ```

> [tab] uv
>
> ```bash theme={null}
> uv add "agentonboard-sdk[flask]"
> ```

> [tab] poetry
>
> ```bash theme={null}
> poetry add agentonboard-sdk --extras flask
> ```

***

## 2. Guard your Flask routes

`@require_agent_token` sets `flask.g.agent_user` and `flask.g.agent_identity`, and injects `agent_user` or `agent_identity` into your route function when declared in its parameters:

```python title="app.py" theme={null}
from flask import Flask, jsonify
from agentonboard import AgentIdentity
from agentonboard.frameworks.flask import require_agent_token

app = Flask(__name__)

# Simulated user store
accounts = {"ada@example.com": "user_123"}

def resolve_user(identity: AgentIdentity) -> str | None:
    return accounts.get(identity.email.strip().lower())

@app.post("/api/notes")
@require_agent_token(audience="notes.com", resolver=resolve_user)
def create_note(agent_user: str):
    # agent_user (and flask.g.agent_user) holds your resolved user ID
    return jsonify({"success": True, "created_by": agent_user})
```

***

## 3. Enabling explicit agent signup (`POST /api/signup`)

Keep `@require_agent_token(..., auto_create=False)` on all regular routes and add a dedicated `POST /api/signup` route using `create_agent_account`:

```python title="app.py" theme={null}
from flask import jsonify, request
from agentonboard import AgentIdentity, create_agent_account
from agentonboard.codes import status_from_code

def create_user(identity: AgentIdentity) -> str:
    email = identity.email.strip().lower()
    user_id = f"user_{len(accounts) + 1}"
    accounts[email] = user_id
    return user_id

@app.post("/api/signup")
def signup_agent():
    outcome = create_agent_account(
        token=request.headers.get("Authorization", ""),
        audience="notes.com",
        resolver=resolve_user,
        creator=create_user,
    )

    if not outcome.ok:
        return (
            jsonify({"code": outcome.code, "error": outcome.error}),
            status_from_code(outcome.code),
        )

    return jsonify({"user": outcome.user, "created": outcome.created}), 201
```

***

## 4. Test with curl

Mint a 5-minute test token using [`POST /api/v1/token/exchange`](https://docs.agentonboard.xyz/api/token-exchange) and call your Flask endpoint:

```bash theme={null}
# Mint a 5-minute test token
TOKEN=$(curl -s -X POST https://agentonboard.xyz/api/v1/token/exchange \
  -H "Authorization: Bearer aon_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"audience":"notes.com"}' \
  | jq -r '.token')

# Call your Flask endpoint
curl -i -X POST http://localhost:5000/api/notes \
  -H "Authorization: Bearer $TOKEN"
```

***

> [card] [FastAPI](https://docs.agentonboard.xyz/fastapi.md)
>
> Guard FastAPI routes with AgentBearerAuth.

> [card] [Testing & Production](https://docs.agentonboard.xyz/testing-and-production.md)
>
> Run all six curl checks and review JWKS caching.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.