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

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Response idle timeouts

Page as Markdown

Set a response idle timeout to terminate responses where the body stops sending data.

About response idle timeouts

A response has two phases. First, the backend sends the response headers, which include the status code. Then, the backend sends the response body in one or more pieces, which are also referred to as frames. A short response sends the body in a single frame. A streamed response, such as an LLM completion, sends many frames over a long time.

A request timeout timer starts with the request and stops when the response headers arrive from the backend. After that point, the request timeout no longer applies, no matter how long the body takes. If the backend stalls halfway through the body, the client already has the status code, and the response stays open without another timer that ends it.

You can set a response idle timeout in the traffic.timeouts.responseIdle field of an AgentgatewayPolicy to terminate responses where the body stalled. The gateway waits for the next frame of the response body, and the timer restarts with every frame that arrives. If no frame arrives in time, the gateway ends the response. A stalled response ends quickly, while an active response can stream for as long as it needs. The response idle timeout does not apply to the wait for the response headers.

Before you begin

  1. Set up an agentgateway proxy.
  2. Install the httpbin sample app.

Set up a response idle timeout

  1. Create an HTTPRoute for the /drip path of the httpbin app. The /drip path sends its response one byte at a time, so you can stall the response body on purpose.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-idle
      namespace: httpbin
    spec:
      hostnames:
      - idle.example
      parentRefs:
      - name: agentgateway-proxy
        namespace: agentgateway-system
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /drip
        backendRefs:
        - name: httpbin
          port: 8000
    EOF
  2. Create an AgentgatewayPolicy that sets a response idle timeout of 2 seconds on the HTTPRoute.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayPolicy
    metadata:
      name: httpbin-idle
      namespace: httpbin
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: httpbin-idle
      traffic:
        timeouts:
          responseIdle: 2s
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    targetRefsThe HTTPRoute that the timeout applies to. You can also target an HTTPRoute rule or a Gateway listener.
    traffic.timeouts.responseIdleThe time that the gateway waits for the next frame of the response body from the backend. The timer restarts with every frame. Response processing and client backpressure do not count. When the time passes, the gateway ends the response.
  3. Send a request to the /drip path. In the query string, numbytes sets the number of bytes, duration sets the time that httpbin spreads the bytes over, and delay=0 sends the first byte right away. With these values, httpbin sends one byte every 3 seconds. The gateway forwards the response headers and the first byte. When the next byte does not arrive within 2 seconds, the gateway ends the response.

    curl -s -o /dev/null -w 'status=%{http_code} bytes=%{size_download} time=%{time_total}s exit=%{exitcode}\n' \
      "http://$INGRESS_GW_ADDRESS:80/drip?duration=9&numbytes=3&delay=0" -H "host: idle.example"

    Example output:

    status=200 bytes=1 time=2.007100s exit=18
    

    The client already has the 200 status code when the timeout applies. The client gets a response that ends early instead of an error status code. The exit=18 value is the curl exit code for a partial file, which shows that the response was cut short.

  4. Send a request with different numbytes and duration values, so that httpbin sends one byte every half second. The whole response takes about 5 seconds, which is longer than the idle timeout. No gap between two bytes reaches 2 seconds, so the response completes.

    curl -s -o /dev/null -w 'status=%{http_code} bytes=%{size_download} time=%{time_total}s exit=%{exitcode}\n' \
      "http://$INGRESS_GW_ADDRESS:80/drip?duration=5&numbytes=10&delay=0" -H "host: idle.example"

    Example output.

    status=200 bytes=10 time=5.063975s exit=0
    

Cleanup

You can remove the resources that you created in this guide. Run the following commands.

kubectl delete AgentgatewayPolicy httpbin-idle -n httpbin
kubectl delete httproute httpbin-idle -n httpbin
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/.