Python SDK
Reference for the ndstill package: sync and async clients, pay(), approvals, simulate, x402 and Verify for FastAPI.
ndstill is the designed Python client for the v2 API, with a synchronous client, an asyncio client, typed models (Pydantic), the x402 transport for httpx, AI proxy helpers and Verify for FastAPI. Python 3.10 or later.
Install#
pip install ndstillCreate a client#
import os
from ndstill import NdStill, AsyncNdStill
ndstill = NdStill(api_key=os.environ["NDSTILL_API_KEY"])
# or, in async code:
async_client = AsyncNdStill(api_key=os.environ["NDSTILL_API_KEY"])| Argument | Default | Notes |
|---|---|---|
api_key | NDSTILL_API_KEY | Org key, agent-scoped key or test key. |
access_token | none | An OAuth 2.1 token instead of a key. |
base_url | https://api.ndstill.com/v2 | A regional cell or a local mock. |
version | 2026-11-01 | Sent as Ndstill-Version. |
timeout | 30.0 | Seconds per request. |
max_retries | 2 | Network errors, 429, 502, 504; same idempotency key. |
http_client | a new httpx.Client | Bring your own (proxies, mTLS, test transports). |
Pay#
payment = ndstill.pay(
agent="agt_01JD8Q3W6Z",
amount={"amount": 4200, "asset": "USD"}, # $42.00 in cents
counterparty="Delta Air Lines",
purpose="Flight SFO to JFK for the offsite",
)
if payment.status == "held":
# A person approves first. Wait here, or listen for approval.decided.
ndstill.approvals.wait(payment.approval_id, timeout=600)
elif payment.status == "declined":
print([r.message for r in payment.reasons])pay() is payments.create(). It accepts rail_preference, mandate_id, dims ({"customer": …, "task": …}) and idempotency_key=; without one, the SDK generates a key and reuses it on retries.
Resources#
| Method | Endpoint |
|---|---|
payments.create(...) / pay(...) | POST /payment-intents |
payments.get(id), payments.list(**filters) | GET /payment-intents… |
payments.request_refund(id, reason=…) | POST /payment-intents/{id}/refund |
simulate(...) | POST /decisions/simulate |
approvals.get(id), approvals.wait(id, timeout=…) | GET /approvals/{id} |
budgets.check(agent=…, amount=…) | GET /budgets for the agent's scopes |
mandates.create(...), mandates.parse(...) | POST /mandates… |
agents.*, freezes.create(...) | /agents…, POST /freezes |
policies.validate(...), policies.replay(...) | /policies/{id}/… |
webhooks.verify(raw_body, headers, secret) | Local Standard Webhooks check |
The async client has the same methods as coroutines: await async_client.pay(...).
Simulate in tests#
# In CI, with a test key: fail the build if the policy would block a normal purchase.
sim = ndstill.simulate(
agent="agt_01JD8Q3W6Z",
amount={"amount": 4200, "asset": "USD"},
counterparty="Delta Air Lines",
)
assert sim.would_outcome == "approve", sim.reasonsPagination#
for payment in ndstill.payments.list(status="held"):
... # iterates every page, following next_cursor
page = ndstill.payments.list(status="held", limit=50).page # one page: .data, .has_more, .next_cursorErrors#
Non-2xx responses raise subclasses of ndstill.NdStillError with type, code, message, request_id and, where present, fields and decline_reasons:
from ndstill import DeclinedError, StepUpRequiredError
try:
ndstill.pay(agent=agent_id, amount={"amount": 90000, "asset": "USD"}, counterparty="Hilton", purpose="Hotel for the offsite")
except DeclinedError as e:
print(e.decline_reasons[0].message, e.request_id)
except StepUpRequiredError:
... # a person has to confirm with a passkeyInvalidRequestError (400), AuthenticationError (401), DeclinedError (402), PermissionError (403), NotFoundError (404), ConflictError (409), RateLimitError (429, with retry_after), UpstreamError, TimeoutError and InternalError. A held payment returns normally with status == "held".
x402 transport#
ndstill.x402.Transport wraps an httpx transport. On a 402 Payment Required it asks ndStill for a decision first, and signs with your wallet only against an approved payment approval token:
import httpx
from ndstill.x402 import Transport
client = httpx.Client(transport=Transport(ndstill, agent="agt_01JD8Q3W6Z", wallet=wallet, max_amount={"amount": 100000, "asset": "USDC"}))
r = client.get("https://api.northwind.example/v1/search", params={"q": "agents"})AI proxy helpers#
openai = ndstill.ai.openai(agent="agt_01JD8Q3W6Z", task="weekly-report") # openai.OpenAI pointed at the proxy
anthropic = ndstill.ai.anthropic(agent="agt_01JD8Q3W6Z") # anthropic.Anthropic pointed at the proxyVerify for FastAPI#
from fastapi import Depends, FastAPI
from ndstill.verify import VerifiedAgent, verify
app = FastAPI()
@app.post("/v1/search")
async def search(body: dict, agent: VerifiedAgent = Depends(verify(require="passport"))):
return run_search(body, agent_id=agent.id)See Verify for sellers. Framework plugins for LangChain and LangGraph, CrewAI and the OpenAI Agents SDK wrap this client as tools; they mirror the MCP tools.