Skip to main content
Version: Next

Apify API client for JavaScript

The Apify API client is the official library to access the Apify REST API from your JavaScript/TypeScript applications. It runs both in Node.js and browser and provides useful features like automatic retries and convenience functions that improve the experience of using the Apify API.

The client simplifies interaction with the Apify platform by providing:

  • Intuitive methods for working with Actors, datasets, key-value stores, and other Apify resources
  • Intelligent parsing of API responses and rich error messages for debugging
  • Built-in exponential backoff for failed requests
  • Full TypeScript support with comprehensive type definitions
  • Cross-platform compatibility in Node.js v16+ and modern browsers

All requests and responses (including errors) are encoded in JSON format with UTF-8 encoding.

For installation instructions, check the Getting Started Guide.

Quick example

Here's an example showing how to run an Actor and retrieve its results:

import { ApifyClient } from 'apify-client';

// Initialize the client with your API token
const client = new ApifyClient({
token: 'YOUR-APIFY-TOKEN',
});

// Start an Actor and wait for it to finish
const run = await client.actor('apify/web-scraper').call({
startUrls: [{ url: 'https://example.com' }],
maxCrawlPages: 10,
});

// Get results from the Actor's dataset
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);

You can find your API token in the Integrations section of Apify Console. See the Getting Started Guide for more details on authentication.