Skip to content

Retrieving "Maximum Charged Results" via API #341

Closed

Description

@muhammetakkurtt

Hello,

I have a question regarding PPR actors.

In the Apify Console, users can manually set the "Maximum charged results" value in the Run Options section. The maximum allowed value is automatically calculated based on the actor’s pricing and the user’s remaining monthly limit, ensuring they cannot enter a value exceeding their available balance.

However, I couldn't find a way to retrieve this value using the Apify Python Client API. For example:

run = client.run(run_id)
run_info = run.get()

# Retrieve run options
options = run_info.get('options', {})
max_charged_results = options.get('maxItems')

If the user manually sets a "Maximum charged results" value, maxItems returns the specified number. However, if it is set to "No limit", the value returned is None.

I also tried checking the following environment variable but got the same result:

max_items = os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS')

As a workaround, I found a manual solution by calculating the maximum number of results a user can retrieve based on their balance. This involves checking the user’s monthly limit, their remaining balance, and the actor’s per-result pricing, then performing the calculation externally. While this works, I was wondering if there is a more direct way to obtain this value.

Is there an API method that provides this pre-calculated "Maximum charged results" value, or is manual calculation the only option?

I would appreciate any guidance on this.

Thank you!

Activity

  1. added
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Jan 29, 2025
  2. janbuchar commented on Feb 3, 2025

    @janbuchar
    Contributor

    Hi! According to the documentation (https://docs.apify.com/platform/actors/development/programming-interface/environment-variables#system-environment-variables), os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS') should give you the user limit on paid dataset items. The run options probably returns the same number.

    If the run has no configured limit, the variable will be empty, which is the correct behavior - you're supposed to let the Actor run and the platform will stop it in case the user runs out of credit.

  3. muhammetakkurtt commented on Feb 3, 2025

    @muhammetakkurtt
    Author

    Hi! According to the documentation (https://docs.apify.com/platform/actors/development/programming-interface/environment-variables#system-environment-variables), os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS') should give you the user limit on paid dataset items. The run options probably returns the same number.

    If the run has no configured limit, the variable will be empty, which is the correct behavior - you're supposed to let the Actor run and the platform will stop it in case the user runs out of credit.

    Is Apify SDK for Python required for the platform to stop the actor? This doesn't seem to work with the Client. Since I'm running it in DEVELOPMENT mode, I'm not being charged, and it allows exceeding the limit. I'm not entirely sure if this happens automatically.

    There should be a way to determine the maximum result a user can enter in the run options based on their remaining credit. In the console interface, this value is displayed in real-time, ensuring that users do not exceed their available limit.

  4. janbuchar commented on Feb 3, 2025

    @janbuchar
    Contributor

    Hi! According to the documentation (https://docs.apify.com/platform/actors/development/programming-interface/environment-variables#system-environment-variables), os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS') should give you the user limit on paid dataset items. The run options probably returns the same number.
    If the run has no configured limit, the variable will be empty, which is the correct behavior - you're supposed to let the Actor run and the platform will stop it in case the user runs out of credit.

    Is Apify SDK for Python required for the platform to stop the actor? This doesn't seem to work with the Client. Since I'm running it in DEVELOPMENT mode, I'm not being charged, and it allows exceeding the limit. I'm not entirely sure if this happens automatically.

    This is handled entirely by the platform, the SDK should not be a requirement. If you're not being charged, then you cannot exceed the limit - I'm not sure how else it should behave.

    There should be a way to determine the maximum result a user can enter in the run options based on their remaining credit. In the console interface, this value is displayed in real-time, ensuring that users do not exceed their available limit.

    Problem is, there cannot really be a way - this number can change while your Actor is running - imagine that the user runs multiple paid Actors at once - then their "limit" is highly unpredictable.

  5. muhammetakkurtt commented on Feb 3, 2025

    @muhammetakkurtt
    Author

    Hi! According to the documentation (https://docs.apify.com/platform/actors/development/programming-interface/environment-variables#system-environment-variables), os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS') should give you the user limit on paid dataset items. The run options probably returns the same number.
    If the run has no configured limit, the variable will be empty, which is the correct behavior - you're supposed to let the Actor run and the platform will stop it in case the user runs out of credit.

    Is Apify SDK for Python required for the platform to stop the actor? This doesn't seem to work with the Client. Since I'm running it in DEVELOPMENT mode, I'm not being charged, and it allows exceeding the limit. I'm not entirely sure if this happens automatically.

    This is handled entirely by the platform, the SDK should not be a requirement. If you're not being charged, then you cannot exceed the limit - I'm not sure how else it should behave.

    There should be a way to determine the maximum result a user can enter in the run options based on their remaining credit. In the console interface, this value is displayed in real-time, ensuring that users do not exceed their available limit.

    Problem is, there cannot really be a way - this number can change while your Actor is running - imagine that the user runs multiple paid Actors at once - then their "limit" is highly unpredictable.

    Thank you for your help!

  6. locked and limited conversation to collaborators on Feb 4, 2025
  7. converted this issue into a discussion #346 on Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions