Payments Class Reference¶
The main entry point for the Nevermined Payments Python SDK.
Payments¶
Payments
¶
Bases: BasePaymentsAPI
Main class that interacts with the Nevermined payments API.
Use Payments.get_instance for server-side usage.
The library provides methods to manage AI Agents, Plans & process AI Agent Requests.
Each of these functionalities is encapsulated in its own API class:
- plans: Manages AI Plans, including registration and ordering and retrieving plan details.
- agents: Handles AI Agents, including registration of AI Agents and access token generation.
- requests: Manages requests received by AI Agents, including validation and tracking.
- facilitator: Handles X402 permission verification and settlement for AI Agents acting as facilitators.
Initialize the Payments class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The initialization options
TYPE:
|
is_browser_instance
|
Whether this is a browser instance (default False)
TYPE:
|
Source code in payments_py/payments.py
get_instance
classmethod
¶
Get an instance of the Payments class for server-side usage.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Payments
|
An instance of Payments |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If nvm_api_key is missing |
Source code in payments_py/payments.py
get_browser_instance
classmethod
¶
Get an instance of the Payments class for browser usage.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Payments
|
An instance of Payments |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If return_url is missing |
Source code in payments_py/payments.py
Plans API¶
PlansAPI
¶
Bases: BasePaymentsAPI
The PlansAPI class provides methods to register and interact with payment plans on Nevermined.
Initialize the PlansAPI class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
Source code in payments_py/api/plans_api.py
get_instance
classmethod
¶
Get a singleton instance of the PlansAPI class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PlansAPI
|
The instance of the PlansAPI class |
Source code in payments_py/api/plans_api.py
register_plan
¶
register_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig,
nonce: Optional[int] = None,
access_limit: Optional[
Literal["credits", "time"]
] = None,
) -> Dict[str, str]
Allows an AI Builder to create a Payment Plan on Nevermined in a flexible manner. A Nevermined Credits Plan limits access based on plan usage. With them, AI Builders control the number of requests that can be made to an agent or service. Every time a user accesses any resource associated with the Payment Plan, the usage consumes from a capped amount of credits. When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.
| PARAMETER | DESCRIPTION |
|---|---|
plan_metadata
|
Plan metadata
TYPE:
|
price_config
|
Plan price configuration
TYPE:
|
credits_config
|
Plan credits configuration
TYPE:
|
nonce
|
Optional nonce for the transaction |
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
The unique identifier of the plan (Plan ID) of the newly created plan |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If registration fails |
Source code in payments_py/api/plans_api.py
register_credits_plan
¶
register_credits_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig,
) -> Dict[str, str]
Allows an AI Builder to create a Payment Plan on Nevermined based on Credits. A Nevermined Credits Plan limits the access by the access/usage of the Plan. With them, AI Builders control the number of requests that can be made to an agent or service. Every time a user accesses any resource associated with the Payment Plan, the usage consumes from a capped amount of credits. When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.
| PARAMETER | DESCRIPTION |
|---|---|
plan_metadata
|
Plan metadata
TYPE:
|
price_config
|
Plan price configuration
TYPE:
|
credits_config
|
Plan credits configuration
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
The unique identifier of the plan (Plan ID) of the newly created plan |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the credits configuration is invalid |
Source code in payments_py/api/plans_api.py
register_time_plan
¶
register_time_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig,
) -> Dict[str, str]
Allows an AI Builder to create a Payment Plan on Nevermined limited by duration. A Nevermined Credits Plan limits the access by the access/usage of the Plan. With them, AI Builders control the number of requests that can be made to an agent or service. Every time a user accesses any resource associated with the Payment Plan, the usage consumes from a capped amount of credits. When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.
| PARAMETER | DESCRIPTION |
|---|---|
plan_metadata
|
Plan metadata
TYPE:
|
price_config
|
Plan price configuration
TYPE:
|
credits_config
|
Plan credits configuration
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
The unique identifier of the plan (Plan ID) of the newly created plan |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the credits configuration is invalid |
Source code in payments_py/api/plans_api.py
register_credits_trial_plan
¶
register_credits_trial_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig,
) -> Dict[str, str]
Allows an AI Builder to create a Trial Payment Plan on Nevermined based on Credits. A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it. A Trial plan is a plan that only can be purchased once by a user.
| PARAMETER | DESCRIPTION |
|---|---|
plan_metadata
|
Plan metadata
TYPE:
|
price_config
|
Plan price configuration
TYPE:
|
credits_config
|
Plan credits configuration
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
The unique identifier of the plan (Plan ID) of the newly created plan |
Source code in payments_py/api/plans_api.py
register_time_trial_plan
¶
register_time_trial_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig,
) -> Dict[str, str]
Allows an AI Builder to create a Trial Payment Plan on Nevermined limited by duration. A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it. A Trial plan is a plan that only can be purchased once by a user.
| PARAMETER | DESCRIPTION |
|---|---|
plan_metadata
|
Plan metadata
TYPE:
|
price_config
|
Plan price configuration
TYPE:
|
credits_config
|
Plan credits configuration
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
The unique identifier of the plan (Plan ID) of the newly created plan |
Source code in payments_py/api/plans_api.py
get_plan
¶
Get the metadata for a given Plan identifier.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The plan's metadata |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the plan is not found |
Source code in payments_py/api/plans_api.py
get_plan_balance
¶
Get the balance of a plan for a specific account.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
account_address
|
The account address to check balance for (defaults to current user) |
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The plan balance information with properly typed fields (balance as int) |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to get plan balance |
Source code in payments_py/api/plans_api.py
order_plan
¶
Order a plan by its ID.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The ID of the plan to order
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, bool]
|
The result of the order operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to order the plan |
Source code in payments_py/api/plans_api.py
mint_plan_credits
¶
Mint credits for a plan.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
credits_amount
|
The amount of credits to mint
TYPE:
|
credits_receiver
|
The address that will receive the credits
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the mint operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to mint credits |
Source code in payments_py/api/plans_api.py
mint_plan_expirable
¶
mint_plan_expirable(
plan_id: str,
credits_amount: int,
credits_receiver: str,
credits_duration: int = 0,
) -> Dict[str, Any]
Mint expirable credits for a plan.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
credits_amount
|
The amount of credits to mint
TYPE:
|
credits_receiver
|
The address that will receive the credits
TYPE:
|
credits_duration
|
The duration of the credits in seconds
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the mint operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to mint credits |
Source code in payments_py/api/plans_api.py
burn_credits
¶
Burn credits from a plan.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
credits_amount
|
The amount of credits to burn
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the burn operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to burn credits |
Source code in payments_py/api/plans_api.py
get_agents_associated_to_plan
¶
get_agents_associated_to_plan(
plan_id: str,
pagination: Optional[PaginationOptions] = None,
) -> Dict[str, Any]
Gets the list of agents that can be accessed with a plan.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
pagination
|
Optional pagination options to control the number of results returned
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The list of all different agents giving access to the plan |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the plan is not found |
Source code in payments_py/api/plans_api.py
get_fiat_price_config
staticmethod
¶
get_crypto_price_config
staticmethod
¶
get_crypto_price_config(
amount: int,
receiver: str,
token_address: str = "0x0000000000000000000000000000000000000000",
) -> PlanPriceConfig
Build a crypto (native/ERC20) price configuration.
Source code in payments_py/api/plans_api.py
get_erc20_price_config
staticmethod
¶
Build an ERC20 price configuration.
get_free_price_config
staticmethod
¶
get_native_token_price_config
staticmethod
¶
Build a native token price configuration.
get_expirable_duration_config
staticmethod
¶
Build an expirable duration credits configuration.
get_non_expirable_duration_config
staticmethod
¶
Build a non-expirable duration credits configuration.
get_fixed_credits_config
staticmethod
¶
Build a fixed credits configuration.
Source code in payments_py/api/plans_api.py
get_dynamic_credits_config
staticmethod
¶
get_dynamic_credits_config(
credits_granted: int,
min_credits_per_request: int = 1,
max_credits_per_request: int = 1,
) -> PlanCreditsConfig
Build a dynamic credits configuration.
Source code in payments_py/api/plans_api.py
set_redemption_type
staticmethod
¶
set_redemption_type(
credits_config: PlanCreditsConfig,
redemption_type: PlanRedemptionType,
) -> PlanCreditsConfig
Set redemption type on a credits configuration (returns new object).
Source code in payments_py/api/plans_api.py
set_proof_required
staticmethod
¶
set_proof_required(
credits_config: PlanCreditsConfig,
proof_required: bool = True,
) -> PlanCreditsConfig
Set proof requirement on a credits configuration (returns new object).
Source code in payments_py/api/plans_api.py
get_pay_as_you_go_price_config
¶
get_pay_as_you_go_price_config(
amount: int,
receiver: str,
token_address: str = plan_utils.ZeroAddress,
) -> PlanPriceConfig
Build a pay-as-you-go price configuration using contract address from API.
This method fetches the PayAsYouGoTemplate contract address from the API info endpoint and uses it to create the price configuration. The address is cached for subsequent calls.
| PARAMETER | DESCRIPTION |
|---|---|
amount
|
The amount per usage in the smallest unit of the token
TYPE:
|
receiver
|
The address that will receive the payment
TYPE:
|
token_address
|
The address of the token to use for payment (defaults to native token)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PlanPriceConfig
|
A PlanPriceConfig object configured for pay-as-you-go payments |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to fetch contract address from API |
ValueError
|
If the receiver address is not a valid Ethereum address |
Source code in payments_py/api/plans_api.py
get_pay_as_you_go_credits_config
staticmethod
¶
order_fiat_plan
¶
Order a fiat plan using Stripe checkout.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The Stripe checkout result |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to order the fiat plan |
Source code in payments_py/api/plans_api.py
redeem_credits
¶
redeem_credits(
agent_request_id: str,
plan_id: str,
redeem_from: str,
credits_amount_to_redeem: str,
) -> Dict[str, Any]
Redeem credits from a plan for a specific agent request.
| PARAMETER | DESCRIPTION |
|---|---|
agent_request_id
|
The unique identifier of the agent request
TYPE:
|
plan_id
|
The unique identifier of the plan
TYPE:
|
redeem_from
|
The address to redeem credits from
TYPE:
|
credits_amount_to_redeem
|
The amount of credits to redeem
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the redeem operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to redeem credits |
Source code in payments_py/api/plans_api.py
Agents API¶
AgentsAPI
¶
Bases: BasePaymentsAPI
The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.
Source code in payments_py/api/base_payments.py
get_instance
classmethod
¶
Get a singleton instance of the AgentsAPI class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AgentsAPI
|
The instance of the AgentsAPI class |
Source code in payments_py/api/agents_api.py
register_agent
¶
register_agent(
agent_metadata: AgentMetadata,
agent_api: AgentAPIAttributes,
payment_plans: List[str],
) -> Dict[str, str]
Registers a new AI Agent on Nevermined. The agent must be associated to one or multiple Payment Plans. Users that are subscribers of a payment plan can query the agent. Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits. When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.
| PARAMETER | DESCRIPTION |
|---|---|
agent_metadata
|
Agent metadata
TYPE:
|
agent_api
|
Agent API attributes
TYPE:
|
payment_plans
|
The list of payment plans giving access to the agent |
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
The unique identifier of the newly created agent (Agent Id) |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If registration fails |
Source code in payments_py/api/agents_api.py
register_agent_and_plan
¶
register_agent_and_plan(
agent_metadata: AgentMetadata,
agent_api: AgentAPIAttributes,
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig,
access_limit: Optional[
Literal["credits", "time"]
] = None,
) -> Dict[str, str]
Registers a new AI Agent and a Payment Plan associated to this new agent. Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits. When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.
| PARAMETER | DESCRIPTION |
|---|---|
agent_metadata
|
Agent metadata
TYPE:
|
agent_api
|
Agent API attributes
TYPE:
|
plan_metadata
|
Plan metadata
TYPE:
|
price_config
|
Plan price configuration
TYPE:
|
credits_config
|
Plan credits configuration
TYPE:
|
access_limit
|
Optional access limit for the plan |
Returns: Dictionary containing agentId, planId, and txHash
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If registration fails |
Source code in payments_py/api/agents_api.py
get_agent
¶
Gets the metadata for a given Agent identifier.
| PARAMETER | DESCRIPTION |
|---|---|
agent_id
|
The unique identifier of the agent
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The agent's metadata |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the agent is not found |
Source code in payments_py/api/agents_api.py
get_agent_plans
¶
Gets the list of plans that can be ordered to get access to an agent.
| PARAMETER | DESCRIPTION |
|---|---|
agent_id
|
The unique identifier of the agent
TYPE:
|
pagination
|
Optional pagination options to control the number of results returned
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The list of all different plans giving access to the agent |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the agent is not found |
Source code in payments_py/api/agents_api.py
add_plan_to_agent
¶
Add a plan to an agent.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
agent_id
|
The unique identifier of the agent
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to add plan to agent |
Source code in payments_py/api/agents_api.py
remove_plan_from_agent
¶
Remove a plan from an agent.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the plan
TYPE:
|
agent_id
|
The unique identifier of the agent
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to remove plan from agent |
Source code in payments_py/api/agents_api.py
update_agent_metadata
¶
update_agent_metadata(
agent_id: str,
agent_metadata: AgentMetadata,
agent_api: AgentAPIAttributes,
) -> Dict[str, Any]
Updates the metadata and API attributes of an existing AI Agent.
| PARAMETER | DESCRIPTION |
|---|---|
agent_id
|
The unique identifier of the agent
TYPE:
|
agent_metadata
|
The new metadata attributes for the agent
TYPE:
|
agent_api
|
The new API attributes for the agent
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
The result of the update operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the agent is not found or if the update fails |
Source code in payments_py/api/agents_api.py
Facilitator API (x402)¶
FacilitatorAPI
¶
Bases: BasePaymentsAPI
The FacilitatorAPI class provides methods to verify and settle AI agent permissions. It enables AI agents to act as facilitators, managing credit verification and settlement for subscribers using X402 access tokens.
Source code in payments_py/api/base_payments.py
get_instance
classmethod
¶
Get a singleton instance of the FacilitatorAPI class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FacilitatorAPI
|
The instance of the FacilitatorAPI class |
Source code in payments_py/x402/facilitator_api.py
verify_permissions
¶
verify_permissions(
payment_required: X402PaymentRequired,
x402_access_token: str,
max_amount: Optional[str] = None,
) -> VerifyResponse
Verify if a subscriber has permission to use credits from a payment plan. This method simulates the credit usage without actually burning credits, checking if the subscriber has sufficient balance and permissions.
The planId and subscriberAddress are extracted from the x402AccessToken.
| PARAMETER | DESCRIPTION |
|---|---|
payment_required
|
x402 PaymentRequired from 402 response (required, for validation)
TYPE:
|
x402_access_token
|
The X402 access token (contains planId, subscriberAddress, agentId)
TYPE:
|
max_amount
|
The maximum number of credits to verify (as string, optional) |
| RETURNS | DESCRIPTION |
|---|---|
VerifyResponse
|
VerifyResponse with is_valid boolean and optional error details |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If verification fails |
Source code in payments_py/x402/facilitator_api.py
settle_permissions
¶
settle_permissions(
payment_required: X402PaymentRequired,
x402_access_token: str,
max_amount: Optional[str] = None,
agent_request_id: Optional[str] = None,
) -> SettleResponse
Settle (burn) credits from a subscriber's payment plan. This method executes the actual credit consumption, burning the specified number of credits from the subscriber's balance. If the subscriber doesn't have enough credits, it will attempt to order more before settling.
The planId and subscriberAddress are extracted from the x402AccessToken.
| PARAMETER | DESCRIPTION |
|---|---|
payment_required
|
x402 PaymentRequired from 402 response (required, for validation)
TYPE:
|
x402_access_token
|
The X402 access token (contains planId, subscriberAddress, agentId)
TYPE:
|
max_amount
|
The number of credits to burn (as string, optional) |
agent_request_id
|
Agent request ID for observability tracking (optional) |
| RETURNS | DESCRIPTION |
|---|---|
SettleResponse
|
SettleResponse with success boolean and transaction details |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If settlement fails |
Source code in payments_py/x402/facilitator_api.py
X402 Token API¶
X402TokenAPI
¶
Bases: BasePaymentsAPI
X402 Token API for generating access tokens.
Handles X402 access token generation for subscribers to authorize payment operations with AI agents.
Source code in payments_py/api/base_payments.py
get_instance
classmethod
¶
Get a singleton instance of the X402TokenAPI class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the API
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
X402TokenAPI
|
The instance of the X402TokenAPI class |
Source code in payments_py/x402/token.py
get_x402_access_token
¶
get_x402_access_token(
plan_id: str,
agent_id: Optional[str] = None,
redemption_limit: Optional[int] = None,
order_limit: Optional[str] = None,
expiration: Optional[str] = None,
) -> Dict[str, Any]
Create a permission and get an X402 access token for the given plan.
This token allows the agent to verify and settle permissions on behalf of the subscriber. The token contains cryptographically signed session keys that delegate specific permissions (order, burn) to the agent.
| PARAMETER | DESCRIPTION |
|---|---|
plan_id
|
The unique identifier of the payment plan
TYPE:
|
agent_id
|
The unique identifier of the AI agent (optional) |
redemption_limit
|
Maximum number of interactions/redemptions allowed (optional) |
order_limit
|
Maximum spend limit in token units (wei) for ordering (optional) |
expiration
|
Expiration date in ISO 8601 format, e.g. "2025-02-01T10:00:00Z" (optional) |
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
A dictionary containing: - accessToken: The X402 access token string |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If the request fails |
Example
from payments_py import Payments, PaymentOptions
from payments_py.x402 import X402TokenAPI
payments = Payments.get_instance(
PaymentOptions(nvm_api_key="nvm:subscriber-key", environment="sandbox")
)
token_api = X402TokenAPI.get_instance(payments.options)
result = token_api.get_x402_access_token(plan_id="123", agent_id="456")
token = result["accessToken"]
Source code in payments_py/x402/token.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
Requests API¶
AgentRequestsAPI
¶
Bases: BasePaymentsAPI
The AgentRequestsAPI class provides methods to manage the requests received by AI Agents integrated with Nevermined.
Note: For request validation and credit settlement, use the x402 API instead: - payments.facilitator.verify_permissions() - to verify token and permissions - payments.facilitator.settle_permissions() - to burn credits
Source code in payments_py/api/base_payments.py
get_instance
classmethod
¶
Get a singleton instance of the AgentRequestsAPI class.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
The options to initialize the payments class
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AgentRequestsAPI
|
The instance of the AgentRequestsAPI class |
Source code in payments_py/api/requests_api.py
track_agent_sub_task
¶
Tracks an agent sub task.
This method is used by agent owners to track agent sub tasks for agent tasks. It records information about credit redemption, categorization tags, and processing descriptions.
| PARAMETER | DESCRIPTION |
|---|---|
track_agent_sub_task
|
The agent sub task data to track
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
A promise that resolves to the result of the operation |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to track the agent sub task |
Source code in payments_py/api/requests_api.py
start_simulation_request
¶
start_simulation_request(
price_per_credit: float = 0.01,
batch: bool = False,
agent_name: str = None,
plan_name: str = None,
) -> StartAgentRequest
This method simulates an agent request.
| PARAMETER | DESCRIPTION |
|---|---|
price_per_credit
|
The price per credit in USD
TYPE:
|
batch
|
Whether the request is a batch request
TYPE:
|
agent_name
|
The name of the agent
TYPE:
|
plan_name
|
The name of the plan
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StartAgentRequest
|
The information about the simulation of the request |
Source code in payments_py/api/requests_api.py
finish_simulation_request
¶
finish_simulation_request(
agent_request_id: str,
margin_percent: float = 0.2,
batch: bool = False,
) -> Dict[str, Any]
Simulates the redemption of credits for an agent request.
| PARAMETER | DESCRIPTION |
|---|---|
agent_request_id
|
The unique identifier of the agent request.
TYPE:
|
margin_percent
|
The margin percentage to apply. Defaults to 0.2.
TYPE:
|
batch
|
Whether the request is a batch request. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
A dictionary containing the result of the simulation, including the credits to redeem and the success status. |
| RAISES | DESCRIPTION |
|---|---|
PaymentsError
|
If unable to finish the simulation request. |