---
title: "fields and excludes: Get Only the IP Data You Need"
slug: "/tutorials/ip-geolocation-api-fields-and-excludes"
description: "Use fields and excludes to trim IPGeolocation.io responses to the location, security, or ASN data your code reads, with curl, Python, and Node.js examples."
---

# Get Only the IP Data You Need With fields and excludes

By [Daud Ahmad](https://www.linkedin.com/in/daudahmad0303) Software Engineer

Posted on November 25, 2026 | 11 min read

![Get Only the IP Data You Need With fields and excludes](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1600/format/webp/2026/10/ip-geolocation-api-fields-and-excludes.png)

`fields` and `excludes` are two query parameters that trim an IPGeolocation.io response to what your code reads: `fields` keeps only the dot paths you list, and `excludes` removes the paths you name. Both work on every plan, including the free Developer plan, and the `ip` field always comes back.

Picture a storefront that reads four values from each lookup: the visitor's country code, city, currency, and time zone. A default lookup for 8.8.8.8 on a Developer-plan key returned 1,577 bytes in our run on October 29, 2026. Asking for those four paths returned 142 bytes, for the same 1 credit.

* * *

## TL;DR

`fields` and `excludes` filter an IPGeolocation.io API response without changing what your plan can return. List dot paths such as `location.city`, separated by commas; `ip` is always included, and the same parameters work in the official SDKs and on bulk lookups.

*   Optional modules (security, abuse contact, user agent, and others) need `include` first, and `include` is paid. On a Developer-plan key, `include=*` is ignored, and naming a paid module returns a 401.
*   A path the API doesn't recognize is ignored without an error, and if no path in `fields` is valid, the full default response comes back.
*   A smaller response costs the same credits. The price drops only when `fields` leaves out all base data from a security or abuse contact request.

* * *

## Before you start

*   You have an IPGeolocation.io API key in an environment variable, not in your code (see [keeping the API key out of your code](https://ipgeolocation.io/tutorials/secure-api-key-before-production)).
*   You have curl, plus Python 3.10 or later or Node.js 18 or later for the SDK section.
*   For the `include`, company, and bulk examples, your key is on a paid plan. Code comments mark those requests.

```bash
export IPGEO_API_KEY="your_api_key"
```

If you haven't made a first request yet, [getting started with the IP Geolocation API](https://ipgeolocation.io/tutorials/getting-started-with-ip-geolocation-api) covers it.

* * *

## Ask for one field with fields

The `fields` parameter takes a comma-separated list of paths and returns only those specific fields, plus `ip`. A path names the object and then the field, joined by dots, such as `location.city` or, one level deeper, `user_agent.device.type`. Here is a country-only lookup:

```bash
curl -s "https://api.ipgeolocation.io/v3/ipgeo?apiKey=${IPGEO_API_KEY}&ip=8.8.8.8&fields=location.country_code2"
```

```json
{"ip":"8.8.8.8","location":{"country_code2":"US"}}
```

That's 50 bytes, against 1,577 for the default response on a Developer-plan key and 1,840 on a paid key (which adds the network and company objects).

![Default 1,577-byte IP lookup response beside a 50-byte response trimmed to location.country_code2](https://blogs.ipgeolocation.io/blogs-site/content/images/2026/10/ip-lookup-default-vs-fields-response-size.webp)

Most requests need more than one value. Country code and city are the combination our team sees most, and online stores usually add currency, sometimes time zone too:

```bash
curl -s "https://api.ipgeolocation.io/v3/ipgeo?apiKey=${IPGEO_API_KEY}&ip=8.8.8.8&fields=location.country_code2,location.city,currency.code,time_zone.name"
```

```json
{"ip":"8.8.8.8","location":{"country_code2":"US","city":"Mountain View"},"currency":{"code":"USD"},"time_zone":{"name":"America/Los_Angeles"}}
```

Name an object without a field (`fields=location`) to get all of it. If you list an object and one of its own fields, the whole object comes back.

Watch the spelling. A mistyped path is ignored without an error, so `fields=location.city,location.cuntry_code2` returns only the city. Paths are case-sensitive. When none of them is valid, because of a typo or the wrong case (`Location.Country_Code2`), the API ignores `fields` and returns the full default response. A valid path to data the response doesn't carry is different: `fields=company.name` on a Developer-plan key returns only `ip`. Every path, with the plan it needs, is listed in the [IP Geolocation API documentation](https://ipgeolocation.io/documentation/ip-location-api.html).

* * *

## Remove whole objects with excludes

`excludes` works the other way round: you get the complete response minus the objects or fields you name. Our team suggests it when you want almost everything and need to drop a whole object or two. The time zone object is the largest in the default response, so this request drops it along with the country metadata:

```bash
curl -s "https://api.ipgeolocation.io/v3/ipgeo?apiKey=${IPGEO_API_KEY}&ip=8.8.8.8&excludes=time_zone,country_metadata"
```

The response, formatted for reading:

```json
{
  "ip": "8.8.8.8",
  "location": {
    "continent_code": "NA",
    "continent_name": "North America",
    "country_code2": "US",
    "country_code3": "USA",
    "country_name": "United States",
    "country_name_official": "United States of America",
    "country_capital": "Washington, D.C.",
    "state_prov": "California",
    "state_code": "US-CA",
    "district": "Santa Clara",
    "city": "Mountain View",
    "zipcode": "94043-1351",
    "latitude": "37.42240",
    "longitude": "-122.08421",
    "is_eu": false,
    "country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
    "geoname_id": "6301403",
    "country_emoji": "🇺🇸"
  },
  "currency": {
    "code": "USD",
    "name": "US Dollar",
    "symbol": "$"
  },
  "asn": {
    "as_number": "AS15169",
    "organization": "Google LLC",
    "country": "US"
  }
}
```

The compact response was 687 bytes on a Developer-plan key. An `excludes` path that doesn't exist raises no error, and `ip` stays even if you exclude it.

Which one to reach for depends on the job. `fields` suits production code that reads a known set of values: the request records exactly what the code uses, and fields the API adds later won’t grow your payload. `excludes` suits dashboards and logs that show most of the response.

* * *

## How fields, excludes, and include work together

`include` adds optional modules, `fields` narrows the response to the paths you list, and `excludes` removes paths from what's left. When they conflict, `excludes` wins. A module you include stays in the response when `fields` doesn't mention it, and if `fields` names paths inside it, only those paths stay. Exclude the module itself and the API doesn't look it up at all, so it isn't charged either. An object that `excludes` leaves empty is removed.

![Flow of include adding modules, fields keeping paths, and excludes removing paths, with ip always returned](https://blogs.ipgeolocation.io/blogs-site/content/images/2026/11/include-fields-excludes-order-and-rules.webp)

These results are from our live run on November 25, 2026:

| Request Parameters | What Came Back |
| --- | --- |
| `fields=location&excludes=location.continent_code,location.continent_name` | The location object without the two continent fields |
| `fields=location.city,location.country_code2&excludes=location.country_code2` | The city only |
| `fields=location.country_code2&excludes=location.country_code2` | `{"ip":"8.8.8.8"}`, because the emptied location object is removed |
| `fields=security.threat_score` (no include) | Only `ip`, because security wasn't added |
| `include=security&fields=location.city` (paid key) | The city plus the full security object |
| `include=security&excludes=security` (paid key) | The default response without security, for 1 credit |
| `include=security&excludes=security.threat_score` (paid key) | The full response, with security minus its threat score |
| `include=security` on a Developer-plan key | HTTP 401: "IP-security lookup is not supported on your subscription." |

To read part of an optional module, include it and name the paths you want inside it:

```bash
# Paid plan: include=security needs a paid key.
curl -s "https://api.ipgeolocation.io/v3/ipgeo?apiKey=${IPGEO_API_KEY}&ip=2.56.188.34&include=security&fields=location.city,security.threat_score,security.is_vpn"
```

```json
{"ip":"2.56.188.34","location":{"city":"Dallas"},"security":{"threat_score":80,"is_vpn":true}}
```

* * *

## Recipes for each kind of IP data

Each row in this table was run on October 29, 2026, against 8.8.8.8 (Google's public DNS) or 2.56.188.34 (a hosting address from our documentation). Rows marked paid need a paid-plan key.

| Data | Parameters | Returned | Credits |
| --- | --- | --- | --- |
| Location: country only | `fields=location.country_code2` | `"country_code2":"US"` | 1   |
| Location: city and coordinates | `fields=location.city,location.latitude,location.longitude` | Mountain View, 37.42240, -122.08421 | 1   |
| Security risk signals (paid) | `include=security&fields=security.threat_score,security.is_vpn,security.is_proxy` | 80, true, false | 2   |
| ASN | `fields=asn.as_number,asn.organization` | AS15169, Google LLC | 1   |
| Company (paid) | `fields=company.name,company.type` | Google LLC, HOSTING | 1   |
| Abuse contact (paid) | `include=abuse&fields=abuse.emails` | network-abuse@google.com | 1   |
| Time zone | `fields=time_zone.name,time_zone.current_time` | America/Los_Angeles and the local time | 1   |
| User agent (paid) | `include=user_agent&fields=user_agent.name,user_agent.device.type`, with the visitor's `User-Agent` header | Chrome, Desktop | 1   |

For the location rows, [look up the visitor's real IP](https://ipgeolocation.io/guides/get-real-client-ip-address), not your server's. The security fields are explained in [check an IP for VPN, proxy, and Tor](https://ipgeolocation.io/tutorials/check-ip-for-vpn-proxy-tor), and the [IP Abuse Contact API](https://ipgeolocation.io/ip-abuse-contact-api.html) page covers the abuse contact object.

* * *

## When a trimmed request costs fewer credits

Credits follow the modules a request touches, not the number of fields it returns. A default lookup costs 1 credit whether it returns every field or one. The most common mix-up our team sees is expecting a smaller response to cost less.

The exception involves the two modules that add credits. Security adds 2, and abuse contact adds 1 to the base lookup's 1. When `fields` leaves out every base path, the base credit goes too: `include=security&fields=security` costs 2 credits instead of 3, and `include=abuse&fields=abuse` costs 1 instead of 2. Check the charge on any request with the `X-Credits-Charged` header:

```bash
# Paid plan: security-only request.
curl -s -o /dev/null -D - "https://api.ipgeolocation.io/v3/ipgeo?apiKey=${IPGEO_API_KEY}&ip=2.56.188.34&include=security&fields=security.threat_score,security.is_vpn,security.is_proxy" | grep -i x-credits-charged
```

```text
x-credits-charged: 2
```

![Credits per request: default 1, one field 1, include=security 3, security only 2, abuse contact only 1](https://blogs.ipgeolocation.io/blogs-site/content/images/2026/10/ip-lookup-credits-per-request-fields-bricks.webp)

For every combination, see [how IPGeolocation.io charges credits](https://ipgeolocation.io/help/how-ipgeolocation-io-credits-work) and the [credits usage table](https://ipgeolocation.io/documentation/credits-usage.html).

* * *

## Use fields and excludes in Python and Node.js

The official SDKs take `fields` and `excludes` as lists of the same paths. This Python script uses the [official IPGeolocation.io Python library](https://ipgeolocation.io/documentation/ip-geolocation-api-python-sdk.html) (`pip install ipgeolocationio`) to request the storefront set:

```python
import os
import sys

from ipgeolocation import (
    IpGeolocationClient,
    IpGeolocationClientConfig,
    IpGeolocationException,
    LookupIpGeolocationRequest,
)

# The four values a storefront reads: country, city, currency, and time zone.
FIELDS = ["location.country_code2", "location.city", "currency.code", "time_zone.name"]

api_key = os.environ.get("IPGEO_API_KEY")
if not api_key:
    sys.exit("Set IPGEO_API_KEY first.")

with IpGeolocationClient(IpGeolocationClientConfig(api_key=api_key)) as client:
    try:
        response = client.lookup_ip_geolocation(
            LookupIpGeolocationRequest(ip="8.8.8.8", fields=FIELDS)
        )
    except IpGeolocationException as exc:
        # Covers a bad key (401), used-up credits (429), and network failures.
        sys.exit(f"Lookup failed: {exc}")

    data = response.data
    # Objects you didn't ask for come back as None, so check before reading.
    country = data.location.country_code2 if data.location else None
    city = data.location.city if data.location else None
    currency = data.currency.code if data.currency else None
    time_zone = data.time_zone.name if data.time_zone else None
    print(country, city, currency, time_zone)
    print("Credits charged:", response.metadata.credits_charged)
```

```text
US Mountain View USD America/Los_Angeles
Credits charged: 1
```

The package installs as `ipgeolocationio` but imports as `ipgeolocation`; a `ModuleNotFoundError` usually means the import used the package name. With a wrong key, the script stops with `Lookup failed: API request failed with HTTP status 401: Provided API key is not valid.` followed by the API's support note.

The [official IPGeolocation.io JavaScript library](https://ipgeolocation.io/documentation/ip-geolocation-api-javascript-sdk.html) (`npm install ip-geolocation-api-javascript-sdk`) works the same way. Save this as `filtered-lookup.mjs`:

```javascript
import { IpGeolocationClient, IpGeolocationError } from "ip-geolocation-api-javascript-sdk";

const apiKey = process.env.IPGEO_API_KEY;
if (!apiKey) {
  console.error("Set IPGEO_API_KEY first.");
  process.exit(1);
}

const client = new IpGeolocationClient({ apiKey });

try {
  const { data, metadata } = await client.lookupIpGeolocation({
    ip: "8.8.8.8",
    // Paths stay snake_case here, even though the response properties are camelCase.
    fields: ["location.country_code2", "location.city", "currency.code", "time_zone.name"],
  });
  console.log(
    data.location?.countryCode2 ?? null,
    data.location?.city ?? null,
    data.currency?.code ?? null,
    data.timeZone?.name ?? null,
  );
  console.log("Credits charged:", metadata.creditsCharged);
} catch (error) {
  // Covers a bad key (401), used-up credits (429), and network failures.
  if (error instanceof IpGeolocationError) {
    console.error("Lookup failed:", error.message);
    process.exitCode = 1;
  } else {
    throw error;
  }
} finally {
  await client.close();
}
```

```text
US Mountain View USD America/Los_Angeles
Credits charged: 1
```

Run it with `node filtered-lookup.mjs`; the `.mjs` extension lets the script use `await` at the top level. For full walk-throughs, see IP geolocation in [Python](https://ipgeolocation.io/tutorials/ip-geolocation-in-python), [JavaScript](https://ipgeolocation.io/tutorials/ip-geolocation-in-javascript), and [PHP](https://ipgeolocation.io/tutorials/ip-geolocation-in-php).

* * *

## Filter bulk lookups the same way

The bulk endpoint applies the same `fields` and `excludes` to every address in the request:

```bash
# Paid plan: bulk lookup needs a paid key.
curl -s -X POST "https://api.ipgeolocation.io/v3/ipgeo-bulk?apiKey=${IPGEO_API_KEY}&fields=location.country_code2" \
  -H "Content-Type: application/json" \
  -d '{"ips":["8.8.8.8","2.56.188.34","10.0.0.1"]}'
```

```json
[{"ip":"8.8.8.8","location":{"country_code2":"US"}},{"ip":"2.56.188.34","location":{"country_code2":"US"}},{"message":"'10.0.0.1' is a bogon IP address."}]
```

The request was charged 2 credits, one per valid address; the bogon address returned a message and wasn't charged. Bulk accepts up to 50,000 addresses or domains per request.

* * *

## Mistakes to avoid

*   **Treating fields like include.** Our team sees this mix-up often. `fields` can't turn on a module: `fields=security.threat_score` without `include=security` returns only the `ip` field.
*   **Trusting a filter you haven't tested.** Typos and wrong case fail silently, and a list with no valid path brings back the full response, which still contains your keys. In a test, check that the keys you read are present and that a key you didn't ask for, such as `asn`, is absent.
*   **Trimming too tightly.** If your code later needs a field you left out, a second lookup costs another credit. Build the list from every decision the request serves.
*   **Caching without the field list.** When you cache per IP, put the field list in the cache key, or a trimmed response will answer a request that expected more.

* * *

## Smaller responses for AI agents

Agents that call the API through the [IPGeolocation.io MCP server](https://ipgeolocation.io/integrations/ipgeolocation-io-mcp) can pass `fields` and `excludes` on its lookup tools too. Every byte of tool output lands in the model's context, so a 50-byte country lookup instead of a 1,577-byte default leaves the agent more room for the rest of the task.

* * *

## Get the IP data your code needs from IPGeolocation.io

IPGeolocation.io returns the most complete IP data in a single call. One request can carry geolocation, security risk signals (VPN, proxy, and Tor detection with a threat score), ASN, company, abuse contact data, time zone, and parsed user agent details. `fields` and `excludes` then cut that down to what your code reads, on single and bulk lookups, in the official SDKs, and through the MCP server. Start with the [IP Geolocation API](https://ipgeolocation.io/ip-location-api.html), or compare what each plan includes on [IPGeolocation.io pricing](https://ipgeolocation.io/pricing.html).

## Frequently asked questions

### Are fields and excludes available on the free plan?

**Answer:** Yes. `fields` and `excludes` work on every IPGeolocation.io plan. The free Developer plan gives you 1,000 credits a day for life, with no credit card. Both parameters trim what your plan returns but don't add data. Paid plans add more data, such as accuracy radius, company, network, and security data.

### Does using fields reduce API credits?

**Answer:** Not on its own. An IPGeolocation.io lookup costs 1 credit whether it returns every field or one. Credits drop only when `fields` removes all base data from a security or abuse contact request: security alone costs 2 credits instead of 3.

### How do I get only the country from an IP address?

**Answer:** Add `fields=location.country_code2` to an IPGeolocation.io lookup, or `location.country_name` for the full name. For 8.8.8.8 the response is `{"ip":"8.8.8.8","location":{"country_code2":"US"}}`, 50 bytes, for 1 credit.

### Can I use fields and excludes in the same request?

**Answer:** Yes. `fields` narrows the IPGeolocation.io response first, then `excludes` removes paths from what's left, so `fields=location&excludes=location.continent_code,location.continent_name` returns the location object without its two continent fields. When the two conflict, `excludes` wins: a field listed in both is dropped, an object left empty is removed, and a module added with `include` and then excluded isn't returned or charged.

### Why does my response still contain every field?

**Answer:** When none of the paths in `fields` is valid, the IPGeolocation.io API ignores the parameter and returns the full default response instead of an error. Check for typos and letter case: paths are case-sensitive, so `Location.Country_Code2` doesn't match `location.country_code2`.

### Do fields and excludes work with bulk lookups?

**Answer:** Yes. The IPGeolocation.io bulk endpoint applies the same `fields` and `excludes` to each address, up to 50,000 per request, on paid plans. Credits are charged per valid address; private, bogon, and malformed addresses aren't charged.

### Related Tutorials

[![How to Run a Bulk IP Lookup on a CSV Without Losing Rows](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1000/format/webp/2026/11/visual-0-feature-option-g-before-and-after.webp)](https://ipgeolocation.io/tutorials/bulk-ip-lookup-csv)

[How to Run a Bulk IP Lookup on a CSV Without Losing Rows](https://ipgeolocation.io/tutorials/bulk-ip-lookup-csv)

A Python script that sends the IP addresses from a 10,000-row CSV to the IPGeolocation.io bulk API in one request, gives every row a status, writes the rows to retry to their own file, and resumes where it stopped.

Posted on December 1, 2026

By [Abdullah Afzal](https://www.linkedin.com/in/abdullah-a-08ba162b7?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)

[Read More: How to Run a Bulk IP Lookup on a CSV Without Losing Rows](https://ipgeolocation.io/tutorials/bulk-ip-lookup-csv)

[![How to Read an MMDB File in Python, Go, Node.js, and Java](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1000/format/webp/2026/10/visual-0-feature-option-f-search-tree.webp)](https://ipgeolocation.io/tutorials/how-to-read-mmdb-file)

[How to Read an MMDB File in Python, Go, Node.js, and Java](https://ipgeolocation.io/tutorials/how-to-read-mmdb-file)

Open an MMDB file once, look up IPv4 and IPv6 addresses, and handle missing and malformed input in Python, Go, Node.js, and Java. Every program is tested against IPGeolocation.io's free sample files, with the output it prints.

Posted on November 30, 2026

By [Abdullah Afzal](https://www.linkedin.com/in/abdullah-a-08ba162b7?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)

[Read More: How to Read an MMDB File in Python, Go, Node.js, and Java](https://ipgeolocation.io/tutorials/how-to-read-mmdb-file)

[![How to Automate IPGeolocation.io Database Updates](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1000/format/webp/2026/10/visual-0-feature-option-a-daily-cycle.webp)](https://ipgeolocation.io/tutorials/automate-ipgeolocation-database-updates)

[How to Automate IPGeolocation.io Database Updates](https://ipgeolocation.io/tutorials/automate-ipgeolocation-database-updates)

One Bash script that checks IPGeolocation.io's status endpoint once a day, installs a new database release only after its signature and checksums pass, and makes your application load it.

Posted on November 29, 2026

By [Abdullah Afzal](https://www.linkedin.com/in/abdullah-a-08ba162b7?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)

[Read More: How to Automate IPGeolocation.io Database Updates](https://ipgeolocation.io/tutorials/automate-ipgeolocation-database-updates)

[![Log the Credits Each Request Uses with X-Credits-Charged](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1000/format/webp/2026/11/0-log-credits-x-credits-charged.png)](https://ipgeolocation.io/tutorials/log-x-credits-charged)

[Log the Credits Each Request Uses with X-Credits-Charged](https://ipgeolocation.io/tutorials/log-x-credits-charged)

Every successful IPGeolocation.io response tells you what it cost in the X-Credits-Charged header. Log it with the feature that made the call, total it by day, and get an alert when a call's cost changes or a feature passes its budget, in Python or Node.js.

Posted on November 24, 2026

By Abdul Mateen

[Read More: Log the Credits Each Request Uses with X-Credits-Charged](https://ipgeolocation.io/tutorials/log-x-credits-charged)

[![How to Get a DMA Code from an IP Address](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1000/format/webp/2026/11/dma-code-from-ip-address.png)](https://ipgeolocation.io/tutorials/dma-code-from-ip-address)

[How to Get a DMA Code from an IP Address](https://ipgeolocation.io/tutorials/dma-code-from-ip-address)

A DMA code is the three-digit code for a US TV market. Get it from an IP address with one IPGeolocation.io lookup, read it next to the ZIP code, and count visits by market.

Posted on November 23, 2026

By [Daud Ahmad](https://www.linkedin.com/in/daudahmad0303)

[Read More: How to Get a DMA Code from an IP Address](https://ipgeolocation.io/tutorials/dma-code-from-ip-address)

[![Auto-Detect Country Code and Time Zone on Signup Forms](https://blogs.ipgeolocation.io/blogs-site/content/images/size/w1000/format/webp/2026/11/auto-detect-country-code-signup-form-1.png)](https://ipgeolocation.io/tutorials/auto-detect-country-code-signup-form)

[Auto-Detect Country Code and Time Zone on Signup Forms](https://ipgeolocation.io/tutorials/auto-detect-country-code-signup-form)

Pre-fill a signup form's country, phone dial code, and time zone from one IP lookup on your server, then let the browser and the visitor correct them. Tested Node.js and intl-tel-input code.

Posted on November 3, 2026

By [Daud Ahmad](https://www.linkedin.com/in/daudahmad0303)

[Read More: Auto-Detect Country Code and Time Zone on Signup Forms](https://ipgeolocation.io/tutorials/auto-detect-country-code-signup-form)
