Rate Limiting and Long-Session Management for LLM Services Under Compute Constraints

    Compute constraints in LLM inference surface at the application layer as session expiry, input-length caps, daily quotas, and 429/503 responses. This article explains the technical meaning of these limits and presents application-side engineering practices: preflight token checks and chunking, long-session summarization with externalized state, quota-aware retry and backoff, and graceful degradation with clear user messaging.

    1. Background: How Compute Constraints Reach the Application Layer

    Large-model inference consumes substantial accelerator compute and memory. When generating each new token, the model must access the key-value cache (KV Cache) corresponding to all prior context. The longer the context, the higher the memory footprint and compute cost of a single request. When online users grow faster than compute supply, service providers must make trade-offs in resource allocation.

    Public reports indicate that a large-model service recently made similar adjustments: long conversations inactive for more than seven days can no longer be continued, the single-input text limit was shortened to around 40,000 characters, and a daily usage quota was introduced, with a “server busy”-type message returned after the quota is exhausted. These rules appear to be product-level restrictions, but in essence they map underlying resource constraints directly to user-perceivable interaction boundaries.

    For developers, such incidents are a reminder that applications relying on third-party inference services must design with “resource availability may change at any time” as a normal condition. The following sections discuss three categories of strategies—session freshness, input length, and call quota—and explain their technical meaning and application-side responses.

    2. Technical Meaning of Three Rate-Limiting Strategies

    2.1 Session Freshness Management

    The core of session freshness management is reclaiming long-inactive context. If the server retains the full history and cache state for every session over a long period, it will continuously consume resources. With a freshness threshold, sessions beyond the threshold are archived or cleaned up, and context must be rebuilt when the session is accessed again.

    The cost of this strategy is that users need to provide background information again. Applications should store session history in storage they control rather than relying only on server-side state. The following pseudocode checks whether a session is still within the server-side active window before requesting a continuation. The seven-day value is an example threshold; actual values should follow the service provider’s documentation.

    1. SESSION_IDLE_LIMIT = 7 days
    2. function can_resume_remote_session(last_active_at, now):
    3. return now - last_active_at <= SESSION_IDLE_LIMIT
    4. function handle_session(session, now):
    5. if can_resume_remote_session(session.last_active_at, now):
    6. return "resume" # continue conversation with session identifier
    7. return "rebuild_from_local" # rebuild context from locally saved summary

    2.2 Single-Input Length Limit

    Input limits are usually measured in tokens, not in Chinese characters. Different tokenizers segment Chinese text differently, so the same 40,000-character text may convert to noticeably different token counts. Therefore, the application layer should not judge whether a limit is exceeded directly by character count. It should use the counting method provided by the service provider, or conservatively reserve headroom.

    The following example function estimates tokens at about 1.5 tokens per Chinese character and one token per four other characters. This is only a conservative rough estimate; formal counting should use the tokenizer that matches the target model.

    1. function estimate_tokens(text):
    2. cjk = count of characters in range U+4E00 to U+9FFF
    3. other = length(text) - cjk
    4. return floor(cjk * 1.5) + ceil(other / 4)

    2.3 Daily Quota and Rate-Limit Responses

    A daily quota sets an upper bound on request volume or compute volume within a calendar day. It differs from common rate limiting. Rate limiting focuses on requests per second or per minute, while quota focuses on the total amount per day. Their recovery times differ greatly, and applications must distinguish between them.

    The HTTP protocol already has general semantics for such cases. 429 Too Many Requests (defined in RFC 6585) indicates that the client has exceeded a rate or quota limit. 503 Service Unavailable indicates that the service is temporarily unavailable. The handling differs: 429 usually requires waiting or reducing request frequency, while 503 is more suitable for retrying after backoff. Specific response codes and messages should follow the service provider’s documentation.

    3. Application-Side Engineering Responses

    3.1 Preflight Checks and Chunking Before Input

    Completing preflight checks before sending a request avoids invalid calls that consume quota. For overlong text, split by token budget and preserve paragraph boundaries where possible to reduce semantic breaks. If a single segment itself exceeds the budget, split it further by sentence.

    1. function split_by_budget(paragraphs, budget):
    2. chunks = []
    3. current = []
    4. current_cost = 0
    5. for p in paragraphs:
    6. cost = estimate_tokens(p)
    7. if current is not empty and current_cost + cost > budget:
    8. chunks.append(join(current, "\n"))
    9. current = []
    10. current_cost = 0
    11. current.append(p)
    12. current_cost = current_cost + cost
    13. if current is not empty:
    14. chunks.append(join(current, "\n"))
    15. return chunks

    3.2 Summary Compression and Externalized State for Long Sessions

    The cost of long sessions mainly comes from historical messages. A common approach has three steps:

    • Keep the original text of the most recent turns to preserve conversational coherence.
    • Compress earlier content into a summary that records user goals, confirmed constraints, pending items, and key numbers.
    • Persist the full history in the application’s own database or object storage for auditing and session reconstruction.

    Summaries inevitably lose detail, so the types of information that must be retained should be agreed in advance. The summary itself should also carry a version number to make it easier to investigate issues such as “why did the model forget a certain condition?” After the server reclaims a session, the application can reconstruct context using the summary plus the most recent original text, greatly reducing the loss in user experience.

    3.3 Quota-Aware Retry and Backoff

    When encountering 429 or 503, immediate retries worsen congestion. The recommended approach is exponential backoff with random jitter, while respecting the wait time in response headers first. Retry-After may be a number of seconds or an HTTP date format, and implementations need to parse both.

    Daily quota exhaustion requires special handling. Before the quota resets the next day, retrying is meaningless, and continued retries only waste connection resources. At this point, place tasks in a queue and wait for quota recovery, or switch to a degraded mode.

    1. function call_with_backoff(send, max_retries):
    2. for attempt in 0 to max_retries - 1:
    3. resp = send()
    4. if resp.status not in (429, 503):
    5. return resp
    6. if resp.headers has "Retry-After":
    7. delay = parse_seconds(resp.headers["Retry-After"])
    8. else:
    9. delay = min(60, 2 ^ attempt) + random_uniform(0, 1)
    10. sleep(delay)
    11. raise error("retry limit exceeded")

    3.4 Degradation and User Messaging

    When a limit is triggered, the interface should show a clear status and avoid silent failure. Common handling includes:

    • Automatically save unsent user input to prevent content loss.
    • Prompt the user to create a new session and automatically attach relevant history.