Skip to main content

Official Python SDK for SynapseNetwork agent service discovery, paid API invocation, and receipts

Project description

SynapseNetwork Python SDK

Official Python SDK for agents and applications that use SynapseNetwork to discover services, invoke APIs, and receive auditable USDC settlement receipts.

SynapseNetwork gives agents a scoped Agent Key instead of an unlimited API key or credit card. Your code can search for a service, invoke it with an explicit price or spend cap, then verify the receipt that records what happened.

Install

pip install synapse-network-ai-sdk

Python 3.9 or newer is required.

Five-minute quickstart

Create an Agent Key in the SynapseNetwork dashboard, then export it before your app starts:

export SYNAPSE_AGENT_KEY=agt_xxx

Production is the default SDK environment and uses:

https://api.synapse-network.ai

Search for a service, invoke it with the discovered fixed price, then read the receipt:

from synapse_client import SynapseClient

client = SynapseClient()

services = client.search("invoice extraction", limit=5)
service = services[0]

result = client.invoke(
    service.service_id,
    {"invoice_url": "https://example.com/invoice.pdf"},
    cost_usdc=str(service.pricing.amount),
    idempotency_key="invoice-job-001",
)

receipt = client.get_invocation(result.invocation_id)
print(receipt.status, receipt.charged_usdc)

Try the free echo service

For a production connectivity smoke test, call the first-party echo service. It is intended for SDK checks and should charge 0 USDC.

python -m pip install synapse-network-ai-sdk
export SYNAPSE_AGENT_KEY=agt_xxx
from synapse_client import SynapseClient

client = SynapseClient()

result = client.invoke(
    "svc_synapse_echo",
    {"message": "hello from the Python SDK"},
    cost_usdc="0",
    idempotency_key="python-echo-001",
)

receipt = client.get_invocation(result.invocation_id)
print(receipt.status, receipt.charged_usdc)

Invocation modes

Mode Use for SDK method Billing input
Fixed-price API Normal provider APIs with a known price invoke() Pass the latest discovered price as cost_usdc
Token-metered LLM LLM services priced by input and output tokens invoke_llm() Pass an optional spend cap such as max_cost_usdc

LLM example:

result = client.invoke_llm(
    "svc_deepseek_chat",
    {
        "messages": [{"role": "user", "content": "Summarize this document."}],
        "max_tokens": 512,
    },
    max_cost_usdc="0.010000",
    idempotency_key="llm-job-001",
)

print(result.usage.input_tokens, result.usage.output_tokens)
print(result.synapse.charged_usdc)

Provider APIs

Most users start as consumers with SynapseClient. If you operate an API that agents should call, use SynapseAuth and the provider facade from backend or operator tooling after owner authentication.

Provider setup lets you register services, publish pricing, inspect health, and reconcile earnings. Keep normal agent runtime code on SynapseClient with an existing Agent Key.

Safety rules

  • Do not commit Agent Keys, owner private keys, provider secrets, wallet seed phrases, or production tokens.
  • Pass money values as strings such as "0" or "0.05"; do not recompute settlement amounts with floating-point math.
  • Use the discovered fixed price for invoke() and a spend cap for invoke_llm().
  • Use gateway_url only for private deployments or documented sandboxes. Public examples should target production.

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapse_network_ai_sdk-1.0.1.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synapse_network_ai_sdk-1.0.1-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file synapse_network_ai_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: synapse_network_ai_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for synapse_network_ai_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6b1479276eb12cf6f80307d9693c6080a941fcfbe39e30480f4853716bdd43c8
MD5 db5590bf06c20100253f383267c8b0ec
BLAKE2b-256 20b9de64b4ff7a7afc259eaec7443ae1ac5c3930ec467ab244428466f968ab26

See more details on using hashes here.

File details

Details for the file synapse_network_ai_sdk-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for synapse_network_ai_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35a298f1d70a1112dd23cb62e37fbaae114a9bb66ef483645abd221f7f08b0a5
MD5 6c7aa17a507740d21e6a9c6c7b3306fb
BLAKE2b-256 47bb779eac74bef113b7425a1e851040c5f3b4bc2f5127b491e647e4e3dc5b16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page