Specifying Actor Memory in Apify API Calls

Troubleshooting: Configuring Actor Memory for Apify Run-Sync Endpoints

When orchestrating Apify Actors via API, resource allocation—specifically memory—is a critical factor for both execution stability and cost efficiency. A frequent challenge arises when using the run-sync-get-dataset-items endpoint: the Actor appears to ignore memory settings defined in the request body.

The Common Misconception

In standard asynchronous "Run Actor" requests, developers typically pass runOptions within the JSON payload to specify memoryMbytes. However, the synchronous run-sync-get-dataset-items endpoint follows a different protocol.

Technical Note: Attempting to include "memoryMbytes": 2048 inside the POST body will result in the Actor reverting to its default memory allocation, as this endpoint does not parse runtime options from the request payload.

The Solution: Query Parameter Injection

The correct architectural approach for this specific endpoint is to pass the memory requirement as a URL Query Parameter. By appending &memory=VALUE directly to the endpoint, you force the scheduler to allocate the specified resources before the synchronous execution begins.

Correct Syntax: Use &memory=256 (where 256 is the value in MB) at the end of your API URL string.

Implementation Example

Below is the standardized format for constructing your API request URL to ensure proper resource provisioning:

javascript
// Constructing the Synchronous Run URL with 256MB RAM
const APIFY_API_URL = `https://api.apify.com/v2/acts/novi~fast-tiktok-api/run-sync-get-dataset-items?token=YOUR_API_TOKEN&memory=256`; 

Key Performance Takeaways

  • Endpoint Specificity: Always verify if your chosen Apify endpoint supports body parameters or requires URL query parameters for runtime configuration.
  • Cost Optimization: Only allocate the memory necessary for the task. Synchronous runs are billed based on the memory/time product ($GBh).
  • Timeout Prevention: Insufficient memory is a leading cause of Task timed out or Actor internal error in synchronous operations.
Keywords: Apify API, Actor Memory Allocation, run-sync-get-dataset-items, Web Scraping Optimization, Serverless Resource Management.

Comments