Skip to content
oslew
Get a free key

APIs

Batch geocoding API

A batch geocoding API geocodes a whole file of addresses as one job, rather than one request per address. oslew accepts a CSV or JSON lines upload of up to 2,000,000 rows, works through it at the submitting key’s own address rate, and returns one answer per input row, in the original order, carrying your ids. There is no separate batch price and no separate batch allowance: each row costs what a single geocode costs, and the job survives the server that accepted it.

Last reviewed

Geocoding a file one request at a time means writing a pacer, a retry loop, a checkpoint and a way to resume after a crash — and then running it somewhere for as long as the file takes. A batch job moves all of that to the service. You upload the file once, poll a status that says how long is left, and download the answers once, joined to your own ids.

Four calls make a job

  • Submit the file with POST /v1/batch, naming its format. The input is stored before the service replies, so once you hold a job id, the job exists independently of the server that took it.
  • Follow it with GET /v1/batch/{id}: its state, how many rows are done and found, and remaining_s, the seconds the rest should take at the job’s rate.
  • Collect the answers with GET /v1/batch/{id}/results when the state is done, as CSV or JSON lines, whichever format the input was in.
  • Delete it with DELETE /v1/batch/{id} when you have the results, if you do not want the file kept. GET /v1/batch lists the account’s jobs, newest first.

Preparing the file

The body of the upload is the file itself, in UTF-8, at most 64 MiB and 2,000,000 rows. The format query parameter decides how it is read — csv, or jsonl, the default — and the Content-Type header is ignored. A CSV sent without format=csv is read as JSON lines, where a line that is not a JSON object is taken to be an address, so the job is accepted and geocodes the header row and every comma-joined line as if each were one address. Always name the format.

In a CSV, the first non-blank line is the header. The address column may be called q, address, query or text, matched without regard to case but otherwise exactly, so a stray space before a name makes it a different column. An id column comes back on each answer; a near column, quoted because it contains a comma, filters that row to a city-sized cell around a point. Other columns are ignored. No field may contain a line break, and a byte-order mark from a spreadsheet export is not stripped, so it becomes part of the first column’s name.

In JSON lines, each line is an object with the address under one of the same four names and optional string id and near fields — or simply the address itself, for the common case of a text file with one address per line. The whole file is checked before anything is stored, and one bad row refuses all of it, with the row number in the error.

Throughput is your rate multiplied by time

A job takes one token per row from the submitting key’s address bucket, as fast as the bucket refills. That bucket is the same one the key’s geocodes, validations and time-zone lookups draw on, and that single fact is the whole pricing model: bulk and interactive work share one budget per key, and neither has an allowance of its own. The job reports the rate it is paced at as rps.

So the time a file needs is its row count divided by the key’s rate. Take a hypothetical file of 250,000 addresses. On the Address plan, at 20 rows a second, it needs about three and a half hours. On Scale, at 100 a second, it needs a little over forty minutes. On the Free plan, at 1 a second, it needs nearly three days — fine for a trial on a sample, not for the whole file. At high rates the geocoder itself can become the slower of the two, so treat remaining_s as a floor rather than a promise.

Because the job spends the key’s whole rate, two habits matter:

  • Give bulk work its own key. A backfill running on the key your checkout uses will crowd the checkout out, and the checkout’s requests will meet HTTP 429. A key minted for batch work keeps the two apart.
  • Poll slowly, or from another key. Progress is written every five hundred rows, so polling every few seconds learns nothing and spends tokens the job would have used. Jobs belong to the account, not the key, so a second key of the same account can follow, collect and cancel without touching the job’s bucket.

What comes back

The results hold one row per input row, in input order, each carrying your id. Every row is geocoded exactly as a single geocode would be with one result requested, the row’s own near, and interpolation on. That means the tie count is still taken over the full set of candidates the search kept, so asking for one answer per row does not hide an ambiguous address.

Each row carries the matched name, position, precision and precision_m, the calibrated confidence, tied_at_top, and the address in normalised parts and as one line. A row that matched nothing, or whose own near did not parse, carries an error instead, and one bad row never fails the job. found in the status counts rows that got a position, not rows that are right: an answer on the wrong street is still found. A batch row has no why field and no provenance column; its rows come from the permissively licensed address and place layers, and a row whose evidence you need to inspect can be sent to the single geocode route on its own.

