Skip to main content

Clone Python SDK

Server-side synchronous and asynchronous clients for Clone predictions, usage, observation events, cancellation and optional user-approved Clone connections. Composer UI stays in the JavaScript SDK. This client never submits a user message.

Python 3.11+. Install clone-sdk from PyPI; import clone_sdk.

python -m pip install clone-sdk==0.2.1
import os
from clone_sdk import CloneClient

with CloneClient(os.environ["CLONE_APP_KEY"]) as client:
    result = client.predict(
        "subject-from-your-authenticated-session",
        {
            "request_id": "prediction-001",
            "session_id": "conversation-001",
            "context_revision": "1",
            "mode": "next_prompt",
            "draft": {"text": "", "revision": 0},
            "messages": [{"role": "user", "content": "Draft a product announcement.", "origin": "human"}],
            "language": "en",
        },
    )
    print(result.status)

For FastAPI or other async servers, use async with AsyncCloneClient(...) and await client.predict(...). Reuse a client for the application's lifetime and close it during shutdown. The async client enforces a total 15-second deadline, including body reads. The sync client uses 15-second per-I/O timeouts and checks the elapsed budget between response chunks. Both bound concurrency to 16 by default, reject saturation without queuing, limit response bodies to 1 MiB, and never automatically retry potentially billable work. Override timeout up to 30 seconds and max_concurrent_requests up to 1,000 after measuring your load.

Derive user_id from your server session; the client overwrites an untrusted body's user_id. Keep the app key exclusively on your backend. HTTPS is required except loopback development. Redirects are not followed. Client errors expose only a safe code, HTTP status and numeric retry_after, never response text.

Keep the same request ID and exact body when reconciling an unknown result. Hide failed predictions and keep your editor and manual send path independent. Response identity is checked; the host still owns expiry, rendering, Tab/Undo, session changes and successful-send acknowledgments.

Optional personalization uses started, flow = client.connect(user_id, redirect_uri) to create a PKCE flow (or started, flow = await client.connect(...) for async). Store the returned flow in a server session, redirect the user to started.authorize_url, then call exchange(flow, callback, authenticated_user_id). State, request and subject must match. The flow contains a secret verifier and must not be logged or serialized to browser storage. Basic predictions need no Clone end-user account.

client.record_event(
    subject,
    {
        "event_id": "event-001",
        "request_id": "prediction-001",
        "kind": "presented",
    },
)
usage = client.usage()
client.cancel(subject, "prediction-001")

Only report submitted after your host accepts the send. Reuse an event ID on delivery retries. Behavior receipts and outcomes contain no prompt text and do not change billing. Explicit evaluations can supply a reason; guidance and edited successful submissions require content_opt_in=True before sending text. Feedback memory is encrypted, app/user scoped, and expires after 30 days. Call client.clear_feedback(subject) to clear it. See feedback for event fields and clearing semantics. Read the public API, billing and reliability contracts before production use.

Development: uv sync, uv run pytest, uv run ruff check ., uv build and uv run twine check dist/*. All ordinary tests use local or mocked transports; they do not establish model quality or customer adoption.

Metadata

Release files for clone-sdk 0.2.1

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

Source distribution (sdist)

Source distribution for clone-sdk 0.2.1
File Size Uploaded Provenance
clone_sdk-0.2.1.tar.gz 56.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for clone-sdk 0.2.1
File Interpreter ABI Platform
clone_sdk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 64.6 kB

Release files / clone_sdk-0.2.1.tar.gz

Download URL clone_sdk-0.2.1.tar.gz
Size 56.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7d2e723c6fdb5d5197d7794bf801e39c9d076887e8a42336f41e53a9b7283d8d
BLAKE2b-256 checksum
How to use checksums
1877ec9c4cfab5793e58c6052f6dbfab2f9dd22f5bd6a81998aabf231b3bcceb
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 Oct 4, 2026.

Transparency log

Release files / clone_sdk-0.2.1-py3-none-any.whl

Download URL clone_sdk-0.2.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d69b74656f7cbee46671396a2a8e4a7faa1fed6fbd389220df38abc4a7f47d06
BLAKE2b-256 checksum
How to use checksums
0e4ecf7d0c7172df0ed357011a8be461a027b73ae676c1fdd035161f174aca81
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 Oct 4, 2026.

Transparency log

Security for clone-sdk 0.2.1

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for clone_sdk-0.2.1.tar.gz

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 Oct 4, 2026.

Transparency log

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.

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