# SDKs

> What the Python and TypeScript SDKs cover today (the Crawl API, POST /v1/serp and usage), how to install them, and how to call the compatible endpoints over HTTP.

There are two official SDKs, for Python and TypeScript. Both cover the Crawl API, `POST /v1/serp` and `GET /v1/usage`.

> **Note:** The SDKs don't wrap the compatible SERP, Pages, AI answers, Business and Ads endpoints yet. Call those over HTTP, as in every example in these docs, or with an existing DataForSEO v3 client pointed at our base URL. See [Migrate from DataForSEO](https://dataforgaio.com/docs/migrate-from-dataforseo.md).

## What they cover

| Python | TypeScript | Endpoint |
|---|---|---|
| `crawl(url, output_format=, include_receipt=, project_id=)` | `crawl(url, { outputFormat, includeReceipt, projectId })` | `POST /v1/crawls` |
| `crawl_batch(urls, webhook_url=, output_format=, include_receipt=, project_id=)` | `crawlBatch(urls, { webhookUrl, ... })` | `POST /v1/crawls/batch` |
| `get_crawl(ref, include_receipt=)` | `getCrawl(ref, { includeReceipt })` | `GET /v1/crawls/{ref}` |
| `wait_for_batch(job_id, timeout=600, poll_interval=2, max_poll_interval=15)` | `waitForBatch(jobId, { timeoutMs, pollIntervalMs, maxPollIntervalMs })` | Polls `GET /v1/crawls/{ref}` |
| `get_receipt(ref)` | `getReceipt(ref)` | `GET /v1/crawls/{ref}/receipt` |
| `serp(keyword, search_engine=, country=, language=, device=)` | `serp(keyword, { searchEngine, country, language, device })` | `POST /v1/serp` |
| `usage()` | `usage()` | `GET /v1/usage` |

`ref` is a batch `job_id` (`job_...`) or a task id (`cr_...`). Responses are the API's own JSON, with its snake_case field names.

The crawl methods don't take `auto_upgrade`, `max_level` or `max_cost` yet, so they use the API defaults. To set a ceiling, call `POST /v1/crawls` directly.

## Python

```bash
pip install dataforgaio
pip install "dataforgaio[langchain]"    # adds DataForGAIOLoader
pip install "dataforgaio[llamaindex]"   # adds DataForGAIOReader
```

```python
from dataforgaio import DataForGAIO

client = DataForGAIO()  # reads DATAFORGAIO_API_KEY; or DataForGAIO(api_key="dg_...")

result = client.crawl("https://example.com", output_format="markdown")
task = result["tasks"][0]
print(task["status"], task["content"]["title"], task["receipt"]["billed_usd"])

job = client.crawl_batch(["https://example.com/a", "https://example.com/b"])
done = client.wait_for_batch(job["job_id"], timeout=600)
```

- Sync `DataForGAIO` and async `AsyncDataForGAIO` clients. Python 3.9 or later; the only runtime dependency is `httpx`.
- `DataForGAIOLoader` (LangChain) and `DataForGAIOReader` (LlamaIndex) put every receipt field in each document's metadata and skip pages whose `content_check` isn't `substantive` (pass `include_non_substantive=True` to keep them).
- Default base URL `https://api.dataforgaio.com/v1`, overridable with `base_url=` or `DATAFORGAIO_BASE_URL`.

## TypeScript

```bash
npm install @dataforgaio/sdk
```

```ts
import { DataForGAIO } from '@dataforgaio/sdk';

const client = new DataForGAIO(); // reads DATAFORGAIO_API_KEY

const result = await client.crawl('https://example.com', { outputFormat: 'markdown' });
const task = result.tasks[0]!;
console.log(task.status, task.content?.title, task.receipt?.billed_usd);
```

- No runtime dependencies; uses the built-in `fetch`. ESM and CommonJS builds for Node 18 or later, Deno, Bun and edge runtimes.
- Client options: `apiKey`, `baseUrl`, `timeoutMs` (default 120 s), `maxRetries`, `headers`, `fetch`. Every method accepts an `AbortSignal` as `signal`.

## Errors and retries (both SDKs)

| Error | HTTP | API `code` |
|---|---|---|
| `AuthError` | 401, 403 | `unauthorized`, `forbidden` |
| `InsufficientBalance` | 402 | `balance_required` |
| `InvalidRequest` | 400, 422 | `invalid_request`, `invalid_target` |
| `NotFound` | 404 | `not_found` |
| `RateLimited` | 429 | `rate_limited` (with `retry_after` in seconds) |
| `APIError` | anything else | e.g. `not_configured` |

Both retry up to `max_retries` / `maxRetries` times (default 2): 429 on any method, honoring `Retry-After` up to 60 s; 5xx and network errors on `GET`, with exponential backoff and full jitter; and connection failures on `POST` where the request never reached us. A `POST` isn't retried after a 5xx or a read timeout, since the crawl or search may already have run. See [Retrying safely](https://dataforgaio.com/docs/retrying-safely.md).

## Calling the compatible endpoints

Until the SDKs cover them, a few lines of HTTP do the job:



```python title="Python"
import os
import requests

def dfg(path, tasks):
    res = requests.post(
        f"https://api.dataforgaio.com/v1/{path}",
        auth=("api", os.environ["DATAFORGAIO_API_KEY"]),
        json=tasks,
        timeout=180,
    )
    res.raise_for_status()
    return res.json()

body = dfg("serp/google/organic/live/advanced",
           [{"keyword": "web data api", "location_code": 2840, "language_code": "en", "max_cost": 0.002}])
```

```ts title="TypeScript"
async function dfg(path: string, tasks: object[]) {
  const auth = Buffer.from(`api:${process.env.DATAFORGAIO_API_KEY}`).toString('base64');
  const res = await fetch(`https://api.dataforgaio.com/v1/${path}`, {
    method: 'POST',
    headers: { Authorization: `Basic ${auth}`, 'Content-Type': 'application/json' },
    body: JSON.stringify(tasks),
  });
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
  return res.json();
}

const body = await dfg('serp/google/organic/live/advanced', [
  { keyword: 'web data api', location_code: 2840, language_code: 'en', max_cost: 0.002 },
]);
```



Task-level errors arrive inside an HTTP 200, so check each `tasks[].status_code` as well.
