Skip to content
Help guide the future of agentgateway — Take the survey

Retries

Verified : Automated tests passed for: Configuration files: The configuration files on this page were checked against their schema. End-to-end run: Every step ran in a fresh test environment and the results were checked.
Page as Markdown

Configure automatic retry attempts for failed backend requests.

Attaches to:

Note

Agentgateway supports more than one configuration style. Where a feature can also be configured in the simplified llm or mcp modes, the examples on this page show each option in tabs. For more information, see Routing-based configuration.

When a backend request fails, agentgateway can be configured to retryRetryA resiliency feature that automatically resends failed requests to backends. Retries can be configured with backoff strategies and specific conditions for when to retry. the request. Keep in mind that each retry goes to the same route backend as the original request. For LLM traffic, if you also want to configure failover so that an endpoint is marked as unhealthy and a request tried with a different endpoint, use failover routing with virtual models.

Configure retries

Add a retry policy to an MCP listener, an LLM gateway, or a route. If you omit attempts, a failed request is retried once. To disable retries, set attempts to 0.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
mcp:
  port: 3000
  policies:
    retry:
      # Maximum number of retries after the original request.
      # Note: A value of 3 allows up to 3 retries after the initial attempt.
      attempts: 3
      # Optional; if set, a delay between each additional attempt
      backoff: 500ms
      # A list of HTTP response codes to consider retry-able.
      # In addition, retries are always permitted if the request to a backend was never started.
      codes: [429, 500, 503]
  targets:
  - name: everything
    stdio:
      cmd: npx
      args: ["@modelcontextprotocol/server-everything"]

Retry requests with large bodies

When a request has retries enabled and an HTTP body, the request body is buffered so that it can be resent. If the body is larger than the frontend buffer limit, the request is not retried. The default limit is 2 MiB or 32 MiB for LLM requests. To retry larger requests, raise the limit in the frontendPolicies.http.maxBufferSize field.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
frontendPolicies:
  http:
    # Maximum request or response body size to buffer, in bytes.
    maxBufferSize: 10485760

Choose which requests and responses are retried

By default, a response is retried when its status code is in codes. Two optional CEL expressions refine the retry decision.

  • precondition is evaluated on the request before the request is sent. When the expression is false, the request is sent once and never retried. Use a precondition to retry only idempotent requests, such as GET requests.
  • condition is evaluated on each response. A response is retried when the status code is in codes or when the condition expression is true.
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
gateways:
  default:
    port: 3000
routes:
- policies:
    retry:
      attempts: 2
      backoff: 200ms
      codes: [503]
      # Optional; a CEL expression on the request. When false, the request is never retried.
      precondition: 'request.method == "GET"'
      # Optional; a CEL expression on each response. When true, the response is also retried.
      condition: 'response.headers["x-retry"] == "true"'
  backends:
  - host: localhost:8080

With this configuration, a GET request that gets a 503 response reaches the backend three times. The three calls are the original request and two retries, 200 milliseconds apart. A POST request that gets a 503 response reaches the backend once. For a GET request, a 200 response with an x-retry: true header is retried the same way as a 503 response.

Each retry carries an x-retry-attempt header with the retry number, starting at 1. The original request has no x-retry-attempt header. The backend can use the header to tell a retry from a new request.

Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.