Skip to main content

Installing the SDK

The TAP Python SDK lives at sdk/python/ in the repo. Install it editable:

git clone https://github.com/HonestFreak/TAP
cd sol
pip install -e sdk/python

Optional model adapters are extras:

pip install -e 'sdk/python[anthropic]' # Claude
pip install -e 'sdk/python[openai]' # GPT-4o family
pip install -e 'sdk/python[ollama]' # Local Llama via Ollama
# Gemini works out of the box with httpx — no extra install required.

Public surface

from tap import (
TapConsumer, ConsumerSession, # consumer client + per-session iterator
TapProducer, # producer host
Decision, Evaluator, # halt-on-evaluator types
compose, content_policy, # standard-library evaluators
json_schema, length_cap, topic_drift,
tokenizer, # process-local tokenizer registry
)

Lower-level layers — exposed for custom integrations:

ModulePurposeGuide
tap.consumer.policy.ConsumerPolicyAudit producer terms before escrowConsumer
tap.consumer.session.TokenChunk / CommitSignedStreaming + observability eventsConsumer
tap.producer.pricing.PricingProducer price + tokenizer configProducer
tap.producer.channel.ActiveChannelPer-session producer stateProducer
tap.timing.parameters.TimingParametersgrace / pause / total timeoutsConsumer
tap.protocol.commit.CommitMessage / SignedCommitmentOff-chain commitment typesConsumer
tap.protocol.codecCommit encode/decode (mirrors on-chain layout)Wire format
tap.protocol.signingEd25519 commit signingWire format
tap.x402.*x402 wire-format codecsx402
tap.chain.instructionsopen_channel / settle / dispute / close buildersOn-chain
tap.chain.pdaChannel + vault PDA derivationOn-chain
tap.chain.rpc.ChainClientThin async-RPC convenience wrapper
tap.evaluators.*JSON schema, length, topic, repetition, content policyEvaluators
tap.adapters.*Anthropic / OpenAI / Gemini / Ollama wrappersProducer

Exceptions

Every SDK error subclasses tap.exceptions.TapError, so applications can catch protocol failures without trapping unrelated network or wallet errors.

ExceptionRaised when
TapErrorBase class — catch this to handle any TAP failure
X402ErrorBad / missing fields in X-PAYMENT-REQUIREMENTS, X-PAYMENT, or X-PAYMENT-RESPONSE; producer terms violate the consumer's ConsumerPolicy; tokenizer mismatch on the §5.3.7 check
ProtocolErrorWire-format or schema violation in a commit, SSE frame, or codec
CommitmentErrorCommit fails sequence / monotonicity / signature validation
HaltErrorCounterparty stops responding past the configured pause window
SettlementErrorOn-chain settle / close returned an unexpected state
ChannelStateErrorOperation requested on a channel in the wrong lifecycle state

System requirements

  • Python 3.12+ (uses slots=True dataclasses extensively)
  • A Solana keypair with USDC and SOL on the target cluster
  • For the demo: a Gemini API key (or wire your own model adapter)

Verifying the install

python3 -c "from tap import TapConsumer, TapProducer, tokenizer; print(tokenizer.is_registered('tap.tok.v1'))"
# True

Tests

cd sdk/python
pytest tests/test_codec_parity.py tests/test_pda_parity.py tests/test_x402_codecs.py tests/test_tokenizer.py