{
  "openapi": "3.0.3",
  "info": {
    "title": "IPRout API",
    "description": "Developer-first IP intelligence platform providing geolocation and ASN lookups with low latency and simple integration.",
    "version": "1.0.0",
    "contact": {
      "name": "IPRout",
      "url": "https://iprout.com"
    }
  },
  "servers": [
    {
      "url": "https://api.iprout.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Lookup",
      "description": "GeoIP and ASN lookups"
    }
  ],
  "paths": {
    "/ip/{ip}": {
      "get": {
        "tags": ["Lookup"],
        "operationId": "lookupIp",
        "summary": "Lookup IP address",
        "description": "Return geolocation and ASN information for a supplied IP address.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "ip",
            "in": "path",
            "required": true,
            "description": "The IPv4 or IPv6 address to look up.",
            "schema": {
              "type": "string"
            },
            "example": "8.8.8.8"
          }
        ],
        "responses": {
          "200": {
            "description": "Lookup successful",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IpInfo"
                },
                "example": {
                  "ip": "8.8.8.8",
                  "country_code": "US",
                  "country": "United States",
                  "region": "California",
                  "city": "Mountain View",
                  "timezone": "America/Los_Angeles",
                  "latitude": 37.4056,
                  "longitude": -122.0775,
                  "asn": 15169,
                  "organization": "Google LLC"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/InvalidIp"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          }
        }
      }
    },
    "/ip": {
      "get": {
        "tags": ["Lookup"],
        "operationId": "lookupCallerIp",
        "summary": "Lookup caller IP",
        "description": "Return geolocation and ASN information for the caller IP address.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Lookup successful",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IpInfo"
                },
                "example": {
                  "ip": "203.0.113.10",
                  "country_code": "AU",
                  "country": "Australia",
                  "region": "New South Wales",
                  "city": "Sydney",
                  "timezone": "Australia/Sydney",
                  "latitude": -33.8688,
                  "longitude": 151.2093,
                  "asn": 1221,
                  "organization": "Telstra Corporation Ltd"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Provide your API key as a bearer token: `Authorization: Bearer YOUR_API_KEY`."
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Provide your API key in the `X-API-Key` header."
      }
    },
    "schemas": {
      "IpInfo": {
        "type": "object",
        "required": [
          "ip",
          "country_code",
          "country"
        ],
        "properties": {
          "ip": {
            "type": "string",
            "description": "The IP address that was looked up.",
            "example": "8.8.8.8"
          },
          "country_code": {
            "type": "string",
            "description": "ISO 3166-1 alpha-2 country code.",
            "example": "US"
          },
          "country": {
            "type": "string",
            "description": "Country name.",
            "example": "United States"
          },
          "region": {
            "type": "string",
            "nullable": true,
            "description": "Region or state.",
            "example": "California"
          },
          "city": {
            "type": "string",
            "nullable": true,
            "description": "City name.",
            "example": "Mountain View"
          },
          "timezone": {
            "type": "string",
            "nullable": true,
            "description": "IANA timezone identifier.",
            "example": "America/Los_Angeles"
          },
          "latitude": {
            "type": "number",
            "format": "double",
            "nullable": true,
            "description": "Approximate latitude.",
            "example": 37.4056
          },
          "longitude": {
            "type": "number",
            "format": "double",
            "nullable": true,
            "description": "Approximate longitude.",
            "example": -122.0775
          },
          "asn": {
            "type": "integer",
            "nullable": true,
            "description": "Autonomous System Number.",
            "example": 15169
          },
          "organization": {
            "type": "string",
            "nullable": true,
            "description": "Network ownership / organization name.",
            "example": "Google LLC"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable error message."
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Missing or invalid API key"
            }
          }
        }
      },
      "InvalidIp": {
        "description": "Invalid IP",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Invalid IP"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limited",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Rate Limited"
            }
          }
        }
      },
      "InternalServerError": {
        "description": "Internal server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Internal Server Error"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    },
    {
      "ApiKeyAuth": []
    }
  ]
}
