Prompt
Can you recommend an API security approach that won't break legitimate users?
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
Yes: use a layered, risk-based API security approach that protects the API without forcing overly aggressive controls on normal users.
Recommended approach
1. Strong identity first
- Use OAuth 2.0 / OpenID Connect for user-facing APIs.
- Use mTLS, signed JWTs, or API keys only for machine-to-machine access.
- Keep tokens short-lived and scope them narrowly.
2. Least privilege
- Give each client/service only the permissions it needs.
- Use scoped access tokens instead of broad account-level credentials.
- Separate public, partner, and internal APIs with different policies.
3. Adaptive rate limiting, not hard blocking
- Rate-limit by user, client ID, IP, and token, not just IP.
- Use burst + sustained limits so normal spikes still work.
- Add progressive throttling rather than immediate rejection.
4. Behavior-based anomaly detection
- Detect unusual patterns like:
- very high error rates
- abnormal geo/location changes
- impossible travel
- high-volume enumeration
- token reuse from multiple devices
- Prefer step-up verification or temporary throttling over instant bans.
5. Input validation and schema enforcement
- Validate requests against a strict schema.
- Reject malformed inputs early.
- This prevents abuse without affecting legitimate clients that follow the contract.
6. Safe authorization checks
- Enforce object-level authorization on every request.
- Don’t rely on the front end or on “hidden” endpoints.
- Use policy checks consistently to avoid breaking valid access paths.
7. Bot and abuse controls that are friction-aware
- For suspicious traffic, use:
- CAPTCHA only for interactive flows
- proof-of-work or challenge-response where appropriate
- device/session reputation
- Avoid CAPTCHA on core API calls unless absolutely necessary.
8. Versioned, well-documented API contracts
- Maintain clear deprecation and versioning policies.
- Communicate rate limits and error responses clearly.
- Legitimate users are less likely to be blocked if clients can adapt.
9. Observability and feedback loops
- Log authentication, authorization, and throttling decisions.
- Monitor false positives.
- Continuously tune thresholds based on real traffic.
A good default pattern
If you want a practical baseline:
- OAuth2/OIDC + short-lived tokens
- Scoped authorization
- Per-client and per-user adaptive rate limits
- Anomaly detection with step-up controls
- Strict schema validation
- Clear versioning and deprecation
Key principle
The best way to avoid breaking legitimate users is to degrade gracefully:
- warn first
- throttle next
- challenge when needed
- block only when confidence is high
If you want, I can also give you:
- a reference architecture,
- a policy checklist, or
- a sample API gateway configuration for this approach.