# REST API guide

> Call Cozybit's Apify tools from code: Bearer auth, run-sync-get-dataset-items for small calls, async runs for batches, spend caps and actor IDs.

Source: https://cozybit.dev/integrations/api/

Integrations

Run any Cozybit tool from your own code with Apify's REST API or its Python and JavaScript clients. You authenticate with one header, and every run can carry a spend cap.

## Authentication

Create a free Apify account, then copy your API token in Apify Console under *Settings, API & Integrations*. Keep it in an environment variable and send it as a header:

**Header**

```text
Authorization: Bearer $APIFY_TOKEN
```

Never put the token in a URL (`?token=`): URLs end up in logs, browser history and proxies.

## The four endpoints you need

| To | Call |
|---|---|
| Run a tool and get its records in one call (up to 300 s) | `POST /v2/acts/ACTOR_ID/run-sync-get-dataset-items` |
| Start a run and return at once | `POST /v2/acts/ACTOR_ID/runs` |
| Check a run, or wait up to 60 s for it | `GET /v2/actor-runs/RUN_ID?waitForFinish=60` |
| Read a run's records as JSON, CSV or Excel | `GET /v2/datasets/DATASET_ID/items?format=json` (or `csv`, `xlsx`) |

All under `https://api.apify.com`. The request body of a run is the tool's input as JSON.

## Synchronous: a few items per call

Best for interactive use and small lookups. The call returns the dataset items directly.

**curl**

**YouTube Transcripts, one video**

```bash
curl -sS --max-time 310 -X POST \
  "https://api.apify.com/v2/acts/mzceZowBx7VrobetK/run-sync-get-dataset-items?maxTotalChargeUsd=0.10" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://www.youtube.com/watch?v=jNQXAC9IVRw"], "languages": ["en"], "includeSegments": false}'
```

**Python**

**apify-client 3.x**

```python
# pip install apify-client
import os
from decimal import Decimal

from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("mzceZowBx7VrobetK").call(
    run_input={
        "urls": ["https://www.youtube.com/watch?v=jNQXAC9IVRw"],
        "languages": ["en"],
        "includeSegments": False,
    },
    max_total_charge_usd=Decimal("0.10"),  # spend cap for this run
)
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item.get("status"), item.get("title"))
```

**JavaScript**

**apify-client 2.x, Node 18+**

```javascript
// npm install apify-client
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('mzceZowBx7VrobetK').call(
  {
    urls: ['https://www.youtube.com/watch?v=jNQXAC9IVRw'],
    languages: ['en'],
    includeSegments: false,
  },
  { maxTotalChargeUsd: 0.1 }, // spend cap for this run
);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
for (const item of items) console.log(item.status, item.title);
```

- The call waits at most 300 seconds, then answers HTTP 408; the run itself continues. Serverless functions usually stop sooner.
- Don't retry a timed-out POST automatically; check your runs in Console first, or you may pay twice.

## Asynchronous: batches and long jobs

Start the run, wait for it, then read the records. Use this for many items, whole playlists, states or registers.

**Start, wait, read**

```bash
# 1. Start a run; the answer comes back at once
curl -sS -X POST "https://api.apify.com/v2/acts/mzceZowBx7VrobetK/runs?maxTotalChargeUsd=1" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d @input.json
# The answer's data.id is RUN_ID and data.defaultDatasetId is DATASET_ID.

# 2. Wait up to 60 s per call until data.status is SUCCEEDED
curl -sS "https://api.apify.com/v2/actor-runs/RUN_ID?waitForFinish=60" \
  -H "Authorization: Bearer $APIFY_TOKEN"

# 3. Read the records as JSON, CSV or Excel (format=json, csv or xlsx)
curl -sS "https://api.apify.com/v2/datasets/DATASET_ID/items?format=csv" \
  -H "Authorization: Bearer $APIFY_TOKEN" -o results.csv
```

Instead of polling, you can let Apify call a webhook of yours when a run finishes, or use the Zapier and Make triggers for finished runs.

## Spend control

Every run accepts `maxTotalChargeUsd`, as a query parameter or a client option. The run stops cleanly when the next result would exceed it, and you keep what was delivered. Each tool also has a `maxResults`-style input to limit rows.

During the trial until 31 Dec 2026 every result costs 0.00001 USD, so a 0.10 USD cap allows up to 10,000 results. See [pricing](https://cozybit.dev/pricing/).

## Records and statuses

Every record has the fields documented on its tool page. Most tools add a `status` and an `error` message to each record; the job tools report each board's outcome in the run's `RUN_SUMMARY`. Failed items stay in the output so you can inspect them, and errors are never charged.

## Actor IDs

| Tool | Actor ID (never changes) | Name |
|---|---|---|
| [YouTube Transcript Scraper](https://cozybit.dev/tools/youtube-transcripts/) | `mzceZowBx7VrobetK` | `cozybit/youtube-transcript-scraper` |
| [Google Trends API](https://cozybit.dev/tools/google-trends/) | `G4aJjtT7Oiw6gMaAG` | `cozybit/google-trends-scraper` |
| [Google Hotels Scraper](https://cozybit.dev/tools/google-hotels/) | `YC0mAdrRhMBogWXUm` | `cozybit/google-hotels-scraper` |
| [Hotel Price Comparison](https://cozybit.dev/tools/hotel-booking-prices/) | `z5dWV7FhZ6tlo9zgF` | `cozybit/google-hotels-booking-prices` |
| [Google Flights Scraper](https://cozybit.dev/tools/google-flights/) | `rTAa68kee8wUtPb3d` | `cozybit/google-flights-scraper` |
| [Greenhouse, Lever & Ashby Jobs Scraper](https://cozybit.dev/tools/greenhouse-lever-ashby-jobs/) | `NqfY1akFLdBLjtCwM` | `cozybit/greenhouse-lever-ashby-jobs-scraper` |
| [EU Pay Transparency Checker](https://cozybit.dev/tools/eu-pay-transparency/) | `T1Rddpght86iXfGQm` | `cozybit/eu-pay-transparency-checker` |
| [US Hospital Price Transparency](https://cozybit.dev/tools/hospital-prices/) | `UOauyR6iKMKP6ZCa2` | `cozybit/hospital-price-transparency` |
| [UK Visa Sponsor Register](https://cozybit.dev/tools/uk-visa-sponsors/) | `xmc5KprXtajpboQQR` | `cozybit/uk-sponsor-register` |
| [UK Gambling Licence Register](https://cozybit.dev/tools/uk-gambling-licences/) | `wWvHi6YQHyk6X9raL` | `cozybit/uk-gambling-licence-register` |
| [Peppol Directory Lookup](https://cozybit.dev/tools/peppol-directory/) | `qMyzrf2IKcdsPlGOd` | `cozybit/peppol-directory-registrations` |

Use the ID in code: names can be renamed, IDs cannot. The machine-readable list with example inputs is in [catalog.json](https://cozybit.dev/catalog.json).
