caelum0x 894359e5ff feat(railyard): per-app completion pass — money-correct settlement + crate cores
- rago: exactly-once prepaid settlement (deterministic idempotency, unique partial index + in-tx ON CONFLICT guard) — closes the double-charge risk
- mint: double-entry + reserve conservation verified (14 tests)
- ledgerline: atomic settlement outbox + partial recovery index (37 tests)
- abacus: hard per-agent budget enforcement + kill-switch (54 tests)
- vend: crash reaper / in-flight session reconciliation
- turnstile/agent-runtime/ranguard/rit/game-economy/context-passport/rithub: core advanced + tests
2026-09-07 17:17:54 +03:00

1.8 KiB
Raw Permalink Blame History

railyard-relay

Dependency-free Python 3.11+ SDK for Relay’s OpenAI-compatible and native inference surfaces, AITP paid retries, settlement evidence, catalog/quotes, health, and cost-event operations.

from relay_sdk import RelayClient

relay = RelayClient(
    "https://relay.example",
    api_key="...",
    settlement_evidence_verifier=lambda evidence: verify_mint_attestation(
        evidence, pinned_mint_public_key
    ),
)
result = relay.paid_chat_completions(
    {
        "model": "tensorzero::model_name::openai::gpt-4o",
        "messages": [{"role": "user", "content": "Hello"}],
    },
    authorizer=lambda payment: wallet.authorize_aitp(payment),
)

The SDK uses the Python standard library by default and accepts injectable sync or async transports. Paid methods retry exactly once. Dropped streams hand the request UUID to an application-owned recovery queue; asynchronous settlement lookup is deliberately separate from object finalization. settlement_evidence() verifies by default; only verifier-owning recovery code should use settlement_evidence_unverified().

Settlement replay fails closed: RelayAlreadySettledError is emitted only when the configured verifier approves Mint's signed attestation. Missing verification raises RelayUnverifiedSettlementEvidenceError; a bad proof raises RelayInvalidSettlementEvidenceError. Keep pinned Mint keys outside the evidence envelope.

Binary multipart is available on both clients and reuses the exact encoded body after an AITP challenge:

from relay_sdk import MultipartForm

form = MultipartForm().file(
    "file", "requests.jsonl", "application/jsonl", payload_bytes
)
result = relay.paid_multipart("v1/files", form, authorizer)

Run python -m pytest and python -m compileall -q src tests locally.