Skip to main content

aimarket-streaming

Documentation

Document Description
User guide Install, configure, verify plugin is loaded
User cases Personas and cross-plugin workflows
SDK integration Code examples and hook behavior

SSE/WS streaming + per-chunk billing with micro-receipts. Capability streams tokens. Every N tokens → signed micro-receipt. Consumer can cancel mid-stream — pays only for what was received. Channel balance debited incrementally.

When to Use

  • LLM text generation (tokens streamed → billed per 10 tokens)
  • Long-running AI tasks where consumer wants partial results
  • Budget-sensitive consumers who want to cancel mid-stream
  • Audit: every chunk has a signed receipt for compliance

Installation

pip install aimarket-streaming

Example

from aimarket_hub.signing import Signer
from aimarket_streaming.streaming import StreamingBiller

signer = Signer()
biller = StreamingBiller(signer)

session = biller.open_session(
    capability_id="text.generate@v1", product_id="prod-gpt",
    channel_id="ch_abc123", price_per_token_usd=0.001,
    tokens_per_chunk=10
)

async def token_stream():
    for word in ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", ".", "..."]:
        yield word  # In production: yield actual LLM tokens

import asyncio
async def main():
    async for chunk in biller.stream_tokens(session, token_stream()):
        print(f"Chunk {chunk['chunk_receipt']['chunk_index']}: "
              f"${chunk['cumulative_price_usd']:.6f} "
              f"({chunk['cumulative_tokens']} tokens)")

asyncio.run(main())

# Cancel mid-stream — pays only for received
result = biller.cancel_session(session.session_id)
print(f"Cancelled. Total paid: ${result['total_price_usd']:.6f}")

Per-Chunk Billing

  • price_per_token_usd: 0.001 (0.1 cent per token)
  • tokens_per_chunk: 10 (micro-receipt every 10 tokens)
  • Each chunk receipt is Ed25519-signed — verifiable audit trail

License

MIT · Maintained by AI-Factory

Metadata

Release files for aimarket-streaming 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aimarket-streaming 2.0.0
File Size Uploaded
aimarket_streaming-2.0.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aimarket-streaming 2.0.0
File Interpreter ABI Platform
aimarket_streaming-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / aimarket_streaming-2.0.0.tar.gz

Download URL aimarket_streaming-2.0.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f5421daea483aee220189cbe6d03de9435ecfaf0a1173785403770d5134b2340
BLAKE2b-256 checksum
How to use checksums
15e4183405fa4a404dc902e90b46468c78fe1b29eb4b0adcfa5c9d899f0c683a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / aimarket_streaming-2.0.0-py3-none-any.whl

Download URL aimarket_streaming-2.0.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
153237818926f5eab9b9c58bacc9a1921dd1b4202d424d4b8be22bbc290b7496
BLAKE2b-256 checksum
How to use checksums
17e86f6a05efed7bcc3deb56e281766fc2d3b7a93afb14333974cc86e53ac741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page