Skip to main content

lyzr-rag-client

Typed sync/async Python client for the Lyzr RAG /v1 API. Use it from PepGenX (Okta bearer + API key + tenant headers, or key-only) and from Lyzr-hosted deployments (x-api-key). Built on httpx and pydantic.

PyPI CI

Install

pip install lyzr-rag-client
# or
uv add lyzr-rag-client

Requires Python 3.10+. Runtime dependencies: httpx and pydantic only.

PepGenX quick start

Composite posture: Okta client-credentials token plus the five house-style headers.

import os

from lyzr_rag_client import ClientCredentials, ModelSpec, RagClient, SourceInput, VectorStoreSpec

tokens = ClientCredentials(
    issuer=os.environ["LYZR_OAUTH_ISSUER"],
    client_id=os.environ["LYZR_OAUTH_CLIENT_ID"],
    client_secret=os.environ["LYZR_OAUTH_CLIENT_SECRET"],
    scope=os.environ.get("LYZR_OAUTH_SCOPE"),
)

client = RagClient.for_pepgenx(
    os.environ["LYZR_RAG_BASE_URL"],  # APIM base + RAG route from onboarding
    api_key=os.environ["PEPGENX_API_KEY"],
    team_id=os.environ["PEPGENX_TEAM_ID"],
    project_id=os.environ["PEPGENX_PROJECT_ID"],
    user_id=os.environ["PEPGENX_USER_ID"],
    token_provider=tokens,
)

me = client.auth.whoami()
print(me.subject, me.org_id, me.roles)

kb = client.knowledge_bases.create(
    "demo",
    vector_store=VectorStoreSpec(provider="qdrant", credential_id="qdrant-prod"),
    # Or: VectorStoreSpec(provider="astra", credential_id="astra-prod")
    embedding=ModelSpec(model="text-embedding-3-small"),
)

job = client.documents.ingest(
    kb.id,
    [SourceInput(kind="text", text="PepsiCo Q3 margin notes…", title="notes")],
)
client.jobs.wait(job.id)

hits = client.query.retrieve(kb.id, "What changed in Q3?")
answer = client.query.answer(kb.id, "What changed in Q3?")
print(answer.answer, len(hits.results))

Key-only (no Okta)

When the deployment runs without bearer auth, omit token and tenant headers:

client = RagClient.for_pepgenx(
    os.environ["LYZR_RAG_BASE_URL"],
    api_key=os.environ["PEPGENX_API_KEY"],
    team_id=None,
    project_id=None,
)

Only x-pepgenx-apikey is sent. See docs/AUTH.md and docs/PEPGENX.md.

Lyzr-hosted quick start

import os

from lyzr_rag_client import RagClient

client = RagClient.for_lyzr(
    base_url=os.environ["LYZR_RAG_BASE_URL"],
    api_key=os.environ["LYZR_API_KEY"],
)

base_url is always explicit or taken from LYZR_RAG_BASE_URL. There is deliberately no built-in default hostname.

Environment variables

Variable Purpose
LYZR_RAG_BASE_URL Service base URL (required unless base_url= is passed)
LYZR_RAG_TOKEN Bearer token for plain BearerAuth resolution
LYZR_API_KEY Lyzr-hosted x-api-key
PEPGENX_API_KEY PepGenX API key (x-pepgenx-apikey by default)
PEPGENX_TEAM_ID Tenant team_id header
PEPGENX_PROJECT_ID Tenant project_id header
PEPGENX_USER_ID Attribution user_id / GPID header
PEPGENX_API_KEY_HEADER Override API-key header name (default x-pepgenx-apikey)
LYZR_OAUTH_TOKEN_URL / LYZR_OAUTH_ISSUER Token endpoint, or Okta issuer (issuer → {issuer}/v1/token)
LYZR_OAUTH_CLIENT_ID OAuth client id
LYZR_OAUTH_CLIENT_SECRET OAuth client secret
LYZR_OAUTH_SCOPE Optional space-delimited scopes
LYZR_OAUTH_AUDIENCE Optional audience claim for the token request

When constructing RagClient(base_url=None, auth=None), auth auto-resolves in this order: PEPGENX_* → LYZR_API_KEY → LYZR_RAG_TOKEN.

