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.1

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.1
File Size Uploaded
aimarket_streaming-2.0.1.tar.gz 4.2 kB Details

Built distribution (wheel)

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

Total release size: 8.9 kB

Release files / aimarket_streaming-2.0.1.tar.gz

Download URL aimarket_streaming-2.0.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b9dc962adce14c864a8cf994226aada7855c5a39f7cf5465634b968b351ec1d9
BLAKE2b-256 checksum
How to use checksums
64f066350d115ff43b0cb44fcb74977ef99c46900e2bda786cbc6597ad7cb749
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.1-py3-none-any.whl

Download URL aimarket_streaming-2.0.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
055b9c27713ff230c22568f0d5ca2afb3c26806d6b28e0fd218044cf8cd0fe70
BLAKE2b-256 checksum
How to use checksums
6e23fb541c547f98a850ca756277b944ac82ff4441fcdf2cf94fd8e775762dab
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.1 This release

2 release files

2.0.0

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