The invention discloses an LLM-DoS
attack protection method based on a multi-level defense strategy and a related device, and belongs to the field of
artificial intelligence security. According to the method, denial of service attacks aiming at a large
language model are effectively prevented through a three-layer defense strategy: firstly, dynamic frequency control is carried out on an API request, a three-stage
rate limiting system is established, a load-aware dynamic adjustment
algorithm is introduced, and when the
system load is too high, the quota is automatically adjusted; secondly, constructing an input
perception classifier by adopting a lightweight Transform model, breaking through context limitation in combination with a random fragment compression and length penalty strategy, and realizing hierarchical interception of
attack requests through a harmfulness scoring function; and finally, a request hash mapping and streaming response
multiplexing technology is implemented at a
server side, and real-time detection and response
multiplexing are performed on repeated high-
concurrency attack requests, so that consumption of computing resources is reduced. According to the method, the security and availability of the large
language model service can be effectively improved, and the influence of DoS attacks on the
system is reduced.