Async

from lyzr_rag_client import AsyncRagClient

async with AsyncRagClient.for_lyzr(base_url=..., api_key=...) as client:
    me = await client.auth.whoami()

AsyncRagClient mirrors RagClient; call await client.aclose() if you are not using the context manager.

Streaming answers

from lyzr_rag_client import CitationsEvent, DeltaEvent, DoneEvent, ErrorEvent

for event in client.query.stream(kb_id, "Summarize the margin notes"):
    match event:
        case CitationsEvent(citations=cites):
            ...
        case DeltaEvent(text=chunk):
            print(chunk, end="", flush=True)
        case DoneEvent(answer=final):
            print("\n", final)
        case ErrorEvent(code=code, detail=detail):
            raise RuntimeError(f"{code}: {detail}")

Jobs and uploads

  • documents.ingest(...) and documents.upload(...) return 202 + a JobOut.
  • An Idempotency-Key is generated automatically (pass idempotency_key= to reuse one).
  • Poll with client.jobs.wait(job.id) (default 1 s interval, 600 s timeout).
  • Multipart upload: client.documents.upload(kb.id, files=["./report.pdf"]).

Retries and timeouts

Defaults: 60 s total timeout, 5 s connect; 3 attempts with exponential backoff 1 s → 30 s (jitter); Retry-After is honoured when present.

Which requests retry (idempotent methods, bodies with an Idempotency-Key, transport connect failures, 429/503, and 502-504 on idempotent calls) is documented in docs/ERRORS.md.

Error handling

from lyzr_rag_client import NotFoundError

try:
    client.knowledge_bases.get(kb_id)
except NotFoundError as e:
    print(e.code, e.request_id, e.detail)

See docs/ERRORS.md for the full hierarchy and .code vocabulary.

Transaction ids

Pass transaction_id= on any resource call. The SDK sends it as the transaction_id header; the service echoes the correlation id in X-Request-Id (available as APIError.request_id).

Security

  • Auth credentials are wrapped in Secret; minted/imported API-key material is redacted in model/RequestSpec repr/str. Neither appears in logs.
  • TLS verification is on by default (verify=True).
  • Corporate CA: RagClient(..., verify="/path/to/ca.pem").
  • HTTP proxies follow httpx trust_env (standard HTTP_PROXY / HTTPS_PROXY / NO_PROXY).

Compatibility

SDK 0.1.x targets Lyzr RAG API v1 as frozen in spec/SOURCE (OpenAPI pin: spec/openapi.json).

Development

Target Purpose
make sync uv sync --locked
make lint / make fmt Ruff check / format
make type mypy --strict
make test pytest with ≥90% coverage
make test-e2e Live e2e (-m e2e)
make security bandit + pip-audit
make build Wheel/sdist + twine check
make gen-models Regenerate models (scripts/gen_models.sh)
make sync-core Vendor _core into the sibling memory client
make all lint + type + test + security + build

License

MIT. See LICENSE.

Metadata

Release files for lyzr-rag-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lyzr-rag-client 0.1.0
File Size Uploaded
lyzr_rag_client-0.1.0.tar.gz 104.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lyzr-rag-client 0.1.0
File Interpreter ABI Platform
lyzr_rag_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 163.8 kB

Release files / lyzr_rag_client-0.1.0.tar.gz

Download URL lyzr_rag_client-0.1.0.tar.gz
Size 104.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1e8226220a9de335259922b68f23762b66cc55d16e53c5079d08521e0f7e168e
BLAKE2b-256 checksum
How to use checksums
701c0368a102efc942f559fc9aa698ec5260d4fc1a067a073e18d3715bf82572
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / lyzr_rag_client-0.1.0-py3-none-any.whl

Download URL lyzr_rag_client-0.1.0-py3-none-any.whl
Size 59.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
279d32a6343f865a3ec8f1e8ed96dfa6126bbe269a46a6d0add6efa179c79f0d
BLAKE2b-256 checksum
How to use checksums
bad4b9e4246407733e4640a2f952dc0bb1083758f5998c3b8ebb1e1a7c495a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page