Register an agent and associate it with existing payment plans:
import osfrom payments_py.common.types import AgentMetadata, AgentAPIAttributes, AuthType# Define agent metadataagent_metadata = AgentMetadata( name="My AI Assistant", description="An intelligent assistant that helps with various tasks", tags=["ai", "assistant", "productivity"], author="Your Company")# Define API configuration. All AgentAPIAttributes fields are optional —# most builders only need to set authentication. See# "AgentAPIAttributes Fields" below for opt-in Additional Security.agent_api = AgentAPIAttributes( auth_type=AuthType.BEARER, token=os.environ["AGENT_BEARER_TOKEN"],)# List of plan IDs that grant access to this agentpayment_plans = [plan_id_1, plan_id_2]# Register the agentresult = payments.agents.register_agent( agent_metadata=agent_metadata, agent_api=agent_api, payment_plans=payment_plans)print(f"Agent ID: {result['agentId']}")
Setting endpoints opts the agent into a platform-enforced allowlist. When set, only requests matching one of the registered URLs are accepted during x402 verification; non-matching requests are rejected. When omitted, the platform performs no route-level allowlist check — your Payments library middleware (PaymentMiddleware, @requires_payment) remains the sole gate.
The :agentId and :taskId placeholders will be replaced with actual values during request validation.
Migration note: existing agents that registered before April 2026 still have these fields populated and continue to enforce the allowlist as before. No migration is needed.
update_agent_metadata is also where builders typically opt in to Additional Security by adding an endpoints allowlist or agent_definition_url to an existing agent:
import osfrom payments_py.common.types import ( AgentMetadata, AgentAPIAttributes, AuthType, Endpoint,)updated_metadata = AgentMetadata( name="Updated Agent Name", description="Updated description with new features", tags=["ai", "updated", "v2"])# Adding `endpoints` activates the platform-enforced allowlist for this# agent. To return to allow-all, omit it on the next update.updated_api = AgentAPIAttributes( auth_type=AuthType.BEARER, token=os.environ["AGENT_BEARER_TOKEN"], endpoints=[Endpoint(verb="POST", url="https://new-api.com/v2/tasks")], agent_definition_url="https://new-api.com/v2/openapi.json",)result = payments.agents.update_agent_metadata( agent_id="your-agent-id", agent_metadata=updated_metadata, agent_api=updated_api)print(f"Update successful: {result}")