Skip to main content
To process billing and access control, every billable request must include a user identity. This guide shows exactly how to pass it from popular clients and runtimes.
Avoid PII in user IDs. Prefer stable, pseudonymous strings (e.g., “user_123”). Avoid spaces and special characters.

Supported methods

  1. Body field user — recommended (works with OpenAI‑compatible SDKs)
  2. Header X-Paywall-User — easy to inject via middleware/proxy
  3. URL prefix /{user}/… — fallback when body/headers cannot be modified
Base URL and auth for all examples:
  • Base URL: https://api.paywalls.ai/v1
  • Header: Authorization: Bearer $PAYWALLS_API_KEY

Option 2 — Header X-Paywall-User

Option 3 — URL prefix (fallback)

Use the URL prefix only if you cannot modify body/headers.

Node (OpenAI SDK)

Body user
Header X-Paywall-User
Streaming

Python (OpenAI SDK)

Header variant (if your SDK layer supports default headers):

Vercel AI SDK (Edge)

Body user
Header injection

Fetch / cURL

fetch (header)
cURL (body user)
cURL (header)

Behavior summary

On each request Paywalls extracts the user id (body > header > URL), checks authorization and balance, and either:
  • Returns an assistant message with an authorization/top‑up link (no charge), or
  • Forwards the request, meters usage, deducts balance, and streams the model response.

Best practices

  • Use body user when possible; header is a great middleware fallback.
  • Keep IDs stable across sessions and retries. Avoid PII.
  • Ensure your server/edge passes the user on every billable request.