{
 "openapi": "3.1.0",
 "info": {
  "title": "IPzentra API",
  "version": "1.0.0",
  "description": "IP intelligence: country, region and city, network, and VPN, proxy, Tor and hosting detection with a risk score. Send your API key in the X-Api-Key header.",
  "contact": {
   "name": "IPzentra support",
   "url": "https://ipzentra.com/contact"
  },
  "termsOfService": "https://ipzentra.com/terms"
 },
 "externalDocs": {
  "description": "API documentation",
  "url": "https://ipzentra.com/docs"
 },
 "servers": [
  {
   "url": "https://api.ipzentra.com"
  }
 ],
 "security": [
  {
   "ApiKeyHeader": []
  }
 ],
 "tags": [
  {
   "name": "Lookup"
  },
  {
   "name": "Service"
  }
 ],
 "paths": {
  "/v1/{ip}": {
   "get": {
    "tags": [
     "Lookup"
    ],
    "operationId": "lookupIp",
    "summary": "Look up an IP address",
    "parameters": [
     {
      "name": "ip",
      "in": "path",
      "required": true,
      "description": "IPv4 or IPv6 address.",
      "schema": {
       "type": "string"
      },
      "example": "49.207.48.1"
     }
    ],
    "responses": {
     "200": {
      "description": "Lookup result.",
      "headers": {
       "X-RateLimit-Remaining-Day": {
        "$ref": "#/components/headers/Remaining"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Lookup"
        }
       }
      }
     },
     "400": {
      "description": "Invalid IP address (bad_ip).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "$ref": "#/components/responses/NoPlan"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/ServerError"
     }
    }
   }
  },
  "/v1/": {
   "get": {
    "tags": [
     "Lookup"
    ],
    "operationId": "lookupCaller",
    "summary": "Look up the IP address making the request",
    "responses": {
     "200": {
      "description": "Lookup result.",
      "headers": {
       "X-RateLimit-Remaining-Day": {
        "$ref": "#/components/headers/Remaining"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Lookup"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "$ref": "#/components/responses/NoPlan"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/ServerError"
     }
    }
   }
  },
  "/v1/check": {
   "get": {
    "tags": [
     "Lookup"
    ],
    "operationId": "checkCountry",
    "summary": "Check an IP against the countries you expect",
    "parameters": [
     {
      "name": "ip",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "example": "49.207.48.1"
     },
     {
      "name": "country",
      "in": "query",
      "required": true,
      "description": "One or more ISO alpha-2 codes, comma separated.",
      "schema": {
       "type": "string"
      },
      "example": "IN,SG"
     }
    ],
    "responses": {
     "200": {
      "description": "Lookup result with country_match.",
      "headers": {
       "X-RateLimit-Remaining-Day": {
        "$ref": "#/components/headers/Remaining"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Check"
        }
       }
      }
     },
     "400": {
      "description": "Invalid IP (bad_ip) or country list (bad_country).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "$ref": "#/components/responses/NoPlan"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/ServerError"
     }
    }
   }
  },
  "/v1/batch": {
   "post": {
    "tags": [
     "Lookup"
    ],
    "operationId": "batchLookup",
    "summary": "Look up up to 100 IP addresses in one request",
    "description": "Each valid IP counts as one lookup against your daily quota. Invalid IPs are not charged. If the batch is larger than the lookups left today, the whole request is refused with 429 and nothing is charged.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BatchRequest"
       },
       "example": {
        "ips": [
         "49.207.48.1",
         "8.8.8.8"
        ],
        "country": "IN"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "One result per IP, in the order sent.",
      "headers": {
       "X-RateLimit-Remaining-Day": {
        "$ref": "#/components/headers/Remaining"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BatchResponse"
        }
       }
      }
     },
     "400": {
      "description": "Body is not valid (bad_body, no_ips, bad_country).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "405": {
      "description": "Use POST (method_not_allowed).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "More than 100 IPs (too_many_ips).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "402": {
      "$ref": "#/components/responses/NoPlan"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/ServerError"
     }
    }
   }
  },
  "/health": {
   "get": {
    "tags": [
     "Service"
    ],
    "operationId": "health",
    "summary": "Service status",
    "security": [],
    "responses": {
     "200": {
      "description": "All systems working.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     },
     "503": {
      "description": "Degraded.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "ApiKeyHeader": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key",
    "description": "Your API key from app.ipzentra.com, starting with ipz_."
   }
  },
  "headers": {
   "Remaining": {
    "description": "Lookups left today for your account.",
    "schema": {
     "type": "integer"
    }
   }
  },
  "schemas": {
   "Lookup": {
    "type": "object",
    "required": [
     "ip",
     "version"
    ],
    "properties": {
     "ip": {
      "type": "string",
      "description": "The IP address that was looked up.",
      "example": "49.207.48.1"
     },
     "version": {
      "type": "integer",
      "description": "IP version, 4 or 6.",
      "enum": [
       4,
       6
      ]
     },
     "country_code": {
      "type": [
       "string",
       "null"
      ],
      "description": "ISO 3166-1 alpha-2 country code.",
      "example": "IN"
     },
     "country_name": {
      "type": [
       "string",
       "null"
      ],
      "description": "Country name in English.",
      "example": "India"
     },
     "continent": {
      "type": [
       "string",
       "null"
      ],
      "description": "Continent name.",
      "example": "Asia"
     },
     "is_eu": {
      "type": "boolean",
      "description": "True when the country is in the European Union."
     },
     "time_zone": {
      "type": [
       "string",
       "null"
      ],
      "description": "IANA time zone of the country.",
      "example": "Asia/Kolkata"
     },
     "currency_code": {
      "type": [
       "string",
       "null"
      ],
      "description": "ISO 4217 currency of the country.",
      "example": "INR"
     },
     "region": {
      "type": [
       "string",
       "null"
      ],
      "description": "Region or state.",
      "example": "Karnataka"
     },
     "city": {
      "type": [
       "string",
       "null"
      ],
      "description": "City.",
      "example": "Bengaluru"
     },
     "location_confidence": {
      "type": [
       "string",
       "null"
      ],
      "description": "How confident the region and city are.",
      "enum": [
       "high",
       "medium",
       "low",
       null
      ]
     },
     "asn": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Autonomous system number of the network.",
      "example": 24309
     },
     "org": {
      "type": [
       "string",
       "null"
      ],
      "description": "Network owner.",
      "example": "Atria Convergence Technologies"
     },
     "network": {
      "type": [
       "string",
       "null"
      ],
      "description": "The address range the IP belongs to.",
      "example": "49.207.48.0 - 49.207.63.255"
     },
     "is_bogon": {
      "type": "boolean",
      "description": "True for private, reserved or unroutable addresses."
     },
     "is_vpn": {
      "type": [
       "boolean",
       "null"
      ],
      "description": "True for known VPN servers, and for hosting networks where people only appear through a VPN or proxy. Null on the Free plan."
     },
     "vpn_confidence": {
      "type": [
       "string",
       "null"
      ],
      "description": "confirmed for known VPN servers, likely for hosting networks, null otherwise. Null on the Free plan.",
      "enum": [
       "confirmed",
       "likely",
       null
      ]
     },
     "is_proxy": {
      "type": [
       "boolean",
       "null"
      ],
      "description": "True for open proxies. Null on the Free plan."
     },
     "is_tor": {
      "type": [
       "boolean",
       "null"
      ],
      "description": "True for Tor exit nodes. Null on the Free plan."
     },
     "is_hosting": {
      "type": [
       "boolean",
       "null"
      ],
      "description": "True for hosting and datacenter networks. Null on the Free plan."
     },
     "hosting_provider": {
      "type": [
       "string",
       "null"
      ],
      "description": "Hosting company, when known.",
      "example": "Clouvider"
     },
     "risk": {
      "type": [
       "string",
       "null"
      ],
      "description": "Overall risk level. Null on the Free plan.",
      "enum": [
       "low",
       "medium",
       "high",
       null
      ]
     },
     "risk_score": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Risk score from 0 upwards; higher is riskier. Null on the Free plan.",
      "example": 0
     },
     "reason_codes": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "type": "string"
      },
      "description": "Why the risk score is what it is, for example hosting or vpn_known_provider. Null on the Free plan.",
      "example": []
     },
     "upgrade": {
      "type": "string",
      "description": "Present only on the Free plan: how to get the Pro-only fields."
     }
    }
   },
   "Check": {
    "allOf": [
     {
      "$ref": "#/components/schemas/Lookup"
     },
     {
      "type": "object",
      "properties": {
       "expected": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "The countries you sent.",
        "example": [
         "IN",
         "SG"
        ]
       },
       "country_match": {
        "type": "boolean",
        "description": "True when the IP country is one of the expected countries."
       }
      }
     }
    ]
   },
   "BatchRequest": {
    "type": "object",
    "required": [
     "ips"
    ],
    "properties": {
     "ips": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "minItems": 1,
      "maxItems": 100
     },
     "country": {
      "type": "string",
      "description": "Optional: expected countries, comma separated. Adds country_match to each result.",
      "example": "IN"
     }
    }
   },
   "BatchItemError": {
    "type": "object",
    "properties": {
     "ip": {
      "type": "string"
     },
     "error": {
      "type": "string",
      "example": "bad_ip"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "BatchResponse": {
    "type": "object",
    "properties": {
     "count": {
      "type": "integer",
      "description": "IPs sent."
     },
     "ok": {
      "type": "integer",
      "description": "Valid IPs looked up."
     },
     "results": {
      "type": "array",
      "items": {
       "oneOf": [
        {
         "$ref": "#/components/schemas/Check"
        },
        {
         "$ref": "#/components/schemas/BatchItemError"
        }
       ]
      }
     },
     "upgrade": {
      "type": "string",
      "description": "Present only on the Free plan."
     }
    }
   },
   "Health": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "ok",
       "degraded"
      ]
     },
     "db": {
      "type": "boolean"
     },
     "redis": {
      "type": "boolean"
     },
     "data": {
      "type": "boolean"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "string",
      "description": "Machine-readable code.",
      "example": "rate_limited"
     },
     "message": {
      "type": "string"
     },
     "subscribe": {
      "type": "string"
     }
    }
   }
  },
  "responses": {
   "Unauthorized": {
    "description": "Missing, invalid or expired API key (invalid_key, key_expired).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "NoPlan": {
    "description": "The account has no plan with API access (subscription_required).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Forbidden": {
    "description": "The key does not allow this caller (origin_not_allowed, ip_not_allowed, browser_only_key).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "RateLimited": {
    "description": "Per-second limit or daily quota reached (rate_limited).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "ServerError": {
    "description": "Unexpected error (server_error).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  }
 }
}