Skip to main content

Version: latest

Stream Routes

Stream routes enable API7 Gateway to proxy Layer 4 (L4) traffic — TCP and UDP connections — in addition to the standard Layer 7 (HTTP/HTTPS) traffic handled by regular routes. This allows you to use API7 Gateway as a unified proxy for both HTTP APIs and non-HTTP protocols such as databases, message queues, and custom TCP services.

How Stream Routes Work

Unlike HTTP routes that match on URI paths, HTTP methods, and headers, stream routes match on network-layer attributes:

Match FieldDescriptionExample
remote_addrClient IP address or CIDR range10.0.0.0/8
server_addrGateway listening IP address192.168.1.100
server_portGateway listening port3306
sniTLS Server Name Indication (for TLS streams)db.example.com

All specified match fields are evaluated with AND logic. If no match fields are specified, the stream route matches all traffic on the configured stream proxy ports.

Request Flow

  1. A TCP or UDP client connects to one of the gateway's configured stream_proxy ports.
  2. The gateway evaluates all stream routes against the connection's network attributes.
  3. The matching stream route determines the upstream, and the connection is proxied to the upstream service.

Stream Services

Stream routes must belong to a stream-type service (service with type: stream). A stream service cannot contain regular HTTP routes, and an HTTP service cannot contain stream routes.

Stream services share the same lifecycle as HTTP services:

  • Service templates with versioning
  • Publishing to gateway groups
  • Upstream inheritance (stream routes inherit upstream configuration from their parent service unless overridden)

Supported Plugins

Only a subset of plugins support the stream (L4) context:

PluginCategoryDescription
ip-restrictionSecurityAllow/deny traffic based on client IP
limit-connTrafficLimit concurrent connections
mqtt-proxyProtocolMQTT protocol proxy and routing
traffic-splitTrafficSplit traffic across upstreams by weight
prometheusObservabilityExpose stream metrics
syslogObservabilityLog stream events to syslog

HTTP-only plugins (such as key-auth, proxy-rewrite, or response-rewrite) cannot be applied to stream routes.

Enabling Stream Proxy

Before using stream routes, you must configure the gateway to listen on TCP and/or UDP ports for stream traffic. This is done in the gateway's config.yaml:

apisix:
stream_proxy:
tcp:
- addr: 9100 # Listen on all interfaces, port 9100
- addr: "127.0.0.1:9101" # Listen on specific IP
tls: true # Enable TLS on this port
udp:
- 9200 # Listen on all interfaces, port 9200
info

Stream proxy ports are separate from the HTTP proxy ports (node_listen / ssl.listen). Clients connect to stream proxy ports for L4 traffic and to HTTP ports for L7 traffic.

Stream Routes vs. HTTP Routes

AspectHTTP RoutesStream Routes
ProtocolHTTP, HTTPS, gRPC, WebSocketTCP, UDP
Match criteriaURI, host, headers, methods, expressionsClient IP, server IP, server port, SNI
Service typehttpstream
Plugin supportFull plugin library6 stream-compatible plugins
Routing algorithmRadix tree on URISequential match on IP/port (radix tree on SNI for TLS)

Next Steps

API7.ai Logo

The digital world is connected by APIs,
API7.ai exists to make APIs more efficient, reliable, and secure.

Sign up for API7 newsletter

Product

API7 Gateway

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN PTE. LTD 2019 – 2026. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the Apache Software Foundation