Package
Install one adapter.
Python Core and a compatible Flask version are installed automatically.
pip install apirelio-flaskFlask extension
Register Apirelio during application setup.
import os
from flask import Flask
from apirelio_flask import install_apirelio
app = Flask(__name__)
install_apirelio(
app,
api_key=os.environ.get("APIRELIO_API_KEY", ""),
endpoint=os.environ.get("APIRELIO_ENDPOINT", "https://apirelio.com"),
service="billing-api",
environment="production",
include_routes=("/api/**",),
exclude_routes=("/api/health", "/api/internal/**"),
)B2B context
Resolve stable identities.
Authenticate the request before Flask runs after_request, then resolve the current account and consuming API client from g or another request-local source.
from flask import g
install_apirelio(
app,
# ...connection options...
resolve_customer=lambda request: {
"id": str(g.account.id),
"name": g.account.name,
"plan": g.account.plan,
} if getattr(g, "account", None) else None,
resolve_application=lambda request: {
"id": str(g.api_client.id),
"name": g.api_client.name,
} if getattr(g, "api_client", None) else None,
)Safe enrichment
Add bounded operational context.
Only scalar keys included in metadata_keys are retained by Python Core. Use stable error codes rather than exception messages.
from apirelio_flask import get_request_context
@app.post("/api/invoices")
def create_invoice():
context = get_request_context()
if context:
context.add_metadata({"region": "eu-central"})
context.set_error_code("PAYMENT_REQUIRED")
return {"accepted": True}, 202Lifecycle
Resolved, asynchronous and fail-safe.
The integration records the final status, duration and matched Flask URL rule. Events enter a bounded background queue; resolver and delivery failures never replace the original response or exception.
Request and response bodies, query strings, credentials, cookies and client IP addresses are never included.