This prompt is designed for reliability engineers and platform operators who need to ensure that AI agents strictly obey server-specified retry windows defined by HTTP Retry-After headers. The core job-to-be-done is converting a raw 429 (Too Many Requests) response into a compliant, delayed retry schedule that respects the server's instructions, communicates the delay to end users, and fails safely if the wait exceeds a maximum acceptable threshold. Use this when your agent's tool-calling layer must be provably compliant with external API rate limits to avoid being throttled or banned.
Prompt
Rate Limit Retry-After Compliance Prompt

When to Use This Prompt
Define when the Rate Limit Retry-After Compliance Prompt is the right tool, who should use it, and when to choose a different approach.
The ideal user is an engineer integrating an AI agent into a production system where upstream APIs enforce rate limits with specific Retry-After values (in seconds or as an HTTP-date). Required context includes the raw rate limit response headers, the current system time, and a pre-defined [MAX_WAIT_SECONDS] policy. Do not use this prompt for generic backoff strategies where the server does not provide a Retry-After header; for those cases, use the Rate Limit Header Parsing and Backoff Prompt Template instead. This prompt is also inappropriate for enforcing client-side, self-imposed rate limits where no server instruction exists.
Before implementing, confirm that your agent harness can parse HTTP response headers and inject them into the prompt's [RATE_LIMIT_RESPONSE_CONTEXT] placeholder. The output is a structured decision, not just a delay timer, so you must wire the resulting retry_at_iso8601 timestamp into your agent's scheduler. Avoid using this prompt in fire-and-forget scenarios where the agent cannot be paused and resumed; the entire value lies in the agent's ability to halt execution and resume precisely when the server permits.
Use Case Fit
Where the Rate Limit Retry-After Compliance Prompt works and where it does not. Use these cards to decide if this prompt fits your operational context before integrating it into an agent harness.
Good Fit: HTTP 429-Aware Agents
Use when: your agent makes HTTP calls to APIs that return standard Retry-After headers (seconds or HTTP-date). The prompt produces a compliant backoff schedule with jitter and user-facing delay messages. Guardrail: validate that the agent's HTTP client actually surfaces response headers to the prompt context; missing headers cause silent failures.
Bad Fit: Non-Standard Rate Limiting
Avoid when: the API uses custom rate limit headers (e.g., X-RateLimit-Reset, X-RateLimit-Remaining) without a Retry-After header, or enforces limits via connection drops rather than HTTP 429 responses. Guardrail: use the sibling Rate Limit Header Parsing prompt for custom header ecosystems; this prompt assumes RFC-compliant signaling.
Required Inputs
Must provide: the HTTP response status code, the raw Retry-After header value, the current timestamp, and the maximum acceptable wait threshold. Optional: the original request context for user communication. Guardrail: if any required field is missing or malformed, the prompt must abort with a structured error rather than guessing a retry interval.
Operational Risk: Deadline Misses
What to watch: the server-specified Retry-After value exceeds your system's maximum wait threshold or SLA deadline. The agent may stall indefinitely or fail the upstream task. Guardrail: the prompt must produce a deadline_exceeded decision with escalation path when the retry window breaches the configured maximum, never silently waiting beyond the threshold.
Operational Risk: Thundering Herd
What to watch: multiple agent instances receive the same Retry-After value and retry simultaneously, causing a thundering herd that re-triggers the rate limit. Guardrail: the prompt must apply jitter (randomized delay within a configurable range) to the retry schedule and document the jitter strategy in the output for observability.
Not a Substitute for Client-Side Logic
Avoid when: you can implement deterministic retry logic in application code. An LLM-based prompt adds latency and non-determinism to a problem solvable with a simple header parser and scheduler. Guardrail: use this prompt only when you need natural-language user communication alongside the retry decision, or when retry policy requires contextual reasoning beyond header parsing.
Copy-Ready Prompt Template
A reusable prompt that enforces server-specified Retry-After compliance with deadline handling and user communication.
This template instructs an agent to respect HTTP 429 responses by parsing the Retry-After header, calculating a compliant retry schedule, and communicating the delay to the user. It is designed for reliability engineers embedding rate-limit compliance directly into agent tool-call logic. The prompt forces the agent to treat the server's retry window as authoritative, preventing the common failure mode where agents ignore backoff instructions and hammer throttled endpoints.
textYou are an agent that strictly obeys rate-limit responses from external services. When a tool call returns an HTTP 429 status code, you MUST: 1. Extract the value from the `Retry-After` response header. 2. If the value is a delay in seconds, schedule the retry exactly that many seconds from the current time. 3. If the value is an HTTP-date, calculate the delay as the difference between that date and the current time. 4. Apply jitter of +/- [JITTER_RANGE] seconds to avoid thundering-herd effects, but never retry earlier than the server-specified window. 5. If the calculated retry time exceeds [MAX_WAIT_SECONDS], do NOT retry. Instead, return a deadline-exceeded response. For every rate-limited response, produce a structured output: { "action": "retry" | "deadline_exceeded", "retry_after_seconds": [PARSED_DELAY], "scheduled_retry_at": "[ISO8601_TIMESTAMP]", "jitter_applied_seconds": [JITTER_VALUE], "user_message": "[CLEAR_EXPLANATION_OF_DELAY]", "remaining_budget_seconds": [MAX_WAIT_SECONDS_MINUS_TOTAL_WAITED] } If the action is "deadline_exceeded", the user_message must explain that the retry window exceeds the maximum allowed wait time and suggest alternative actions. [CONSTRAINTS] - Never retry before the server-specified Retry-After window. - Never ignore a 429 response and retry immediately. - Track cumulative wait time across multiple retries for the same task. - If the same endpoint returns 429 on the retry, extract the new Retry-After value and recalculate. [EXAMPLES] Example 1: Retry-After: 120, current time 10:00:00, jitter +5s, max wait 300s Output: action=retry, retry_after_seconds=120, scheduled_retry_at=10:02:05, jitter=+5, user_message="Rate limited. Retrying in approximately 2 minutes." Example 2: Retry-After: 600, current time 10:00:00, max wait 300s Output: action=deadline_exceeded, retry_after_seconds=600, user_message="Server requested a 10-minute wait, which exceeds the 5-minute maximum. Task will not be retried."
Adapt this template by adjusting [JITTER_RANGE] and [MAX_WAIT_SECONDS] to match your service's SLA and user experience requirements. For high-throughput systems, keep jitter tight (1-5 seconds) to avoid excessive drift. For user-facing agents, set [MAX_WAIT_SECONDS] to a value that aligns with acceptable response latency—typically 30-300 seconds depending on the workflow. The structured output schema is designed for direct ingestion into logging and monitoring pipelines; do not remove fields without updating downstream consumers. Before deploying, validate that your agent's tool-call harness actually passes HTTP response headers into the prompt context—this is the most common integration gap.
Prompt Variables
Required inputs for the Rate Limit Retry-After Compliance Prompt. Each placeholder must be populated before the prompt is assembled and sent. Validation notes describe how to verify the input is well-formed before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[RATE_LIMIT_RESPONSE] | The raw HTTP 429 response body or headers containing the Retry-After directive | HTTP/1.1 429 Too Many Requests Retry-After: 120 | Parse check: extract Retry-After header value. Must be a positive integer or HTTP-date. Reject if missing or zero. |
[RETRY_AFTER_SECONDS] | The parsed Retry-After value in seconds, normalized from header or body | 120 | Type check: integer. Range check: 1 to 86400. Convert HTTP-date to delta-seconds if needed. Reject negative values. |
[CURRENT_RETRY_COUNT] | The number of retry attempts already made for this request | 3 | Type check: non-negative integer. Compare against [MAX_RETRIES]. If equal, prompt should recommend escalation instead of retry. |
[MAX_RETRIES] | The maximum allowed retry attempts before escalation | 5 | Type check: positive integer. Must be greater than [CURRENT_RETRY_COUNT] for retry to be valid. Hardcoded or config-driven. |
[MAX_WAIT_THRESHOLD_SECONDS] | The maximum total wait time the system will accept before aborting | 600 | Type check: positive integer. If [RETRY_AFTER_SECONDS] exceeds this, prompt should recommend abort with reason. Typically set by SRE policy. |
[REQUEST_CONTEXT] | Identifier for the request that was rate-limited, for logging and user communication | POST /api/v2/embeddings batch_id=xyz-123 | String. Must include endpoint and enough context for the caller to understand what is delayed. Null allowed if user-facing message is not required. |
[JITTER_ENABLED] | Whether to apply random jitter to the retry delay to prevent thundering herd | Boolean. If true, output schedule should include jitter range. If false, use exact Retry-After value. Default: true. |
Implementation Harness Notes
How to wire the Rate Limit Retry-After Compliance Prompt into a production agent harness with validation, scheduling, and observability.
This prompt is not a standalone chatbot instruction. It is a compliance function that should be called inside a tool execution wrapper whenever an HTTP 429 response is received. The wrapper must extract the Retry-After header value (either a delay-seconds integer or an HTTP-date), capture the tool name and arguments that triggered the rate limit, and pass them into the prompt as [RATE_LIMIT_RESPONSE]. The model's job is to produce a structured compliance decision, not to execute the retry itself. Your application code owns the actual sleep timer and retry dispatch.
Wire the prompt into a retry decision pipeline with these stages: (1) The HTTP client intercepts a 429 response and parses the Retry-After header into a normalized delay-seconds value. If the header is an HTTP-date, compute the delta from the current server time. (2) If the computed delay exceeds [MAX_WAIT_SECONDS], bypass the prompt entirely and escalate to the [ESCALATION_HANDLER] immediately—no model call needed. (3) Otherwise, invoke the prompt with the parsed delay, the tool identifier, the attempt count, and the session's remaining budget. (4) Parse the model's JSON output and validate that retry_after_seconds matches the header-derived value exactly. If the model hallucinates a different delay, reject the output and use the header value directly. (5) If the decision is retry, enqueue a delayed job using your scheduler (e.g., Celery, Temporal, BullMQ) with the exact delay plus optional jitter. If escalate, route to the escalation handler with the model's user_message and reasoning. If abort, log the termination and release any held resources.
Validation and safety checks are mandatory. Before acting on the model's output, confirm: retry_after_seconds is a positive integer within [MAX_WAIT_SECONDS], decision is one of the three allowed enum values, and user_message is present and non-empty for escalate and abort decisions. If the model returns retry but the cumulative retry time for this tool would exceed the session's remaining [BUDGET_REMAINING], override the decision to escalate with a budget-exhaustion reason. Log every decision—including overrides—as a structured audit record with the tool name, attempt number, header value, model decision, final action taken, and timestamp. This audit trail is essential for debugging rate-limit storms and proving compliance to API providers.
Model choice matters here. This prompt requires precise instruction-following and low hallucination on numeric values. Use a model with strong JSON mode and low latency—GPT-4o, Claude 3.5 Sonnet, or Gemini 1.5 Flash are appropriate. Avoid models known to drift on exact numeric constraints. Set temperature=0 and enable structured output mode with the [OUTPUT_SCHEMA] provided. If your platform cannot guarantee structured output, add a post-processing regex fallback that extracts the JSON block and re-validates. Do not use this prompt with a general-purpose chat model that might paraphrase the delay or invent a different backoff strategy.
What to avoid: Do not let the model control the actual timer or retry dispatch. The prompt advises on compliance; your code enforces it. Do not skip the exact-match check on retry_after_seconds—this is the most common failure mode, where the model rounds or adjusts the server-specified delay. Do not use this prompt for non-429 errors; 5xx retries have different semantics and should use a separate backoff prompt. Finally, do not deploy this without a circuit breaker that counts consecutive 429s per tool and escalates if the rate limit is not clearing after N attempts—otherwise you risk an infinite retry loop that the prompt alone cannot prevent.
Expected Output Contract
Fields, format, and validation rules for the structured output produced by the Rate Limit Retry-After Compliance Prompt. Use this contract to parse, validate, and integrate the agent's retry schedule into your application harness.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
retry_schedule | array of objects | Must be a non-empty array. Each element must conform to the retry_entry schema. | |
retry_entry.attempt_number | integer | Sequential integer starting at 1. Must be strictly increasing across the array. | |
retry_entry.retry_after_seconds | integer | Must be a positive integer. Must match the value parsed from the Retry-After header for the first entry. Subsequent entries may use exponential backoff with jitter if specified in [BACKOFF_POLICY]. | |
retry_entry.scheduled_time_utc | ISO 8601 datetime string | Must be a valid UTC datetime. Must equal the previous attempt time plus retry_after_seconds. Parse check required. | |
max_wait_threshold_exceeded | boolean | Must be true if any retry_entry.retry_after_seconds exceeds [MAX_WAIT_SECONDS], otherwise false. | |
user_message | string | Non-empty string explaining the delay to the end user. Must not expose raw header values or internal retry counts. Tone must match [USER_COMMUNICATION_TONE]. | |
deadline_miss_expected | boolean | Must be true if the final scheduled_time_utc exceeds [DEADLINE_UTC], otherwise false. If true, user_message must include a clear statement that the operation will not complete before the deadline. | |
escalation_required | boolean | Must be true if deadline_miss_expected is true or max_wait_threshold_exceeded is true, otherwise false. Triggers human-in-the-loop workflow in the harness. |
Common Failure Modes
What breaks first when agents parse and obey Retry-After headers, and how to prevent silent failures, stampeding herds, and deadline misses.
Header Parsing Ambiguity
What to watch: The model misinterprets the Retry-After header format, confusing an HTTP-date (e.g., Wed, 21 Oct 2015 07:28:00 GMT) with a delta-seconds integer (e.g., 120). This leads to immediate retries or absurdly long waits. Guardrail: Pre-parse the header in application code and inject a normalized [RETRY_DELAY_SECONDS] and [RETRY_DEADLINE_UTC] into the prompt. Never ask the model to parse raw HTTP headers.
Stampeding Herd After Global Throttle
What to watch: Multiple agent instances receive a 429 simultaneously, all wait the exact same Retry-After duration, and then fire at the same instant, triggering another rate limit. Guardrail: Instruct the agent to apply a bounded random jitter (e.g., ±15% of the wait window) to the computed delay. The prompt should require the final delay to be logged for observability.
Deadline Miss Due to Cumulative Wait
What to watch: An agent with a hard task deadline (e.g., 30 seconds) encounters a Retry-After value that pushes the total execution time past the limit. The agent waits, retries, and succeeds, but the calling system has already timed out. Guardrail: Provide a [TASK_DEADLINE_UTC] in the prompt. Instruct the agent to compare the [RETRY_DEADLINE_UTC] against the task deadline and abort with a DEADLINE_WOULD_BE_EXCEEDED reason code instead of waiting.
Infinite Retry on Non-Recoverable 429
What to watch: The agent treats every 429 as transient and retries indefinitely, even when the response body indicates a quota exhaustion or billing issue that won't resolve with waiting. Guardrail: Add a [MAX_RETRY_COUNT] parameter and require the agent to inspect the 429 response body for non-retryable keywords like quota_exceeded or billing_required. On detection, escalate to a human operator instead of retrying.
Silent Retry-After Ignorance
What to watch: The agent's tool-calling layer or SDK automatically retries without surfacing the 429 to the agent's reasoning context. The agent remains unaware of the delay, misattributes the latency, and cannot communicate the reason to the user. Guardrail: Ensure the tool response schema includes a [RATE_LIMIT_HIT] boolean and the [RETRY_AFTER_SECONDS] value. The system prompt must instruct the agent to check this field and generate a user-facing status message.
User-Facing Communication Failure
What to watch: The agent waits correctly but provides no status update to the user, who sees a frozen UI and assumes a crash. Or the agent reveals internal infrastructure details like raw header values. Guardrail: Require the agent to output a sanitized, user-friendly progress message (e.g., "The server is busy. Retrying in 45 seconds...") immediately upon detecting a rate limit. The prompt should forbid exposing raw Retry-After values or endpoint names.
Evaluation Rubric
Use this rubric to test whether the Rate Limit Retry-After Compliance Prompt produces outputs that are safe to deploy. Each criterion targets a specific failure mode observed in production agent systems.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Retry-After Header Parsing | Extracts integer seconds from standard Retry-After header and date-based Retry-After header with equal reliability | Output uses a hardcoded default delay instead of the server-supplied value; misinterprets date format as seconds | Feed mock 429 responses with both header formats; assert extracted delay matches header value within 1 second tolerance |
Delay Schedule Generation | Produces a schedule with exactly one retry attempt at the computed Retry-After timestamp plus jitter within [0, 1000] ms | Schedule contains multiple immediate retries; jitter exceeds 1000 ms or is negative; retry fires before Retry-After window elapses | Parse output schedule JSON; verify single retry entry; assert retry_time >= now + Retry-After seconds; assert jitter_ms in [0, 1000] |
Maximum Wait Threshold Enforcement | Aborts retry and escalates when computed delay exceeds [MAX_WAIT_SECONDS] threshold; communicates deadline miss to user | Output schedules a retry beyond the max wait threshold without escalation; silently drops the request | Set MAX_WAIT_SECONDS to 30, inject Retry-After of 120; assert output contains escalation action and no scheduled retry |
User-Facing Message Clarity | Generates a message stating the delay in human-readable form, the reason for the delay, and what happens next | Message contains raw seconds only; omits reason; promises a retry that will not occur due to threshold breach | Human review of 20 varied delay scenarios; pass if message includes delay duration, cause, and next step in all cases |
Deadline Miss Handling | When current time exceeds the computed retry window, outputs an immediate escalation without attempting a late retry | Output schedules a retry in the past; attempts an immediate retry ignoring the server's rate limit signal | Simulate clock skew by setting system time 60 seconds ahead of Retry-After window; assert output is escalation, not retry |
Non-429 Response Passthrough | Does not trigger retry logic for non-429 status codes; passes through the original error or response unchanged | Prompt applies Retry-After logic to 503, 500, or 200 responses; misinterprets non-rate-limit headers | Feed mock responses with status 200, 500, 503; assert retry schedule is null and output preserves original status |
Missing Retry-After Header Fallback | Applies a configurable [DEFAULT_BACKOFF_SECONDS] when 429 response lacks a Retry-After header; logs missing header as warning | Output crashes or returns null when header is absent; uses zero-second delay causing immediate retry | Inject 429 response with no Retry-After header; assert delay equals DEFAULT_BACKOFF_SECONDS; assert warning is present in logs |
Idempotency Key Preservation | Preserves or regenerates the [IDEMPOTENCY_KEY] across the retry boundary so the downstream service can deduplicate | Retry attempt uses a new or missing idempotency key, risking double-processing of the original request | Capture idempotency key from initial request; assert retry request carries the same key value |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a simple mock HTTP client that returns 429 responses. Focus on getting the Retry-After header parsing correct before adding jitter or deadline logic. Use a flat structure: parse header, calculate delay, return schedule.
codeYou are a rate-limit compliance agent. When you receive a 429 response with a Retry-After header, extract the delay value and return a retry schedule. [HTTP_RESPONSE_HEADERS] Return JSON: { "retry_after_seconds": [PARSED_VALUE], "retry_at_iso": [CALCULATED_TIMESTAMP], "header_raw": [ORIGINAL_HEADER_VALUE] }
Watch for
Retry-Aftercan be seconds or HTTP-date; prototype parsing often misses the date format- No jitter means thundering herd if multiple agents share a rate limit
- Missing deadline means infinite wait on unreasonable values (e.g.,
Retry-After: 86400)

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us