Chi rate limiting,with keys and credits built in.
Chi speaks net/http, so the standard ReqKey middleware drops straight into r.Use — checking keys, charging credits, and applying each customer’s plan limit.
- Keys issued per customer
- Credits that refill
- Limits per plan, not per process
Official SDKs with drop-in middleware for the stack you already run
- Python
- Node.js
- Go
- Rust
- PHP
- .NET
- Java
- API requests validated
- 100M+
- Average key validation
- <5ms
- Average analytics ingest
- <5ms
- Check and log, end to end
- <10ms
The usual Chi rate limiter counts requests. It doesn’t know your customers.
go-chi/httprate is the companion limiter: LimitByIP or a custom key function over a sliding window, in memory unless you add its Redis backend.
// main.go — with httprater := chi.NewRouter()
r.Use(httprate.LimitByIP(100, time.Minute))- Keyed by IP address by default, not by the customer who is paying
- Counters live in process memory — every worker and every instance keeps its own count
- No API keys: issuing, hashing, scoping, and revoking them is still yours to build
- No credit balance: a request can’t cost 5 on one route and 1 on another, or refill each month
- One limit for everyone — no per-plan limits for Free, Pro, and Enterprise customers
- No per-customer usage log to answer “why was I blocked?” or bill against
- API keys issued per customer, prefixed, hashed, and revocable from the dashboard
- A credit balance per customer — price each route, refill every hour, day, week, or month
- Rate limits set per plan, shared by all of a customer’s keys, from 1 second to 24 hours
- The same count on every worker, instance, and region — no Redis to run
- Over the limit? A 429 with Retry-After, and no credits charged
- Every request logged per customer — status, latency, endpoint — in under 5ms
Chi in three steps, one of them code.
ReqKey runs inside your API, not in front of it. Your server asks one question per request and gets an answer in under 5ms.
- 1
Install the SDK
go get github.com/Req-Key/reqkey-go@latest github.com/go-chi/chi/v5 - 2
Set your project key
Copy it from the dashboard into
REQKEY_PROJECT_KEY. It stays on your server. - 3
Add the Chi middleware
Every request is checked, charged, and logged before your handler runs.
package main import ( "net/http" "os" "github.com/Req-Key/reqkey-go" "github.com/go-chi/chi/v5") func main() { router := chi.NewRouter() // Chi speaks the standard func(http.Handler) http.Handler contract, // so the core middleware works directly — the same is true for Gorilla/Mux. router.Use(reqkey.MustHTTPMiddleware(reqkey.MiddlewareOptions{ ProjectKey: os.Getenv("REQKEY_PROJECT_KEY"), APIID: "api_payments", Mode: reqkey.ModeBoth, KeyName: "X-Startup-Key", })) router.Get("/protected", handler) _ = http.ListenAndServe(":8080", router)}Every request gets one of these answers
- 200Valid key, credits charged — your handler runs
- 402Out of credits
- 403Key disabled, or not allowed on this API
- 429Over the rate limit — no credits charged
Where ReqKey sits
Responses go straight back to your customer. ReqKey sees the key check and the log line, nothing else.
Credits
Charge each route what it costs you.
A lookup can cost 1 credit and a render 5, from the same balance. Excluded paths are never validated, charged, or recorded. In Go:
// Exact paths or trailing-* prefixes: never validated, charged, or recordedExcludePaths: []string{"/health", "/openapi.json", "/docs/*", "/cron/*"}, // Or decide per request with a resolverShouldProtect: func(ctx context.Context, request *reqkey.MiddlewareRequest) (bool, error) { return strings.HasPrefix(request.Path, "/api/"), nil}, // Charge different endpoints differently (non-negative integers)CreditsResolver: func(ctx context.Context, request *reqkey.MiddlewareRequest) (int, error) { if request.Method == http.MethodPost { return 5, nil } return 1, nil},Rate limits
Set limits on plans, not in code.
Your Chi code never hard-codes a number. Each plan carries its credits, refill, and rate limit; moving a customer to Pro changes all three with no deploy.
Example plans. You name them and pick the numbers.
Notes for Chi teams hit in production.
No separate package
Chi uses the standard middleware from reqkey-go — nothing Chi-specific to install.
Scope it with r.Group
Put the middleware inside r.Route("/v1", ...) to protect the paid API and leave everything else open.
Composable
It stacks with chi’s own middleware — RequestID, Logger, Recoverer — in the order you choose.
Chi rate limiting: the questions teams ask.
Something else? Ask the team or read the docs.
Yes: httprate for anonymous IP throttling on public routes, ReqKey for keyed customer routes.
Into the request context — read it with reqkey.DecisionFromContext.
On their plan or on the customer (consumer) in ReqKey — a number of requests per window from 1 second to 24 hours, shared by all of that customer’s keys. Your Chi code never hard-codes a limit, so upgrading a customer is a dashboard change, not a deploy.
A check averages under 5ms. ReqKey runs inside your app as middleware, not as a gateway in front of it, so responses go straight back to your customer.
You choose: fail closed and answer 503, or fail open and let requests through. Invalid keys are denied either way, and a validation is never retried, so no one is charged twice.
Ship API keys in Chiin five minutes.
Free for your first 5 million requests every month. No card, no gateway, no rewrite.