Asking for results before the job is done returns 409, not 404, with the progress a poller needs. Results arrive as one response, so for a large job, stream them to a file rather than reading them into memory. Deciding which rows to accept, which to review and which to reject is a workflow of its own, set out in the customer data clean-up use case.

Parts, leases and takeover

A running job writes its output in parts of 50,000 rows, and the server working on it renews a lease as it writes progress. If that server stops — a crash, an eviction — another server takes the job over once the lease has gone 90 seconds without renewal, and resumes from the last complete part. The rows after that part are geocoded again and take tokens again, but the output still has exactly one row per input row. A server shutting down cleanly for a deploy hands its jobs back at once instead of waiting out the lease.

One consequence is worth knowing. The server that resumes a job does not know which key submitted it, so the remainder is no longer paced by that key’s bucket, and revoking the key no longer stops it. It may finish sooner than remaining_s said. To stop a job, delete it.

Retention and deletion

A batch job keeps the uploaded file and every result part until the job is deleted; there is no expiry. That is deliberate — a job has to be able to resume elsewhere, and its results have to be collectable later — but it makes a batch job the one place your raw addresses persist on the service. Deleting a batch job deletes its input and its result parts; the job’s record — id, state, counts and times — stays in the list. Deleting a finished job is how its data is removed; deleting a running one cancels it within a few hundred rows.

The query log records none of it: Request bodies are not logged: not the Wi-Fi and cell ids a device saw, not a map-matching trace, not a batch file’s rows. Another account’s job id answers 404, the same as an id nobody issued. The security page sets out what else is and is not kept. In a dedicated deployment the operator decides where job data lives: Batch jobs — the uploaded file, the result parts and the job’s state — are written to the index’s own store, or to GEO_BATCH_STORE when it is set.

When a job fails

A job stops as failed, with a reason, if the submitting key is revoked or its account suspended, if the key’s plan changes to one without the Address product, or if its stored input cannot be read back after a takeover. A failed job’s results cannot be collected, even for the rows it finished, so rotate keys after a large job rather than during one, then resubmit the file once the cause is fixed.

What it costs

Batch geocoding is part of the Address product, on every plan. The Address plan is $99 a month for 20 requests a second sustained, burst 100; Scale is $999 a month for 100 requests a second sustained, burst 300. A job costs nothing beyond the rate it occupies while it runs, and the pricing page lists every plan’s address rate. The rate limits explainer covers why a rate, rather than a monthly allowance, suits a backfill that runs once.

Limits worth knowing

  • 2,000,000 rows and 64 MiB per job; split anything larger.
  • A job runs at one key’s rate. A higher plan, not a second job, makes the same file finish sooner.
  • No line breaks inside fields, and a byte-order mark breaks the first column’s name.
  • Results carry no why and no provenance column.
  • Files and results are kept until you delete the job. Delete it once you have what you need.

Bottom line

Use a batch job for any file of addresses you would otherwise loop over: name the format, give it its own key, wait as long as it says, and collect one row per input row. Then delete the job, and read each row’s precision, confidence and tie count before you trust it.

Questions

How large a file can a batch geocoding job take?

Up to 2,000,000 rows and 64 MiB per job, in UTF-8. A larger body is refused before anything is stored, and so is a file with more rows. Split a bigger file into several jobs; each job is paced by the key that submitted it, so several jobs on one key share that key’s rate rather than multiplying it.

How long does a batch geocoding job take?

Rows divided by the submitting key’s address rate. Each row takes one token from the same bucket a single geocode uses, as fast as the bucket refills. The job reports the seconds it expects to need as it runs; at high rates the geocoding itself can be slower than the bucket, so treat that estimate as a floor.

Is batch geocoding priced differently from single requests?

No. There is no batch price and no batch allowance. A job spends the key’s address rate one row at a time, exactly as a loop of single geocodes would, except that the service does the pacing, retrying and resuming for you. A plan with a higher address rate finishes the same file sooner at the same monthly price.

How long are my uploaded files kept?

A batch job keeps the uploaded file and every result part until the job is deleted; there is no expiry. Deleting a batch job deletes its input and its result parts; the job’s record — id, state, counts and times — stays in the list. If a file held customer addresses, collect the results and delete the job.

What happens if a server fails in the middle of a job?

Another server takes the job over once the first has let its lease lapse for 90 seconds, and resumes from the last complete part of the output. Rows after that part are geocoded again, so the output still has exactly one row per input row, with no gaps and no duplicates.

Browse every page →