[Functions](https://cdpfleet.com/docs/functions)

# Geo compare

The same page from 2–5 countries at once, side by side, with a diff of what changes between them. `POST https://cdpfleet.com/v1/functions/geo` → `application/json`.

 

```bash
curl -s https://cdpfleet.com/v1/functions/geo \
  -H "x-api-key: $CDPFLEET_API_KEY" -H "content-type: application/json" \
  -d '{"url":"https://www.google.com/","countries":["us","de","jp"],"formats":["markdown","screenshot"]}' -o geo.json -D - | grep -i '^x-call-id'
```

```js
// Node.js 18+: save as geo.mjs, run node geo.mjs
const res = await fetch('https://cdpfleet.com/v1/functions/geo', {
  method: 'POST',
  headers: { 'x-api-key': process.env.CDPFLEET_API_KEY, 'content-type': 'application/json' },
  body: JSON.stringify({
    url: 'https://www.google.com/',
    countries: ['us', 'de', 'jp'],
    formats: ['markdown', 'screenshot'],
  }),
  signal: AbortSignal.timeout(30000),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`); // 429: wait Retry-After seconds
console.log(await res.text());
```

```python
# Python 3 with requests (pip install requests): save as geo.py, run python geo.py
import os
import requests

r = requests.post(
    "https://cdpfleet.com/v1/functions/geo",
    headers={"x-api-key": os.environ["CDPFLEET_API_KEY"]},
    json={
        "url": "https://www.google.com/",
        "countries": ["us", "de", "jp"],
        "formats": ["markdown", "screenshot"],
    },
    timeout=30,
)
if not r.ok:
    raise SystemExit(f"{r.status_code} {r.text}")  # 429: wait r.headers["Retry-After"] seconds
print(r.text)
```

```java
// Java 17+: save as Main.java, run java Main.java
import java.net.URI;
import java.net.http.*;
import java.time.Duration;

public class Main {
  public static void main(String[] args) throws Exception {
    String body = """
        {
          "url": "https://www.google.com/",
          "countries": ["us", "de", "jp"],
          "formats": ["markdown", "screenshot"]
        }
        """;
    HttpResponse<byte[]> res = HttpClient.newHttpClient().send(
        HttpRequest.newBuilder(URI.create("https://cdpfleet.com/v1/functions/geo"))
            .header("x-api-key", System.getenv("CDPFLEET_API_KEY"))
            .header("content-type", "application/json")
            .timeout(Duration.ofSeconds(30))
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build(),
        HttpResponse.BodyHandlers.ofByteArray());
    if (res.statusCode() != 200) { // 429: wait Retry-After seconds
      throw new RuntimeException(res.statusCode() + " " + new String(res.body()));
    }
    System.out.writeBytes(res.body()); // UTF-8 as it came
    System.out.println();
  }
}
```

```csharp
// .NET 8+: dotnet new console, replace Program.cs with this, run dotnet run
using System.Text;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("CDPFLEET_API_KEY"));
var body = """
    {
      "url": "https://www.google.com/",
      "countries": ["us", "de", "jp"],
      "formats": ["markdown", "screenshot"]
    }
    """;
var res = await http.PostAsync("https://cdpfleet.com/v1/functions/geo",
    new StringContent(body, Encoding.UTF8, "application/json"));
if (!res.IsSuccessStatusCode) // 429: wait Retry-After seconds
    throw new Exception($"{(int)res.StatusCode} {await res.Content.ReadAsStringAsync()}");
Console.WriteLine(await res.Content.ReadAsStringAsync());
```

```go
// Go 1.21+: save as main.go, run go run main.go
package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"strings"
	"time"
)

func main() {
	body := `{
	  "url": "https://www.google.com/",
	  "countries": ["us", "de", "jp"],
	  "formats": ["markdown", "screenshot"]
	}`
	req, _ := http.NewRequest("POST", "https://cdpfleet.com/v1/functions/geo", strings.NewReader(body))
	req.Header.Set("x-api-key", os.Getenv("CDPFLEET_API_KEY"))
	req.Header.Set("content-type", "application/json")
	res, err := (&http.Client{Timeout: 30 * time.Second}).Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
	data, err := io.ReadAll(res.Body)
	if err != nil {
		log.Fatal(err)
	}
	if res.StatusCode != http.StatusOK { // 429: wait Retry-After seconds
		log.Fatalf("%s %s", res.Status, data)
	}
	fmt.Println(string(data))
}
```

## Fields

| Field | Type | Default | What it does |
| --- | --- | --- | --- |
| `url` | string | required | The page to load. A public `http` or `https` address: private, loopback, link-local, CGNAT and cloud-metadata addresses, `localhost`, `.local`/`.internal` names and names that resolve to them are refused (`400 invalid_url`). |
| `country` | string | `"random"` | Two-letter country for the exit IP and for the page's locale, timezone, geolocation and `Accept-Language` (see [countries](#countries)); `"random"` picks one. Unknown codes: `400 invalid_country`. |
| `max_wait` | number | `20` | Seconds to wait for the page to load, 1–60 (`400 invalid_option` otherwise). The whole call returns within about `max_wait` + 5 s, so a client timeout of `max_wait` + 10 s is safe. A page that is still loading then comes back partial (below); one that never started: `408 page_timeout`. |
| `proxy` | string or string\[\] | the Community proxy | Omit it to use the free Community proxy in `country`. Or: your own proxy URL (`http://`, `https://`, `socks5://`), a list (one is picked per call), a `cdpfleet-plan…` token, or a residential `cdpfleet-resi…` token (tier, country, device OS, sticky session) billed per GB to your residential balance ([proxies](https://cdpfleet.com/docs/proxies)). `proxy_rules` isn't supported yet (`400 invalid_option`). |
| `countries` | string\[\] | required | 2–5 [country codes](#countries), no duplicates. The first is the baseline the others are compared with. Each runs through the Community proxy in that country, unless you pass `proxy`. |
| `formats` | string\[\] | `["screenshot", "markdown"]` | Any [scrape](https://cdpfleet.com/docs/functions/scrape) formats, returned per country. |

## Good to know

-   Response: `results {us: {status, url, partial?, …formats}, de: {…}}` and `diff {markdown: {de: "--- us\n+++ de\n…"}}` — a unified diff of each text format (`markdown`, `text`, `html`) against the first country. `url` is where each country ended up after redirects (a site may send a country to another domain).
-   A country that fails gets `error` in its result instead of failing the call, and its diff is `null` — as is every diff when the first country fails; `""` means the pages were identical.
-   Where a site places an exit is up to the site: it can read a Community exit as another country than the one asked for (case [geo compare](https://cdpfleet.com/docs/cases/geo-compare)). Check each country's `url`, language and currency before relying on it.
-   The countries run in parallel, so the call holds one thread per country while it runs.

Billing, errors and countries: [Functions](https://cdpfleet.com/docs/functions).

---
Source: https://cdpfleet.com/docs/functions/geo · Markdown: https://cdpfleet.com/docs/functions/geo.md · All docs for AI tools: https://cdpfleet.com/llms.txt
