Best practices
Session management
Do
- Use Idempotency-Key for create and renew to avoid duplicate orders on retries.
- Terminate sessions when done:
POST /sessions/{session_id}/terminate. - Monitor usage via
GET /sessions/{session_id}/usage; act when usage is high (e.g. >80%). - Limit concurrency when creating many sessions (e.g. semaphore or queue).
Avoid
- Leaving sessions active indefinitely without cleanup.
- Rotating on a fixed schedule regardless of success/failure — prefer rotating on errors (403, 429, captcha) or when telemetry recommends it.
- Hardcoding
api_keyorapi_secret; use environment variables or a secret manager. - Skipping telemetry — report success and errors so the system can suggest when to rotate.
Performance
| Practice | Description |
|---|---|
| Reuse sessions | One session for many requests instead of creating per request |
| Smart rotation | Use telemetry recommendation (e.g. rotate_now) rather than blind timed rotation |
| Report telemetry | Enables better health and rotation advice |
| Cache products | Product list changes infrequently; cache 5–10 minutes |
| Connection pool | Use HTTP client connection pooling |
| Respect rate limits | Read X-RateLimit-* headers and throttle to avoid 429 |
Security
| Practice | Description |
|---|---|
| Env for secrets | Store API key/secret in env or secret manager |
| HTTPS only | All requests to https://api.nexalayer.net/v1 |
| Token refresh | If using JWT, refresh before expiry |
| Monitor usage | Watch for unexpected API or session usage |