Rate limit A2A traffic

TL;DR

Enable the Rate Limiting Advanced plugin on the same service or route as the AI A2A Proxy plugin. Combined with an authentication plugin, rate limits apply per consumer. Requests that exceed the limit are rejected with 429.

Prerequisites

This is a Konnect tutorial and requires a Konnect personal access token.

  1. Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.

  2. Export your token to an environment variable:

     export KONNECT_TOKEN='YOUR_KONNECT_PAT'
    
  3. Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:

     curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN --deck-output
    

    This sets up a Konnect Control Plane named quickstart, provisions a local Data Plane, and prints out the following environment variable exports:

     export DECK_KONNECT_TOKEN=$KONNECT_TOKEN
     export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart
     export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
     export KONNECT_PROXY_URL='http://localhost:8000'
    

    Copy and paste these into your terminal to configure your session.

This tutorial requires Kong Gateway Enterprise. If you don’t have Kong Gateway set up yet, you can use the quickstart script with an enterprise license to get an instance of Kong Gateway running almost instantly.

  1. Export your license to an environment variable:

     export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'
    
  2. Run the quickstart script:

    curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA 
    

    Once Kong Gateway is ready, you will see the following message:

     Kong Gateway Ready
    

decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial, install decK version 1.43 or later.

This guide uses deck gateway apply, which directly applies entity configuration to your Gateway instance. We recommend upgrading your decK installation to take advantage of this tool.

You can check your current decK version with deck version.

For this tutorial, you’ll need Kong Gateway entities, like Gateway Services and Routes, pre-configured. These entities are essential for Kong Gateway to function but installing them isn’t the focus of this guide. Follow these steps to pre-configure them:

  1. Run the following command:

    echo '
    _format_version: "3.0"
    services:
      - name: a2a-currency-agent
        url: http://host.docker.internal:10000
    routes:
      - name: a2a-route
        paths:
        - "/a2a"
        strip_path: true
        service:
          name: a2a-currency-agent
        protocols:
        - http
        - https
    ' | deck gateway apply -
    

To learn more about entities, you can read our entities documentation.

This tutorial uses OpenAI:

  1. Create an OpenAI account.
  2. Get an API key.
  3. Create a decK variable with the API key:

    export DECK_OPENAI_API_KEY='YOUR OPENAI API KEY'
    

You need a running A2A-compliant agent. This guide uses a sample currency conversion agent from the A2A project.

Create a docker-compose.yaml file:

