Skip to main content

Official Python SDK for the Lenz Claim Verification API for AI Product Teams

Project description

lenz-io

Official Python SDK for the Lenz Claim Verification API for AI Product Teams.

Two API primitives for AI product teams. extract pulls verifiable claims out of any text — free, 1000 calls/key/day. verify checks one with a 7-model panel and citations, ~90s. Use them together or alone.

Built for teams whose AI output is async or document-shaped: legal-memo generators, deep-research products, due-diligence platforms, vertical agents producing structured deliverables. Not chat AI, not voice AI, not real-time copilots — pipeline runs are the wrong shape for those.

pip install lenz-io

Quickstart — the canonical integration

from lenz_io import Lenz

client = Lenz(api_key="lenz_...")

# 1. Pull factual claims out of your model output (free, instant)
claims = client.extract(text=llm_output).claims

# 2. Verify the ones that matter (~90s each, 7-model panel)
for claim in claims:
    v = client.verify_and_wait(claim=claim).verdict
    print(v.label, v.score, v.confidence)

How verification works

Frame → Collect Evidence → Debate (2 models, 2 rounds) → Adjudicate (3 models: sources, logic, context) → Conclude. ~90 seconds wall-clock per claim.

Magical-moment demo

from lenz_io import Lenz

client = Lenz(api_key="lenz_...")

v = client.verify_and_wait(claim="Sharks don't get cancer")
print(v.verdict.label, v.verdict.score)
# false 2.0

for source in v.sources[:3]:
    print(" -", source.title, source.url)

The demo claim is pre-cached so this returns in ~1.5s. Your own claims hit the full pipeline (~60-90s) — use webhooks for production async flows.

Get your webhook secret here → lenz.io/api-integration

What you get

  • client.verify_and_wait(...) — submit + poll until the pipeline lands. Returns a typed Verification.
  • client.verify(...) — async submit; returns a task_id. Use webhooks for the callback.
  • client.extract(text=...) — pull verifiable claims out of any text (free, capped at 1000/key/day).
  • client.verify_batch(claims=[...]) — fan-out for multi-claim LLM outputs.
  • client.verifications.{list,get,delete,set_visibility}(...) — manage past verifications.
  • client.followup.{history,send,reset}(verification_id) — Q&A on a verification.
  • client.library.{list,get}(...) — browse the public catalog (no API key needed).
  • client.usage() — credits and rate-limit remaining.

Webhooks

from lenz_io import LenzWebhooks, VerificationCompleted, VerificationNeedsInput

webhooks = LenzWebhooks(secret="whsec_...")

# In your web handler:
event = webhooks.parse(raw_body=request.body, headers=request.headers)
if isinstance(event, VerificationCompleted):
    vid, result = event.verification_id, event.result
    ...
elif isinstance(event, VerificationNeedsInput):
    tid, ni = event.task_id, event.needs_input
    ...

If you're on Python 3.10+ a match statement reads even cleaner — events are plain dataclasses, so structural pattern matching works.

Signature verification is HMAC-SHA256 over the raw body; the SDK does it for you and rejects tampered or replayed payloads.

See examples/core/fastapi_webhook.py for a runnable FastAPI receiver, and examples/core/verify_llm_output.py for the headline extract-and-verify integration pattern.

Errors

Every error subclass is typed and carries a request_id you can quote on support tickets:

from lenz_io import LenzAuthError, LenzRateLimitError, LenzValidationError

try:
    client.verify_and_wait(claim="...")
except LenzAuthError as exc:
    print(exc)
    # Unauthorized
    #   Cause:  Invalid api key
    #   Fix:    Generate a new key at https://lenz.io/api-integration.
    #   Docs:   https://lenz.io/docs/auth
    #   Request ID: req_abc123
except LenzRateLimitError as exc:
    time.sleep(exc.retry_after)
except LenzValidationError as exc:
    for field_err in exc.errors:
        print(field_err["loc"], field_err["msg"])

Resuming a verification

If a verify_and_wait call exceeds its timeout (default 120s) or your process dies mid-poll, the pipeline keeps running. The exception carries the task_id:

from lenz_io import LenzTimeoutError

try:
    client.verify_and_wait(claim="...", timeout=30)
except LenzTimeoutError as exc:
    print("resume later via:", exc.task_id)

# Later (different process / restart):
status = client.get_status("tsk_abc123")
if status.status == "completed":
    print(status.result.verdict.label)

Idempotency

verify_and_wait sends an auto-generated Idempotency-Key on every call by default, so a network drop after submit doesn't spawn a duplicate verification or charge a second credit. Override with idempotency_key="..." to pin a specific key, or idempotency=False to opt out.

Configuration

Lenz(
    api_key="lenz_...",                  # or set LENZ_API_KEY env var
    base_url="https://lenz.io/api/v1",   # override for staging / local
    timeout=30.0,
    max_retries=3,
)

Environment variables:

  • LENZ_API_KEY — read if api_key= is not passed
  • LENZ_BASE_URL — read if base_url= is not passed

Compatibility

  • Python 3.9, 3.10, 3.11, 3.12
  • Works in CI/CD (no interactive prompts, no global state)
  • Mockable for tests: every HTTP call goes through httpx; use respx or inject your own httpx.Client via Lenz(..., http_client=...)

Bug reports + feature requests

github.com/lenzhq/lenz-io-python/issues

For commercial use, volume pricing, or onboarding support, get in touch.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lenz_io-1.0.0rc1.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lenz_io-1.0.0rc1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file lenz_io-1.0.0rc1.tar.gz.

File metadata

  • Download URL: lenz_io-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lenz_io-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 715d3a28bacdcd7862dd3034c96470d82f12c2db2feeffe413a684f1b6a20771
MD5 7346df5395ff672e6bf7da1c8ce9eaea
BLAKE2b-256 57c3e415de6acc7d052faad366c459c9e06686eb1ae7de53ad2f8a94b2afefb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for lenz_io-1.0.0rc1.tar.gz:

Publisher: release.yml on lenzhq/lenz-io-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lenz_io-1.0.0rc1-py3-none-any.whl.

File metadata

  • Download URL: lenz_io-1.0.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lenz_io-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 d2d416722ac1422f607b4fb832b3464d1c56effb74f278893f8449faa6518208
MD5 e861dfc84fdc413bd1821149023d50ad
BLAKE2b-256 6e72469d47b1d839f6ee61495f3b956dd153e753fcd97797e02a5be82cd984a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lenz_io-1.0.0rc1-py3-none-any.whl:

Publisher: release.yml on lenzhq/lenz-io-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page