paymentsPaymentsA class representing a payment system.
Attributes:
nvm_api_key (str): The nvm api key for authentication.environment (Environment): The environment for the payment system.app_id (str, optional): The application ID.version (str, optional): The version of the payment system.headers (dict, optional): The headers for the payment system. Methods:register_credits_plan: Registers a new credits plan.register_time_plan: Registers a new time plan.register_credits_trial_plan: Registers a new credits trial plan.register_time_trial_plan: Registers a new time trial plan.register_agent: Registers a new agentregister_agent_and_plan: Registers a new agent associated to a plan in one steporder_plan: Orders the plan.get_asset_ddo: Gets the asset DDO.get_plan_balance: Gets the plan balance.get_service_token: Gets the service token.get_plan_associated_services: Gets the plan associated services.get_plan_associated_files: Gets the plan associated files.get_plan_details_url: Gets the plan details.get_service_details_url: Gets the service details.get_file_details_url: Gets the file details.get_checkout_plan: Gets the checkout plan.download_file: Downloads the file.mint_credits: Mints the credits associated to a plan and send to the receiver.burn_credits: Burns credits associated to a plan that you own.search_plans: Query for plans base on an input query options.search_agents: Query for agents base on an input query options.query: The AI Query API.__init____init__(
nvm_api_key: str,
environment: Environment,
app_id: Optional[str] = None,
version: Optional[str] = None,
headers: Optional[dict] = None
)
burn_creditsburn_credits(plan_did: str, amount: str) → BurnResultDto
Burn credits for a given Payment Plan DID.
This method is only can be called by the owner of the Payment Plan.
Args:
plan_did (str): The DID of the plan.amount (str): The amount of credits to burn.Returns:
BurnResultDto: The result of the burning operation.Raises:
HTTPError: If the API call fails.Example: response = your_instance.burn_credits(plan_did=”did:nv:e405a91e3152be1430c5d0607ebdf9236c19f34bfba0320798d81ba5f5e3e3a5”, amount=”12”) print(response)
register_agentregister_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 access the agent. Depending on the Payment Plan and the configuration of the agent, the usage of the agent 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.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/register-agent
Args:
agent_metadata (AgentMetadata): Metadata for the agent.agent_api (AgentAPIAttributes): API attributes for the agent.payment_plans (List[str]): List of payment plan IDs that give access to the agent.Returns:
Dict[str, str]: Dictionary containing the agentId of the newly created agent.Example:
from payments_py.common.types import AgentMetadata, AgentAPIAttributes
agent_metadata = AgentMetadata(
name="My AI Agent",
description="A helpful AI agent",
tags=["ai", "assistant"]
)
agent_api = AgentAPIAttributes(
endpoints=[{"POST": "https://example.com/api/v1/agents/:agentId/tasks"}]
)
payment_plans = [plan_id_1, plan_id_2]
result = payments.agents.register_agent(agent_metadata, agent_api, payment_plans)
print(f"Agent ID: {result['agentId']}")
register_agent_and_planregister_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 on Nevermined in one step.
The agent is automatically associated to the Payment Plan. Users that are subscribers of a payment plan can access the agent.
Depending on the Payment Plan and the configuration of the agent, the usage of the agent 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.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/register-agent
Args:
agent_metadata (AgentMetadata): Metadata for the agent.agent_api (AgentAPIAttributes): API attributes for the agent.plan_metadata (PlanMetadata): Metadata for the payment plan.price_config (PlanPriceConfig): Price configuration for the plan. Use helper functions from payments_py.plans to create this.credits_config (PlanCreditsConfig): Credits configuration for the plan. Use helper functions from payments_py.plans to create this.access_limit (Optional[Literal[“credits”, “time”]]): Type of access limit. Can be "credits" or "time". If not specified, it is automatically inferred based on credits_config.duration_secs.Returns:
Dict[str, str]: Dictionary containing agentId, planId, and txHash.Example:
from payments_py.common.types import AgentMetadata, AgentAPIAttributes, PlanMetadata
from payments_py.plans import get_erc20_price_config, get_fixed_credits_config
agent_metadata = AgentMetadata(name="My AI Agent", tags=["ai"])
agent_api = AgentAPIAttributes(
endpoints=[{"POST": "https://example.com/api/v1/agents/:agentId/tasks"}]
)
plan_metadata = PlanMetadata(name="Basic Plan")
price_config = get_erc20_price_config(20, ERC20_ADDRESS, builder_address)
credits_config = get_fixed_credits_config(100)
result = payments.agents.register_agent_and_plan(
agent_metadata, agent_api, plan_metadata, price_config, credits_config
)
print(f"Agent ID: {result['agentId']}, Plan ID: {result['planId']}")
Note: The access_limit parameter is optional. If not specified, it is automatically inferred based on credits_config.duration_secs:
"credits" if duration_secs == 0 (non-expirable plans)"time" if duration_secs > 0 (expirable plans)You can explicitly set it if needed:
# Explicitly set access limit to 'time'
result = payments.agents.register_agent_and_plan(
agent_metadata, agent_api, plan_metadata, price_config, credits_config,
access_limit="time"
)
register_credits_planregister_credits_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig
) → Dict[str, str]
Allows an AI Builder to register 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 to 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.
This method is oriented to AI Builders.
https://docs.nevermined.app/docs/tutorials/builders/create-plan
Args:
plan_metadata (PlanMetadata): Metadata for the payment plan.price_config (PlanPriceConfig): Price configuration for the plan. Use helper functions from payments_py.plans to create this (e.g., get_erc20_price_config, get_fiat_price_config).credits_config (PlanCreditsConfig): Credits configuration for the plan. Use helper functions from payments_py.plans to create this (e.g., get_fixed_credits_config, get_dynamic_credits_config).Returns:
Dict[str, str]: Dictionary containing the planId of the newly created plan.Raises:
PaymentsError: If the API call fails or if the credits configuration is invalid.Example:
from payments_py.common.types import PlanMetadata
from payments_py.plans import get_erc20_price_config, get_fixed_credits_config
plan_metadata = PlanMetadata(name="Basic Plan", description="100 credits plan")
price_config = get_erc20_price_config(20, ERC20_ADDRESS, builder_address)
credits_config = get_fixed_credits_config(100)
response = payments.plans.register_credits_plan(plan_metadata, price_config, credits_config)
print(f"Plan ID: {response['planId']}")
create_filecreate_file(createFileDto: CreateFileDto) → CreateAssetResultDto
It creates a new asset with file associated to it. The file asset must be associated to a Payment Plan. Users that are subscribers of a payment plan can download the files attached to it. Depending on the Payment Plan and the configuration of the file asset, the download 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 downloading the files.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/register-file-asset
Args:
createFileDto: (CreateFileDto): Options for the file creation.Returns:
CreateAssetResultDto: The result of the creation operation.Raises:
HTTPError: If the API call fails.Example: response = your_instance.create_file(plan_did=”did:nv:xyz789”, asset_type=”dataset”, name=”Sample Dataset”, description=”A sample dataset”, files=[{“name”: “file1.csv”, “url”: “https://example.com/file1.csv”}]) print(response)
create_servicecreate_service(createServiceDto: CreateServiceDto) → CreateAssetResultDto
It creates a new AI Agent or Service on Nevermined. The agent/service must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent/service. Depending on the Payment Plan and the configuration of the agent/service, 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/service.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/register-agent
Args:
createServiceDto: (CreateServiceDto): Options for the service creationReturns:
CreateAssetResultDto: The result of the creation operation.Raises:
HTTPError: If the API call fails.Example: response = your_instance.create_service(plan_did=”did:nv:abc123”, service_type=”service”, name=”My Service”, description=”A sample service”, service_charge_type=”fixed”, auth_type=”none”) print(response)
register_time_planregister_time_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig
) → Dict[str, str]
Allows an AI Builder to register a Payment Plan on Nevermined limited by duration. A Nevermined Time Plan limits the access by a specific amount of time. With them, AI Builders can specify the duration of the Payment Plan (1 month, 1 year, etc.). When the time period is over, the plan automatically expires and the user needs to renew it.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/create-plan
Args:
plan_metadata (PlanMetadata): Metadata for the payment plan.price_config (PlanPriceConfig): Price configuration for the plan. Use helper functions from payments_py.plans to create this.credits_config (PlanCreditsConfig): Credits configuration for the plan. Use helper functions from payments_py.plans to create this (e.g., get_expirable_duration_config).Returns:
Dict[str, str]: Dictionary containing the planId of the newly created plan.Raises:
PaymentsError: If the API call fails or if the credits configuration is invalid.Example:
from payments_py.common.types import PlanMetadata
from payments_py.plans import get_erc20_price_config, get_expirable_duration_config, ONE_DAY_DURATION
plan_metadata = PlanMetadata(name="Daily Plan", description="1 day access")
price_config = get_erc20_price_config(50, ERC20_ADDRESS, builder_address)
credits_config = get_expirable_duration_config(ONE_DAY_DURATION)
response = payments.plans.register_time_plan(plan_metadata, price_config, credits_config)
print(f"Plan ID: {response['planId']}")
register_credits_trial_planregister_credits_trial_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig
) → Dict[str, str]
Allows an AI Builder to register a Trial Payment Plan on Nevermined based on Credits. A Nevermined Trial Plan allows subscribers of that plan to test the Agents associated to it. A Trial plan is a plan that can only be purchased once by a user.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/create-plan
Args:
plan_metadata (PlanMetadata): Metadata for the payment plan.price_config (PlanPriceConfig): Price configuration for the plan. Use helper functions from payments_py.plans to create this (typically get_free_price_config for trial plans).credits_config (PlanCreditsConfig): Credits configuration for the plan. Use helper functions from payments_py.plans to create this (e.g., get_fixed_credits_config).Returns:
Dict[str, str]: Dictionary containing the planId of the newly created trial plan.Raises:
PaymentsError: If the API call fails or if the credits configuration is invalid.Example:
from payments_py.common.types import PlanMetadata
from payments_py.plans import get_free_price_config, get_fixed_credits_config
plan_metadata = PlanMetadata(name="Trial Plan", description="Free trial with 10 credits")
price_config = get_free_price_config()
credits_config = get_fixed_credits_config(10)
response = payments.plans.register_credits_trial_plan(plan_metadata, price_config, credits_config)
print(f"Trial Plan ID: {response['planId']}")
register_time_trial_planregister_time_trial_plan(
plan_metadata: PlanMetadata,
price_config: PlanPriceConfig,
credits_config: PlanCreditsConfig
) → Dict[str, str]
Allows an AI Builder to register a Trial Payment Plan on Nevermined limited by duration. A Nevermined Trial Plan allows subscribers of that plan to test the Agents associated to it. A Trial plan is a plan that can only be purchased once by a user.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/create-plan
Args:
plan_metadata (PlanMetadata): Metadata for the payment plan.price_config (PlanPriceConfig): Price configuration for the plan. Use helper functions from payments_py.plans to create this (typically get_free_price_config for trial plans).credits_config (PlanCreditsConfig): Credits configuration for the plan. Use helper functions from payments_py.plans to create this (e.g., get_expirable_duration_config).Returns:
Dict[str, str]: Dictionary containing the planId of the newly created trial plan.Raises:
PaymentsError: If the API call fails or if the credits configuration is invalid.Example:
from payments_py.common.types import PlanMetadata
from payments_py.plans import get_free_price_config, get_expirable_duration_config, ONE_DAY_DURATION
plan_metadata = PlanMetadata(name="Trial Plan", description="Free 1-day trial")
price_config = get_free_price_config()
credits_config = get_expirable_duration_config(ONE_DAY_DURATION)
response = payments.plans.register_time_trial_plan(plan_metadata, price_config, credits_config)
print(f"Trial Plan ID: {response['planId']}")
download_filedownload_file(
file_did: str,
destination: str,
agreement_id: Optional[str] = None
) → DownloadFileResultDto
Downloads the file.
Args:
file_did (str): The DID of the file.agreement_id (str, optional): The agreement ID.destination str: The destination of the file.Returns:
Response: The url of the file.Returns:
DownloadFileResultDto: The result of the download operation.Raises:
HTTPError: If the API call fails.Example: response = your_instance.download_file(file_did=”did:nv:7e38d39405445ab3e5435d8c1c6653a00ddc425ba629789f58fbefccaa5e5a5d”, destination=”/tmp”) print(response)
get_asset_ddoget_asset_ddo(did: str)
Get the Metadata (aka Decentralized Document or DDO) for a given asset identifier (DID).
https://docs.nevermined.io/docs/architecture/specs/Spec-DID https://docs.nevermined.io/docs/architecture/specs/Spec-METADATA
Args:
did (str): The unique identifier (aka DID) of the asset (payment plan, agent, file, etc).Returns:
Response: The response from the API call.get_checkout_planget_checkout_plan(plan_did: str)
Gets the checkout plan.
Args:
plan_did (str): The DID of the plan.Returns:
Response: The url of the checkout plan.get_file_details_urlget_file_details_url(file_did: str)
Gets the file details.
Args:
file_did (str): The DID of the file.Returns:
Response: The url of the file details.get_plan_associated_filesget_plan_associated_files(plan_did: str)
Get array of files DIDs associated with a payment plan.
Args:
plan_did (str): The DID of the plan.Returns:
Response: List of DIDs of the associated files.get_plan_associated_servicesget_plan_associated_services(plan_did: str)
Get array of services/agent DIDs associated with a payment plan.
Args:
plan_did (str): The DID of the plan.Returns:
Response: List of DIDs of the associated services.get_plan_balanceget_plan_balance(
plan_did: str,
account_address: Optional[str] = None
) → BalanceResultDto
Get the balance of an account for a Payment Plan.
Args:
plan_did (str): The DID of the plan.account_address (Optional[str]): The account address. Defaults to self.account_address if not provided.Returns:
BalanceResultDto: The response from the API call formatted as a BalanceResultDto.Raises:
HTTPError: If the API call fails.Example: response = your_instance.get_plan_balance(plan_did=”did:example:123456”, account_address=”0xABC123”) response.raise_for_status() balance = BalanceResultDto.model_validate(response.json()) print(balance)
Expected Response: { “planType”: “credits”, “isOwner”: True, “isSubscriptor”: True, “balance”: 10000000 }
get_plan_details_urlget_plan_details_url(plan_did: str)
Gets the plan details.
Args:
plan_did (str): The DID of the plan.Returns:
Response: The url of the plan details.get_service_access_configget_service_access_config(service_did: str) → ServiceTokenResultDto
get_service_details_urlget_service_details_url(service_did: str)
Gets the service details.
Args:
service_did (str): The DID of the service.Returns:
Response: The url of the service details.get_service_tokenget_service_token(service_did: str) → ServiceTokenResultDto
Get the required configuration for accessing a remote service agent. This configuration includes: - The JWT access token - The Proxy url that can be used to query the agent/service.
Args:
service_did (str): The DID of the service.Returns:
ServiceTokenResultDto: The result of the creation operation.Raises:
HTTPError: If the API call fails.Example: response = your_instance.get_service_token(service_did=”did:nv:xyz789”) print(response)
mint_creditsmint_credits(plan_did: str, amount: str, receiver: str) → MintResultDto
Mints the credits associated with a plan and sends them to the receiver.
Args:
plan_did (str): The DID of the plan.amount (str): The amount of credits to mint.receiver (str): The receiver address of the credits.Returns:
MintResultDto: The result of the minting operation.Raises:
HTTPError: If the API call fails.Example: response = your_instance.mint_credits(plan_did=”did:nv:e405a91e3152be1430c5d0607ebdf9236c19f34bfba0320798d81ba5f5e3e3a5”, amount=”12”, receiver=”0x4fe3e7d42fA83be4E8cF03451Ac3F25980a73fF6”) print(response)
order_planorder_plan(
plan_did: str,
agreementId: Optional[str] = None
) → OrderPlanResultDto
Orders a Payment Plan. The user needs to have enough balance in the token selected by the owner of the Payment Plan.
The payment is done using Crypto. Payments using Fiat can be done via the Nevermined App.
Args:
plan_did (str): The DID of the plan.agreementId (str, optional): The agreement ID.Returns:
OrderPlanResultDto: The result of the order operation, containing the agreement ID and success status.Raises:
HTTPError: If the API call fails.Example: response = your_instance.order_plan(plan_did=”did:nv:a0079b517e580d430916924f1940b764e17c31e368c509483426f8c2ac2e7116”) print(response)
search_agentssearch_agents(
text: Optional[str] = None,
page: Optional[int] = 1,
offset: Optional[int] = 10
)
Search for agents. It will search for agents matching the text provided in their metadata.
Args:
text (str): The text to search for.page (int): The page number.offset (int): The offset.Returns:
Response: The response from the API call.Example: response = your_instance.search_agents(text=”My Agent”) print(response)
search_planssearch_plans(
text: Optional[str] = None,
page: Optional[int] = 1,
offset: Optional[int] = 10
)
Search for plans. It will search for plans matching the text provided in their metadata.
Args:
text (str): The text to search for.page (int): The page number.offset (int): The offset.Returns:
Response: The response from the API call.Example: response = your_instance.search_plans(text=”Basic”) print(response)
This file was automatically generated via lazydocs.