Cities based on oil and gas energy resources are crucial to energy production and economic development, but they also face various disasters and security risks. To ensure the safety and well-being of urban residents during disaster events, the planning of urban shelters is crucial. In this paper, comprehensively considering multiple factors such as disaster risk, population distribution, and convenient transportation, the artificial bee colony algorithm is used to optimize the site selection and capacity planning of shelters. By comprehensively evaluating the disaster resistance capacity of urban refuges, the response speed of residents and other related indicators, the planning algorithm of refuges is continuously optimized to better meet the needs of oil and gas energy resource-based cities. The results of the study showed that the average overall disaster resilience of AI-based urban shelters reached 0.64. When the distance to the shelter was 4 km, the average response speed of residents reached 10.22 min, and other indicators also improved. The research shows that the oil and gas energy urban refuge planning algorithm based on the artificial intelligence elastic city model provides an innovative approach for urban planners and disaster managers. Further research and practice will help promote the application of this algorithm in real cities, improving the resilience and disaster resistance of cities and the safety and security level of residents.