Skip to main content
nozle-sdk supports Python 3.9 through 3.13, uses requests, and includes a py.typed marker. Entity subscription APIs are introduced in 0.5.0.
Version 0.13.1 changes wrap_openai() and wrap_anthropic() to return a client view instead of patching the client you pass in; use the returned client. See Client wrappers. Version 0.13.0 adds AsyncNozle, opt-in retries, the host argument, an optional api_key that reads NOZLE_SECRET_KEY, request_id and retry_after on NozleAPIError, usage capture for any httpx-based LLM client, Core usage reads, and the invoices, alerts and webhooks namespaces. Version 0.12.0 adds billing_configuration to customers.upsert(). Version 0.11.0 sends Feature Events through the Go Engine endpoint. Version 0.10.0 adds NozleAPIError.code and has_code(), richer checkout result types, and no longer requires feature in check_and_deduct(). Version 0.9.1 fixes Feature Event timestamp serialization, including events created by the OpenAI and Anthropic wrappers. Version 0.9.0 introduced subscription options, signed quotes, pending-change withdrawal, and scoped checkout recovery. See subscription self-service and the release notes.

Create a client

The client defaults to the public service bases under https://api.nozle.app. For a local or self-hosted deployment behind one proxy, set host. Set base_url or events_url only when the two services live at unrelated addresses; each one you set wins over host. If you set only one of them, the other service still uses host (by default production), so set host too. Trailing slashes are removed automatically.

Manage the HTTP session

Nozle is synchronous and owns a reusable requests.Session. Use it as a context manager when its lifetime is scoped:
For an application-wide singleton, call nozle.close() during shutdown.

Async client

Version 0.13.0 adds AsyncNozle for asyncio applications such as FastAPI, so SDK calls do not block the event loop. It takes the same arguments as Nozle and has the same namespaces and methods; every method that calls the API is awaited. It sends requests with httpx.AsyncClient, so install the httpx extra:
  • Validation, NozleAPIError (with request_id and retry_after), retries and idempotency keys behave exactly as in Nozle. Retries wait with asyncio.sleep.
  • For an application-wide client, call await nozle.aclose() during shutdown.
  • events.create_transaction_id() and cost_events.create_cost_event_id() make no request and are not awaited.
  • await nozle.webhooks.verify(body, headers) is awaited, because a jwt endpoint reads Nozle’s public key once.
  • For LLM auto-capture, use nozle.capture_async_http_client(...) or wrap an httpx.AsyncClient. AsyncNozle does not wrap a synchronous httpx.Client; use Nozle there.

Authentication model

  • plans() accepts either a publishable pk_ or secret sk_ key.
  • Every customer, event, checkout, subscription, credit, Entity, usage, entitlement, health, and margin operation requires sk_.
  • Wrong key types fail locally with NozleAuthenticationError before network I/O.
This is a backend SDK. Never expose an sk_, master key, or internal credential to browser or mobile code.

API surface

Usage reads, invoices, alerts, webhooks, wrap_http_client(), capture_http_client(), capture_async_http_client() and record_usage() require 0.13.0. check_and_deduct(customer_id, credits=5) remains available for the legacy wallet path. The feature argument is deprecated and ignored.

Transport behavior

  • Retries are off by default (max_retries=0), so a mutation executes at most once per SDK call.
  • With max_retries set, reads are retried, and a write is retried only when it is idempotent or carries an idempotency key.
  • Connection and timeout failures raise NozleTransportError.
  • Non-2xx responses raise structured NozleAPIError.
  • Sensitive values in API error payloads are redacted.
See Errors and retries for handling guidance.

Next steps