cat <<'EOF' > docker-compose.yaml
services:
  a2a-agent:
    container_name: a2a-currency-agent
    build:
      context: .
      dockerfile_inline: |
        FROM python:3.12-slim
        WORKDIR /app
        RUN pip install uv && apt-get update && apt-get install -y git
        RUN git clone --depth 1 https://github.com/a2aproject/a2a-samples.git /tmp/a2a && \
            cp -r /tmp/a2a/samples/python/agents/langgraph/* . && \
            rm -rf /tmp/a2a
        ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
        RUN uv sync --frozen --no-dev
        EXPOSE 10000
        CMD ["uv", "run", "app", "--host", "0.0.0.0"]
    environment:
      - model_source=openai
      - API_KEY=${DECK_OPENAI_API_KEY}
      - TOOL_LLM_URL=https://api.openai.com/v1
      - TOOL_LLM_NAME=gpt-5.1
    ports:
      - "10000:10000"
EOF

Export your OpenAI API key and start the agent:

export DECK_OPENAI_API_KEY='your-openai-key'
docker compose up --build -d

The agent listens on port 10000 and uses the A2A JSON-RPC protocol to handle currency conversion queries. In this guide, the gateway service points to host.docker.internal:10000 instead of the container name because Kong Gateway runs in its own container with a separate DNS resolver.

Enable the AI A2A Proxy plugin

The AI A2A Proxy plugin parses A2A JSON-RPC requests and proxies them to the upstream agent.

echo '
_format_version: "3.0"
plugins:
  - name: ai-a2a-proxy
    config:
      logging:
        log_statistics: true
        log_payloads: true
' | deck gateway apply -

Enable the Key Auth plugin

The Key Auth plugin identifies callers and associates them with a Kong consumer. Rate Limiting Advanced uses this consumer identity to apply per-consumer limits.

echo '
_format_version: "3.0"
plugins:
  - name: key-auth
' | deck gateway apply -

Enable the Rate Limiting Advanced plugin

The Rate Limiting Advanced plugin counts requests per consumer and rejects requests that exceed the configured limit. This configuration allows 5 requests per 30 seconds, intentionally low to make it easy to trigger during testing.

echo '
_format_version: "3.0"
plugins:
  - name: rate-limiting-advanced
    config:
      limit:
      - 5
      window_size:
      - 30
      sync_rate: -1
      namespace: a2a-currency-agent
      strategy: local
' | deck gateway apply -

Set limit and window_size to values appropriate for your production workload. The values in this guide are intentionally low for testing.

Validate rate limit headers

Send an authenticated request to the agent card endpoint and inspect the response headers. The agent card is a lightweight A2A operation (GetAgentCard) that returns agent metadata without calling an LLM, so responses are instant.

curl -X GET "$KONNECT_PROXY_URL/a2a/.well-known/agent-card.json" \
     --no-progress-meter --fail-with-body  \
     -H "apikey: a2a-secret-key-1"

curl -X GET "http://localhost:8000/a2a/.well-known/agent-card.json" \
     --no-progress-meter --fail-with-body  \
     -H "apikey: a2a-secret-key-1"

The response includes rate limit headers:

HTTP/2 200
...
ratelimit-limit: 5
ratelimit-remaining: 4
ratelimit-reset: 30
x-ratelimit-limit-30: 5
x-ratelimit-remaining-30: 4

ratelimit-remaining decreases with each request. ratelimit-reset shows the seconds until the window resets.

Validate rate limit enforcement

Send 6 requests to the agent card endpoint in a loop to exceed the limit. The AI A2A Proxy plugin detects each request as an A2A GetAgentCard operation, so the rate limit applies the same way it does for message/send or any other A2A method.

for i in $(seq 1 6); do
  echo "--- Request $i ---"
  curl -s -o /dev/null -w "HTTP status: %{http_code}\n"\
    http://localhost:8000/a2a/.well-known/agent-card.json \
    -H "apikey: a2a-secret-key-1"
done
for i in $(seq 1 6); do
  echo "--- Request $i ---"
  curl -s -o /dev/null -w "HTTP status: %{http_code}\n"\
    $KONNECT_PROXY_URL/a2a/.well-known/agent-card.json \
    -H "apikey: a2a-secret-key-1"
done

The first 5 requests return HTTP status: 200. The 6th request returns HTTP status: 429:

--- Request 1 ---
HTTP status: 200
--- Request 2 ---
HTTP status: 200
--- Request 3 ---
HTTP status: 200
--- Request 4 ---
HTTP status: 200
--- Request 5 ---
HTTP status: 200
--- Request 6 ---
HTTP status: 429

The 429 response body contains:

{
  "message": "API rate limit exceeded"
}

Cleanup

If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.

curl -Ls https://get.konghq.com/quickstart | bash -s -- -d

FAQs

Yes. Without an authentication plugin, the Rate Limiting Advanced plugin falls back to rate limiting by IP address. Add an authentication plugin if you need per-consumer limits.

Rate limiting applies at request time, before the upstream responds. A streaming SSE response that is already in progress is not interrupted. The rate limit check happens when the client sends the next request.

AI Rate Limiting Advanced limits based on LLM token consumption (prompt and completion tokens). The AI A2A Proxy plugin does not extract token counts from A2A responses, so AI Rate Limiting Advanced has no token data to act on. Use the standard Rate Limiting Advanced plugin for A2A traffic.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!