Cloudflare Trace API

⭐ Beginner's Pick Development / No Auth Required Beginner HTTPS CORS
Free to Use Varies (check documentation)

Overview

The Cloudflare Trace API exposes request metadata collected by Cloudflare's edge network, including your public IP address, country code, datacenter IATA code, HTTP version, TLS version, and user agent—all in a single request. No authentication or API key is required. It is particularly useful for quickly detecting a client's real IP, geographic location, and connection properties in server-side or testing contexts.

💡

Beginner Tip

No sign-up or API key needed. Call https://cloudflare.com/cdn-cgi/trace and you get plain-text key=value output; the JSON version at /json returns structured data. This is one of the simplest and most reliable public APIs available.

Available Data

country name and code
population
capital city
region and subregion
flag image URL
IP address information

Example Response

JSON Response
{
  "name": "Japan",
  "capital": "Tokyo",
  "population": 125800000,
  "region": "Asia",
  "languages": [
    "Japanese"
  ],
  "flag": "https://flagcdn.com/jp.svg",
  "currencies": [
    {
      "code": "JPY",
      "name": "Japanese yen"
    }
  ]
}

Field Reference

ip Your public IP address as seen by Cloudflare's edge.
ts Unix timestamp (with fractional seconds) of the request.
uag User-Agent string of the requesting client.
loc Two-letter ISO 3166-1 country code of the request origin.
tls TLS version used for the connection, e.g., TLSv1.3.
http HTTP protocol version used, e.g., http/2.

Implementation Example

const url = "https://github.com/fawazahmed0/cloudflare-trace-api";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

Response is plain text, not JSON The default /cdn-cgi/trace endpoint returns key=value text format, not JSON.
Use the JSON-formatted endpoint https://speed.cloudflare.com/meta or parse the plain-text response by splitting on newlines and =.
IP shows Cloudflare's IP, not client's You are making the request through a proxy or VPN that exits via a Cloudflare-fronted service.
Make the request directly from the client machine rather than proxying it through another server.
Request blocked by firewall Your server or network blocks outbound HTTPS requests to cloudflare.com.
Verify your server can reach external HTTPS endpoints; add cloudflare.com to any firewall allowlists.

Matrix Score Breakdown

🌐 Reachability 30/30
⚡ Speed 20/20
🔒 Security 15/15
🛠 Developer XP 20/20
✓ Reliability 7/15
Response Time 36ms

Fully tested on Apr 5, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS YES
Category Development
Difficulty Beginner
Verified: 2026-04-04

Similar APIs

View All →