SpendGuard SDK — runtime safety layer client for AI agent frameworks (Pydantic-AI, LangChain, LangGraph, OpenAI Agents SDK). SLICE_12: default token estimators + with_run_plan decorator (Signal 3).
Project description
spendguard-sdk
Python SDK for Agentic SpendGuard — the audit-chain spend control layer for LLM agents. Talks to the Agentic SpendGuard sidecar over Unix-domain-socket gRPC; gates each LLM / tool-call boundary through a Contract DSL evaluator and an atomic budget ledger with KMS-signed, immutable audit chain.
Install
# Core only (raw client, no framework integration)
pip install spendguard-sdk
# With the integration you need
# Pydantic-AI auto-install is temporarily fail-closed because
# CVE-2026-25580 affects pydantic-ai/pydantic-ai-slim before 1.56.0,
# and PyPI does not currently expose a fixed 1.56.0+ release.
# Install spendguard-sdk plus a vetted non-vulnerable pydantic-ai
# release when upstream publishes one.
pip install 'spendguard-sdk[langchain]'
pip install 'spendguard-sdk[langgraph]'
pip install 'spendguard-sdk[openai-agents]'
Quickstart (Pydantic-AI)
import asyncio
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
from spendguard import SpendGuardClient, new_uuid7
from spendguard.integrations.pydantic_ai import (
RunContext,
SpendGuardModel,
run_context,
)
from spendguard._proto.spendguard.common.v1 import common_pb2
async def main():
client = SpendGuardClient(
socket_path="/var/run/spendguard/adapter.sock",
tenant_id="00000000-0000-4000-8000-000000000001",
)
await client.connect()
await client.handshake()
guarded = SpendGuardModel(
inner=OpenAIModel("gpt-4o-mini"),
client=client,
budget_id="44444444-4444-4444-8444-444444444444",
window_instance_id="55555555-5555-4555-8555-555555555555",
unit=common_pb2.UnitRef(
unit_id="66666666-6666-4666-8666-666666666666",
token_kind="output_token",
model_family="gpt-4",
),
pricing=common_pb2.PricingFreeze(
pricing_version="demo-pricing-v1",
price_snapshot_hash=b"<32 bytes>",
fx_rate_version="demo-fx-v1",
unit_conversion_version="demo-units-v1",
),
claim_estimator=lambda messages, settings: [
common_pb2.BudgetClaim(
budget_id="44444444-4444-4444-8444-444444444444",
unit=common_pb2.UnitRef(
unit_id="66666666-6666-4666-8666-666666666666",
token_kind="output_token",
model_family="gpt-4",
),
amount_atomic="500",
direction=common_pb2.BudgetClaim.DEBIT,
window_instance_id="55555555-5555-4555-8555-555555555555",
)
],
)
agent = Agent(model=guarded)
async with run_context(RunContext(run_id=str(new_uuid7()))):
result = await agent.run("Say hello in three words.")
print(result.output)
asyncio.run(main())
If a contract rule denies the call, agent.run(...) raises
spendguard.DecisionStopped carrying reason_codes and
matched_rule_ids.
API surface (core)
| Symbol | Purpose |
|---|---|
SpendGuardClient |
UDS gRPC client to the sidecar |
DecisionStopped, DecisionSkipped, ApprovalRequired |
per-decision exceptions |
derive_idempotency_key(...) |
deterministic key from (tenant, run, step, llm_call, trigger) |
new_uuid7() |
UUID v7 helper |
Wire-protocol compatibility
This SDK pins to a specific protobuf wire version. Check the
sidecar's published version against spendguard.__version__; minor
versions are wire-compatible, major bumps are breaking. (Not yet
enforced at handshake; planned for v0.2.)
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spendguard_sdk-0.5.1.tar.gz.
File metadata
- Download URL: spendguard_sdk-0.5.1.tar.gz
- Upload date:
- Size: 5.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd5c97483011d752d724d7540c51097d3ccb074cd6fcbbc18be66a0382edc014
|
|
| MD5 |
f947b72fa0d7624b5aef01ce60906a7a
|
|
| BLAKE2b-256 |
3b2705d2b261cc1f9b843777b21c5cea987d7416b4bc523c9529690d88161397
|
Provenance
The following attestation bundles were made for spendguard_sdk-0.5.1.tar.gz:
Publisher:
sdk-publish.yml on m24927605/agentic-spendguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spendguard_sdk-0.5.1.tar.gz -
Subject digest:
cd5c97483011d752d724d7540c51097d3ccb074cd6fcbbc18be66a0382edc014 - Sigstore transparency entry: 1703886228
- Sigstore integration time:
-
Permalink:
m24927605/agentic-spendguard@df9e76c9a0e1da9d17ae224322c8486d8f106be6 -
Branch / Tag:
refs/tags/sdk-v0.5.1 - Owner: https://github.com/m24927605
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@df9e76c9a0e1da9d17ae224322c8486d8f106be6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spendguard_sdk-0.5.1-py3-none-any.whl.
File metadata
- Download URL: spendguard_sdk-0.5.1-py3-none-any.whl
- Upload date:
- Size: 5.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
576d6186aa57e6d9fbd93b7c8b6a2f7f8845dd3d573fc00773362d3df10500c6
|
|
| MD5 |
2aebfb1201b00b4572f558be02e9297b
|
|
| BLAKE2b-256 |
b497b0715fb3588d2c62dadfe96fc0e57b40ab7a9f42febbfc0f2c11eca05442
|
Provenance
The following attestation bundles were made for spendguard_sdk-0.5.1-py3-none-any.whl:
Publisher:
sdk-publish.yml on m24927605/agentic-spendguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spendguard_sdk-0.5.1-py3-none-any.whl -
Subject digest:
576d6186aa57e6d9fbd93b7c8b6a2f7f8845dd3d573fc00773362d3df10500c6 - Sigstore transparency entry: 1703886237
- Sigstore integration time:
-
Permalink:
m24927605/agentic-spendguard@df9e76c9a0e1da9d17ae224322c8486d8f106be6 -
Branch / Tag:
refs/tags/sdk-v0.5.1 - Owner: https://github.com/m24927605
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@df9e76c9a0e1da9d17ae224322c8486d8f106be6 -
Trigger Event:
release
-
Statement type: