← Back to Home

Protect a private read and reply

Give a support agent access to the signed-in customer's record, then authorize the exact answer before sending it. You get two separately signed decisions: one for the read and one for the reply, linked to the first. The customer data and reply text stay in your application.

Enable it for one agent

  1. Create your account, then sign in using the link sent to the account owner's mailbox. In the dashboard, get your tenant ID and a tenant API key. Keep the key in your backend.
  2. Connect an agent in Setup. To register a fresh example agent directly, send POST /api/haltstate/agents with headers X-Tenant-Id, X-API-Key and Content-Type: application/json, and body {"agent_id":"private-help","name":"Private support"}. Register it once.
  3. Open Setup → Private account read and reply, select the registered agent, then Enable for this agent. Copy the credential into your backend secret manager as HALTSTATE_PRIVATE_FLOW_TOKEN. The next visit shows its status, not the secret. If you lose the credential, use Replace credential, then update your backend.

The tenant key is for managing your agents. The new, agent-specific credential is for read and reply decisions. Keep it out of browser code, chat prompts and logs.

HTTP equivalent for a fresh trial: From a trusted client, POST JSON to /api/haltstate/signup with your own company_name, email, plan:"starter", and trial:true. Keep the response's tenant_id and api_key privately. To verify your owner session, POST your email to /api/haltstate/auth/magic-link and follow the link in your own mailbox; the public verification endpoint is GET /api/haltstate/auth/verify?token=<token-from-link>. Preserve the secure haltstate_access_token cookie from that sign-in. Register the agent as in step 2.

With that owner's cookie, GET /api/haltstate/private-flow/agents/private-help/setup returns current status. To enable it, POST {} as JSON to the same URL with the same cookie and the exact origin of the dashboard in the Origin header (normally https://haltstate.ai). Copy the first response's credential into your server; subsequent status reads and enable retries do not disclose it. Use a separate backend client, without the owner cookie or browser headers, for both decision requests below.

Connect your read and send boundaries

Your backend supplies two independent facts: the account from the authenticated session, and the account that owns the requested record, from trusted resource metadata. Use opaque identifiers; do not take either fact from the model, an email address it guessed, or a form field. Verify the user's current role and access before each step. Keep the actual private record behind the read check.

Allocate and persist two different operation IDs per business request, one for each phase; reuse those IDs on retries. Buffer the final reply before asking to release it. In Python:

import os
from datetime import datetime, timezone
from haltstate import PrivateFlowClient

client = PrivateFlowClient(agent_token=os.environ["HALTSTATE_PRIVATE_FLOW_TOKEN"],
                           base_url="https://haltstate.ai")

def fresh(grant):
    return (grant.decision == "ALLOW" and grant.may_proceed
            and datetime.now(timezone.utc) < datetime.fromisoformat(
                grant.receipt["expires_at"].replace("Z", "+00:00")))

def answer(job, app):
    # job holds two UUID strings persisted when this request was first received.
    # app supplies your normal auth, resource lookup, evidence store and transport.
    scope = app.authorized_resource_scope(job)  # subject_account, resource_account, resource_id
    read = client.authorize_read(operation_id=job.read_id, **scope)
    app.save_receipt(read.receipt)
    if not fresh(read):
        return
    # The datastore enforces owner + resource together at read time.
    record = app.read_private_record(owner=scope["subject_account"], resource=scope["resource_id"])
    body = app.prepare_answer(record).encode("utf-8")
    scope_now = app.authorized_resource_scope(job)  # recheck the session and owner
    reply = client.authorize_reply(operation_id=job.reply_id, **scope_now,
                                   read_receipt_id=read.receipt_id, reply_bytes=body)
    app.save_receipt(reply.receipt)
    if app.authorized_resource_scope(job) == scope_now and fresh(reply):
        app.send_bytes_to_authenticated_customer(body, account=scope_now["subject_account"],
                                                 idempotency_key=job.reply_id)

Use the same frozen bytes and the same destination associated with the authenticated request. Send promptly within the receipt's expiry. On timeout, error, denial or missing authority, stop. A repeated decision can return the original signed ALLOW for inspection with may_proceed: false; it does not authorize another read or send. If delivery is uncertain, look up the original delivery with your provider instead of starting a new operation. The signed reply is permission to send, not a delivery confirmation.

Read grants last up to 60 seconds; a reply cannot outlive its parent read. If the customer session changes, discard the prepared answer. Owner-enabled actions are named private.read and private.reply in governance; account, agent and applicable policy blocks still take precedence. Use opaque ASCII identifiers of up to 128 characters (letters, numbers, periods, underscores, colons or hyphens, beginning with a letter or number).

An HTTP 429 does not authorize a read or send. Check the response's detail:

If your SDK only reports the status, wait a minute rather than retrying immediately. If a retry is still appropriate, use the same operation ID and exact request body. For a reply, the original read grant must still be valid; waiting does not extend it. Act only on a fresh ALLOW with may_proceed: true. A replay never authorizes another read or send.

SDK Dedicated server client Read / reply
Python PrivateFlowClient or AsyncPrivateFlowClient authorize_read / authorize_reply
TypeScript / JavaScript new PrivateFlowClient({agentToken, baseUrl}) authorizeRead / authorizeReply; pass a buffered Uint8Array
Go haltstate.NewPrivateFlowClient(baseURL, credential) Read / Reply; pass a []byte
Java new PrivateFlowClient(baseUrl, credential) read / reply; pass a byte[]
Rust PrivateFlowClient::new(base_url, credential) read / reply; pass the bytes of the prepared reply

Try the public API with two synthetic accounts

This recipe uses HTTPS and JSON directly, so no particular SDK version is required. Start with a new agent, fixture accounts acct-a and acct-b, and a synthetic record record-1 owned by acct-a. Your application sends the following to the HaltState origin using Authorization: Bearer <private-flow credential> and Content-Type: application/json.

  1. Read: POST /api/haltstate/private-flow/read with {"operation_id":"d654cba1-bd2a-486a-83e9-877f80a8f959","subject_account":"acct-a","resource_account":"acct-a","resource_id":"record-1"}. On a fresh ALLOW with may_proceed:true, read the fixture. Save the response's receipt object as read.json; keep its receipt_id.
  2. Reply: Prepare the exact UTF-8 bytes you intend to send, compute their lowercase SHA-256 hex digest, and call POST /api/haltstate/private-flow/reply. Send the same three account/resource fields, a new UUID in operation_id, plus read_receipt_id and reply_sha256. Save the receipt object as reply.json. On a fresh ALLOW with may_proceed:true, increment a local test send counter. No customer message is needed.
  3. Retry: Repeat that exact reply request. Expect the same receipt ID, may_proceed:false, and a send counter of one. A different operation ID must not release another reply from the same read, either.
  4. Cross-account: Repeat the read with a new operation ID and authenticated account acct-b, leaving the record's actual owner as acct-a. Expect DENY and may_proceed:false. The second customer's private record reader must never run.

Verify both receipts offline

Download the offline verifier and the Sydney public key from the trusted HaltState site. No private key or account token is required. Save only the signed receipt object from each response. In an isolated test environment, use that environment's independently supplied public key and fingerprint.

python -m pip install cryptography
python verify-private-flow-v1.py sydney-ed25519-public.pem 22c0e4d547f721418801535a24c60a8ce2208707ace41ae243c6866e2fc702fc read.json reply.json

The verifier checks both Ed25519 signatures, both content digests, the shared tenant/agent/resource binding, and the reply's reference to the exact signed read. Add --reply-bytes prepared-reply.bin to check the content you prepared. Run it with just the read receipt to verify a signed denial. A signature remains useful for investigation after authority to act expires.

For an independent implementation, verify the Ed25519 signature over the ASCII prefix HALTSTATE-EVIDENCE-EXPORT-MANIFEST-v1, a single zero byte, and the canonical UTF-8 JSON of signature.manifest. Canonical JSON uses sorted object keys, no whitespace separators and literal Unicode. The manifest commits to the SHA-256 of the canonical receipt minus its top-level signature and integrity fields. Match the independently pinned SHA-256 of the raw 32-byte Ed25519 key, not of the PEM file. The linked reply carries both the read receipt ID and its signed payload digest.