# Call the API directly

The DFO API uses JSON over HTTPS at `https://developmentfinance.org/api/v1`. You can try it without a key. Create an API key before you build with it. If you use Python or TypeScript, start with the [SDK quickstart](/docs/start/quickstart). Call the API directly from a language other than Python or TypeScript, or for operations the SDKs do not cover. The OpenAPI document at `https://developmentfinance.org/openapi.json` describes all 73 operations.

## The four parts of the API

| Path                   | What it does                                                                                     |
| ---------------------- | ------------------------------------------------------------------------------------------------ |
| `/api/v1/search`       | Turns a question in plain words into a spec and a sentence giving search's interpretation of it. |
| `/api/v1/datasets`     | Builds a dataset from a spec and serves its versions as files.                                   |
| `/api/v1/graph`        | Looks up places, indicators, provenances, and the ontology that describes them.                  |
| `/api/v1/presentation` | Stores charts, tables, and cards, and publishes them as shares.                                  |

Two ids connect these parts. A `spec_id`, such as `spec_3c6c8e8b57cceb3350ba19c3b59df1f1`, identifies a spec (indicator, places, years, and source). A `content_version`, such as `cv_b8706e8a1459d68a2b78114986e03b83`, identifies the rows built from that spec. A spec gets a new `content_version` when the publisher releases new data.

## Get a dataset

These steps use `curl` and `jq`.

### 1. Ask the question

```bash
export DFO_API=https://developmentfinance.org

curl -fsS -X POST "$DFO_API/api/v1/search/resolve" \
  -H "Content-Type: application/json" \
  -d '{"input":{"kind":"raw_text","query":"ODA from Germany to Nigeria"}}' \
  > resolve.json

jq '{kind, status: .parts[0].status, spec_id: .parts[0].spec.spec_id,
     sentence: .parts[0].spec.resolved.rendered_sentence}' resolve.json
```

```json
{
  "kind": "resolution",
  "status": "definite",
  "spec_id": "spec_3c6c8e8b57cceb3350ba19c3b59df1f1",
  "sentence": "Germany's net disbursements (bilateral flows) to Nigeria for official development assistance, 1960 to 2024. Current US dollars · OECD DAC2a."
}
```

Check `kind` before you read `parts`. Only a `resolution` includes `parts`, and the other kinds are `catalogue` and `declined`. Then check that each part's `status` is `definite`, and read `rendered_sentence`. The other statuses are `candidates`, `no_data`, and `unsupported`. Search uses a model, so a wrong interpretation can produce a plausible dataset for the wrong question.

### 2. Build the dataset

Post the spec to `/api/v1/datasets`.

```bash
jq '{schema_version: 1,
     input: {kind: "spec_id",
             spec_id: .parts[0].spec.spec_id,
             definition: .parts[0].spec.definition},
     options: {format: "parquet"}}' resolve.json > mint.json

curl -fsS -X POST "$DFO_API/api/v1/datasets" \
  -H "Content-Type: application/json" \
  -d @mint.json > manifest.json

jq '{content_version, rows: .coverage.rows, retention}' manifest.json
```

```json
{
  "content_version": "cv_b8706e8a1459d68a2b78114986e03b83",
  "rows": 65,
  "retention": {
    "pinned": false,
    "held_until": "2026-12-16T16:29:03.298584Z"
  }
}
```

Small requests return a manifest immediately. Large requests, such as datasets over 100,000 rows, return `202 Accepted` with an `operation` object. Poll the path in `operation.poll` every `operation.retry_after_ms` milliseconds until `operation.status` is `done`, then read the manifest from the poll response's `manifest` field.

```bash
if jq -e '.operation' manifest.json > /dev/null; then
  poll="$(jq -r '.operation.poll' manifest.json)"
  until [ "$(jq -r '.operation.status' manifest.json)" = "done" ]; do
    sleep "$(jq -r '.operation.retry_after_ms / 1000' manifest.json)"
    curl -fsS "$DFO_API$poll" > manifest.json || exit 1
  done
  jq '.manifest' manifest.json > done.json && mv done.json manifest.json
fi
```

If the build fails, the poll returns an `operation_failed` error, which stops the `curl -f` loop.

### 3. Download the file

The manifest lists the files built for this version under `artifacts`. Download the Parquet bundle, which contains the data with its citation and sources.

```bash
url="$(jq -r 'first(.artifacts[] | select(.rendering.format == "parquet" and .rendering.bundle == true)) | .url' manifest.json)"
curl -fsSL "$DFO_API$url" -o bundle.zip
unzip -Z1 bundle.zip
```

```text
data/oecd-dac2a.parquet
CITATION.cff
README.md
SOURCES.md
data/codes.csv
datapackage.json
```

Follow redirects (`-L`), because a file URL can redirect to storage. Inside the bundle, `datapackage.json` lists the data file, `CITATION.cff` gives the citation, and `SOURCES.md` lists the licences and processing steps.

### 4. Fetch the same version later

Keep `spec_id` and `content_version`. A `GET` request to this path returns the same manifest and files while the DFO stores that version.

```bash
curl -fsS "$DFO_API/api/v1/datasets/spec_3c6c8e8b57cceb3350ba19c3b59df1f1/cv_b8706e8a1459d68a2b78114986e03b83"
```

`retention.held_until` gives the expiry timestamp for an unpinned version. The DFO keeps pinned versions indefinitely. [Updates and revisions](/docs/data/updates-and-revisions) explains the retention rules.

### 5. Pin the version and cite it

Pin the version to keep it indefinitely and get its link. Pass the `artifact_digest` of one file from the manifest's `artifacts`. The pin keeps that file and the version's rows.

```bash
curl -fsS -X POST "$DFO_API/api/v1/datasets/spec_3c6c8e8b57cceb3350ba19c3b59df1f1/cv_b8706e8a1459d68a2b78114986e03b83/pin" \
  -H 'Content-Type: application/json' \
  -d '{"schema_version": 1, "artifact_digest": "sha256:<digest from artifacts>"}'
```

In the response, `pinned.url` is the link to the version's page on /data. Cite that link. A new pin counts against the caller's daily limit of 100 pins. Pinning a version that is already pinned does not count. Requests past the limit return `429` with the code `allowance_exhausted`.

## Errors

Error responses follow RFC 9457 with the content type `application/problem+json`.

```json
{
  "type": "/codes/snapshot_not_found",
  "title": "Snapshot Not Found",
  "status": 404,
  "detail": "'spec_3c6c8e8b57cceb3350ba19c3b59df1f1' has no version at content_version 'cv_00000000000000000000000000000000'",
  "code": "snapshot_not_found",
  "trace_id": "a32b89f54e18451f8e7471a8020f5bee",
  "capability_version": "dset_bb3ffa4a52e70ae3",
  "retryable": false
}
```

Branch on `code`, which is stable. `detail` is for people, and its wording can change. `retryable` is `true` when the same call can succeed later. `GET /codes/{code}` (the path in `type`) returns a description of any error code. Quote `trace_id` when you report a problem.

## Limits

Without a key, a client gets 20 calls a minute on most endpoints and 300 a minute on routes under `/api/v1/datasets/`. API responses include `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Reset` (seconds until the minute's count restarts). Dataset versions and files can come from the site's cache, and those responses have no rate-limit headers. Calls over the limit return `429` with the code `rate_limited`. [Keys and limits](/docs/build/keys-and-limits) lists every limit and explains how to send a key.
