ScrayleClient
The main entry point for the Scrayle SDK. Provides access to all services.
Constructor
import { ScrayleClient } from '@scrayle/sdk';
const client = new ScrayleClient(config?: ScrayleConfig);Configuration
interface ScrayleConfig {
apiKey?: string; // Reads SCRAYLE_API_KEY env var if not set
scrayleHub?: 'eu' | 'us' | 'asia'; // Compute hub (see Scrayle Hub below)
baseApiUrl?: string; // Default: https://api.scrayle.com
actorApiUrl?: string; // Default: https://api.scrayle.com
storageApiUrl?: string; // Default: https://storage.scrayle.com
browserApiUrl?: string; // Default: https://api.scrayle.com
scrapingCrawlApiUrl?: string; // Default: https://api.scrayle.com
timeout?: number; // Default: 30000 ms
}Services
Access services through the client instance:
client.browser // BrowserService - Cloud browser sessions
client.scraping // ScrapingService - Scraping tasks
client.universal // UniversalService - Web unlocking
client.captcha // CaptchaService - CAPTCHA solving
client.proxies // ProxiesService - Proxy management
client.actor // ActorService - Scraper management
client.profiles // ProfilesService - Browser profiles
client.scrapingCrawl // ScrapingCrawlService - Scrape & Crawl
client.storage // IStorageService - KV, Dataset, Object, QueueScrayle Hub
Use scrayleHub to route all API calls to the hub closest to your data source. This is separate from proxyCountry - the hub is where Scrayle's servers process your request, not where the proxy exit IP is located. Individual URL overrides take precedence.
| Hub | Value | Base URL |
|---|---|---|
| Europe (default) | eu | https://api.scrayle.com |
| United States | us | https://usapi.scrayle.com |
| Asia Pacific | asia | https://asiaapi.scrayle.com |
// Use the US hub for lower latency from North America
const client = new ScrayleClient({
apiKey: process.env.SCRAYLE_API_KEY,
scrayleHub: 'us',
});
// proxyCountry is independent - this scrapes via a German exit IP
const result = await client.scrapingCrawl.scrapeUrl('https://example.de', {
proxyCountry: 'DE',
});
// Or set via environment variable
// SCRAYLE_HUB=usStorage Mode
The storage service switches between HTTP (remote) and local filesystem based on the SCRAYLE_IS_ONLINE environment variable:
// HTTP storage (connects to Scrayle Storage API)
SCRAYLE_IS_ONLINE=true
// Local storage (saves to ./storage/ directory)
SCRAYLE_IS_ONLINE=false (default)Aliases
// These are equivalent
import { ScrayleClient } from '@scrayle/sdk';
import { Scrayle } from '@scrayle/sdk';Example
import { ScrayleClient } from '@scrayle/sdk';
const client = new ScrayleClient({
apiKey: process.env.SCRAYLE_API_KEY,
timeout: 60000,
});
// Use any service
const result = await client.scrapingCrawl.scrapeUrl('https://example.com');
const proxyUrl = client.proxies.createProxy({ country: 'US' });
const profile = await client.profiles.create('my-profile');