Skip to main content

SDK Goal

Your SDK should make ingest trivial:
  • capture request lifecycle data
  • normalize payloads
  • batch and flush safely
  • retry on transient failures

Official Python SDK

API Lens ships an official Python SDK in sdks/python, published as apilenss. Supported today:
  • FastAPI (apilens.fastapi middleware)
  • Flask (apilens.flask wrapper)
  • Django / Django Ninja (apilens.django middleware)
Planned / not supported yet (do not wire these): Starlette, Litestar, BlackSheep. We’ll add them when they reach parity; track in the SDK repo issues. Get the exact install and middleware snippets in sdk/python-setup.mdx. Use extras for the framework you need:
Minimal FastAPI example (supported):
  1. Intercept request start/end timestamps
  2. Build normalized request item
  3. Add to in-memory queue
  4. Flush queue on interval or size threshold
  5. POST to /ingest/requests with API key

Required Headers

  • Content-Type: application/json
  • X-API-Key: <app_api_key>

Suggested Defaults

  • Batch size: 100-500
  • Flush interval: 2-5 seconds
  • Max retries: 3
  • Backoff: exponential with jitter

Normalization Rules

  • Uppercase HTTP method
  • Remove query string from route path
  • Convert response time to milliseconds
  • Include environment (production/staging)

Minimal Node Example

Endpoint Checklist

When generating SDK clients for dashboard APIs, include:
  • Auth endpoints (/auth/*)
  • App CRUD (/apps/*)
  • Endpoint stats + options (/apps/{slug}/endpoint-stats, /endpoint-options)
  • Analytics endpoints (/apps/{slug}/analytics/*)
  • Ingest endpoint (/ingest/requests)

Versioning Advice

  • Keep schema adapters per API version
  • Hide wire schema behind typed SDK interfaces
  • Add integration test against a running APILens local env