Smart cities increasingly rely on intelligent technologies to improve urban infrastructure, sustainability, and quality of life. Traffic flow prediction is essential for the optimization of the transportation system, reducing congestion and improving mobility. However, real-world traffic data are often noisy, limited in size, and lack sufficient features to capture the flow dynamics and temporal dependencies, making accurate prediction a significant challenge. Previous studies have shown that recurrent neural network (RNN) variants, such as LSTM and GRU, are well-suited for time series forecasting tasks, but their performance is highly sensitive to hyperparameter settings. This study proposes a hybrid approach that integrates GRU with a metaheuristic optimization algorithm to address this challenge. After effective preprocessing steps and a sliding time window are applied to structure the data, particle swarm optimization (PSO) is utilized to optimize the hyperparameters of the GRU. The model’s performance is evaluated using RMSE, MAE, and R2, and compared against several baseline approaches, including LSTM, CNN-LSTM, and a manually configured GRU. According to the experimental findings, the GRU model that was manually adjusted performed the best overall. However, the PSO-GRU model demonstrated competitive results, confirming that metaheuristics offer a promising alternative when manual tuning is not feasible despite the higher computational costs.