← Blog

How to API Gateway: A Practical Setup Guide

2026-09-07 · 5 min read · SubToAPI Team

Setting up an API gateway means putting a single, controlled entry point in front of one or more backend services, then configuring it to handle routing, authentication, rate limiting, and logging so your actual services don't have to. If you're asking "how to API gateway," you're really asking how to go from "clients talk directly to my backend" to "clients talk to a gateway, and the gateway talks to my backend."

This guide walks through the concrete steps: deciding what you're putting behind the gateway, picking a gateway model (managed vs. self-hosted vs. a purpose-built service), configuring routes and auth, and testing the result before you cut traffic over.

Step 1: Decide what the gateway needs to do

Before touching any config, write down what problem you're solving. Common reasons to add a gateway:

If your only goal is "give my app a stable HTTPS API for a service I use, with keys and usage tracking," you may not need to build a gateway at all — a hosted one can do this out of the box. More on that below.

Step 2: Choose your gateway model

There are three broad options:

  1. Self-hosted software gateways — Kong, NGINX, Envoy, Tyk. You run the software, you own the config, you own the ops burden (scaling, TLS certs, upgrades).
  2. Cloud-managed gateways — AWS API Gateway, Azure API Management, Google Cloud Endpoints. Less ops, but tied to that cloud's routing/auth model and pricing.
  3. Purpose-built API-as-a-service products — a hosted gateway built specifically for one use case, like exposing a third-party API (an AI provider, a payment processor) as a clean, keyed HTTPS API without you running any infrastructure.

For general backend consolidation, options 1 and 2 make sense. For a narrower goal — turning an existing account or subscription into a stable API with your own keys — a purpose-built service is usually faster to ship. For example, if you're wrapping Claude access for an app, SubToAPI does exactly this: it gives you application API keys (sub_live_...), streaming, tool use, and usage metadata without you having to build and operate a gateway yourself.

Step 3: Define your routes

Every gateway needs a routing table: which incoming path maps to which backend, and what transformation (if any) happens in between. A minimal routing config looks like this conceptually:

routes:
  - path: /v1/users/*
    upstream: https://users-service.internal
  - path: /v1/orders/*
    upstream: https://orders-service.internal
  - path: /v1/messages
    upstream: https://ai-provider.internal/v1/messages

Keep routes narrow and explicit rather than wildcarding everything to one backend — it makes rate limiting and auth rules easier to scope later.

Step 4: Add authentication

This is where most gateway setups earn their keep. Instead of every backend service validating credentials independently, the gateway does it once, at the edge.

Typical pattern: clients send a bearer token, the gateway validates it, then either passes a trusted internal token to the backend or strips the client credential entirely.

curl https://api.yourcompany.com/v1/orders \
  -H "Authorization: Bearer sk_live_abc123"

If you're building this yourself, you need to handle key generation, revocation, and per-key rate limits — which is nontrivial to get right. If you're specifically exposing an AI model like Claude, you can skip this build entirely: SubToAPI issues per-application keys and handles auth at the gateway layer so your code just sends a bearer token. See the quickstart for the exact request shape.

Step 5: Add rate limiting and quotas

Rate limits protect your backend and let you differentiate plans. At minimum, decide:

curl -i https://api.yourcompany.com/v1/orders \
  -H "Authorization: Bearer sk_live_abc123"

HTTP/1.1 429 Too Many Requests
Retry-After: 12

If you're managing this for a team, seat-based plans (Solo, Team, Scale) are often simpler to reason about than raw request quotas, since usage naturally scales with headcount.

Step 6: Add observability

A gateway without logging is a black box you'll regret in production. At minimum, log per-request: route, client identity, response status, latency, and (for metered APIs) usage units consumed. This is also where you catch abuse patterns before they become incidents.

If you're building a Node.js proxy in front of a gateway or calling one directly, structure your client so logging and retries live in one place:

async function callGateway(path, body) {
  const res = await fetch(`https://api.subtoapi.app/v1${path}`, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  });

  if (!res.ok) {
    console.error("gateway error", res.status, await res.text());
    throw new Error(`gateway request failed: ${res.status}`);
  }

  return res.json();
}

Step 7: Test before cutover

Before pointing production traffic at the gateway:

Once that's solid, cut traffic over gradually — canary a percentage of clients first if your DNS/load balancer setup allows it.

When to build vs. buy

Building a gateway makes sense when you're consolidating several internal services with custom logic. It's overkill when your actual goal is narrower: turning one external service — like a Claude subscription — into a stable, keyed HTTPS API for your product. In that case, a hosted option gets you there in minutes instead of weeks. Check the pricing page or start a free trial if that's your situation.

questions

Do I need Kubernetes to run an API gateway? No. Self-hosted gateways like NGINX or Envoy can run as a single process behind a load balancer. Kubernetes is common for large deployments but not a requirement.

What's the difference between an API gateway and a reverse proxy? A reverse proxy forwards requests. A gateway adds application-aware logic on top — auth, rate limiting, per-client routing, and usage metering — making it a superset of a plain proxy.

Can I add a gateway without changing my existing backend code? Usually yes. The gateway sits in front of existing services and handles routing, auth, and limits at the edge, so backend code typically doesn't need to change unless you're also restructuring routes.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →