Skip to main content

Genesis Python API Client

Publisher-side client for requesting offers, recording optional signals, and tracking impressions or clicks.

from genesis import GenesisClient, GenesisConfig, OfferRequest, hash_identifier

client = GenesisClient(
    GenesisConfig(
        api_key="gn_test_...",
        mode="test",
        tracking_proxy_base_url="https://app.example.com/genesis-track",
    )
)

response = client.request_offers(
    OfferRequest(
        placement_id="chat_recommendation_after_answer",
        app_id="app_docs_quickstart",
        user_id_hash=hash_identifier("internal-user-id"),
        message="I need a SOC 2 monitoring tool for a seed-stage SaaS company.",
        categories=["security_compliance", "developer_tools"],
        conversation_context=[
            {"role": "user", "content": "Compare SOC 2 monitoring tools."}
        ],
        locale="en-US",
        country="US",
        workflow_state="post_answer",
        device={"type": "server"},
        max_offers=2,
        allowed_categories=["developer_tools", "security_compliance"],
        blocked_categories=["finance_operations"],
        allowed_advertiser_ids=["adv_example"],
        blocked_advertiser_ids=["adv_blocked"],
        allow_formats=["action_card", "lead_form"],
        disable_tracking=False,
        allow_restricted_categories=False,
        require_disclosure=True,
        signals=[
            {
                "type": "recommendation_request",
                "confidence": 0.84,
                "subject": "SOC 2 monitoring",
                "related_subjects": ["evidence automation"],
                "value": "security_compliance",
                "placement_id": "chat_recommendation_after_answer",
                "purpose": "offer_request_context",
            }
        ],
        metadata={"integration": "readme"},
    )
)

Request several placements with shared context:

batch = client.request_offers_batch(
    {
        "placements": [
            {
                "placement_id": "chat_inline_offer",
                "app_id": "app_docs_quickstart",
                "agent_type": "conversational_assistant",
                "surface": "chat",
            },
            {
                "placement_id": "chat_sidebar_offer",
                "app_id": "app_docs_quickstart",
                "agent_type": "conversational_assistant",
                "surface": "chat",
            },
        ],
        "message": "Compare SOC 2 monitoring tools.",
        "categories": ["security_compliance", "developer_tools"],
        "max_offers": 1,
    }
)

Network failures return a safe no-fill response by default so publisher applications can continue without blocking the user experience. Transient HTTP failures are retried according to GenesisConfig.retries. Request fields are normalized to the public /v1/offers schema, and fields outside that schema are omitted. Offer responses expose hosted tracking URLs, variant, experimentId, compositionId, rendererKey, noFill, latencyMs, and timeout diagnostics when the API returns them.

Release a reservation only if the offer was not rendered:

result = client.release_reservation(response["offers"][0], idempotency_key="release-for-my-request")

The offer needs its placement token and request ID. Retries reuse the same key; the optional explicit key also lets a caller reuse it across separate attempts. Failures and rendered-offer conflicts raise rather than reporting a false release.

Prompt weaving supports none, separate_section, inline_when_relevant, offers_only, and always_disclose:

from genesis import get_referenced_offer_tracking_urls, weave_offers_into_prompt

woven = weave_offers_into_prompt(response["offers"], mode="separate_section")
if woven["has_offers"]:
    prompt = woven["text"]
    impression_urls = get_referenced_offer_tracking_urls(rendered_text, woven["offers"])

Select inline_when_relevant only after confirming relevance. Sponsored text always carries disclosure, and returned references preserve hosted click and impression URLs. Fire an impression only after the end user sees a rendered response that actually references the offer.

Set tracking_proxy_base_url only when your publisher app forwards Genesis hosted tracking through a first-party route. The client rewrites Genesis /v1/track/... impression and click URLs while leaving the reviewed advertiser destination URL unchanged.

Metadata

Release files for thegenesis-api-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 thegenesis-api-client 0.1.0
File Size Uploaded Provenance Actions
thegenesis_api_client-0.1.0.tar.gz 20.9 kB Without provenance Details for thegenesis_api_client-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for thegenesis-api-client 0.1.0
File Interpreter ABI Platform Actions
thegenesis_api_client-0.1.0-py3-none-any.whl Python 3 none any Details for thegenesis_api_client-0.1.0-py3-none-any.whl

Total release size: 35.6 kB

Release files / thegenesis_api_client-0.1.0.tar.gz

Download URL thegenesis_api_client-0.1.0.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
50ad1dfebf360ffe6fc17db64f4c031010deabe39bcdcf385fa49b7f30433f15
BLAKE2b-256 checksum
How to use checksums
aa71ebb2fa3921f5035d38fcfe51a7c36622b8ef0cabf48975ebc0fff01f2823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

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

Download URL thegenesis_api_client-0.1.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ad4332c60df91dc72df20ab9e2df18ab5874f047587da01e4ee8a065fd8bdaf
BLAKE2b-256 checksum
How to use checksums
1b6fe2e8999ae9f1648354cccbe27941325c88ec0a3228cbf1a4751006b828ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for thegenesis-api-client 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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