Skip to main content

matrx-batch

Cost-shield foundation for AI workloads in the Matrx ecosystem.

Three primitives:

  1. OpenAI Batch API + Anthropic Message Batches — submit JSONL, poll status, fetch results. Async wrappers over the provider SDKs.
  2. Urgency routerBatchRouter.submit(job) routes a job to live inference, to the provider's Batch API (50% discount, 24h SLA), or makes a cost-based decision automatically.
  3. Embedding cache — content-addressable (SHA256 of model || text) reuse of embedding vectors across the org. Backed by rag.embedding_cache via a host-supplied asyncpg pool.

Dependency posture

matrx-batch sits one notch above matrx-utils in the dependency graph and is consumed by matrx-rag (embedding cache) and matrx-ai (urgency router, future). It MUST NOT import from aidream/ or from any other matrx-* sibling — every cross-boundary dependency comes in via matrx_batch.configure(...).

Usage (host-side wiring)

import matrx_batch
from openai import AsyncOpenAI
from anthropic import AsyncAnthropic

matrx_batch.configure(
    openai_client=AsyncOpenAI(api_key=settings.OPENAI_API_KEY),
    anthropic_client=AsyncAnthropic(api_key=settings.ANTHROPIC_API_KEY),
    pool_factory=lambda: get_async_pg_pool(),
    cost_check=_aidream_budget_precheck,
)

# Wire the cache into matrx-rag's embed() funnel
import matrx_rag
matrx_rag.configure(embedding_cache=matrx_batch.get_embedding_cache())

Usage (consumer)

from matrx_batch import BatchRouter, BatchableJob

router = BatchRouter()
receipt = await router.submit(
    BatchableJob(
        kind="chat",
        provider="anthropic",
        urgency="auto",
        payload={"model": "claude-haiku-4-5", "messages": [...]},
        estimated_tokens_in=8200,
    )
)

See also

  • CLAUDE.md — package rules and injection-point contract.
  • matrx_batch/embedding_cache.py — chunk-level embedding reuse.
  • matrx_batch/router.py — urgency routing decisions.

Download files

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

Source Distribution

matrx_batch-0.2.5.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

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

matrx_batch-0.2.5-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file matrx_batch-0.2.5.tar.gz.

File metadata

  • Download URL: matrx_batch-0.2.5.tar.gz
  • Upload date:
  • Size: 42.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for matrx_batch-0.2.5.tar.gz
Algorithm Hash digest
SHA256 c20007a48c1d3cb02cc26cf49ac42ec93b31e73d78642bd3d46d86476a5f22cc
MD5 7bdfb4e478dbaaaa03037ec1bb29e26d
BLAKE2b-256 8a8c8e8f679adabe59f202015b3b263333e3359e82ab2f92a0977112b610df5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for matrx_batch-0.2.5.tar.gz:

Publisher: publish-package.yml on AI-Matrix-Engine/aidream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file matrx_batch-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: matrx_batch-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for matrx_batch-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2214404a3718229a44946b54f2bee3a0d24dbf82ef2c51786cb92ee24144a930
MD5 7656383a494127d1695cc9e62401dd3a
BLAKE2b-256 40e85d8cb5deba8a7f2eef6efa9d76cab8e793c2743f1d80d72df2d1b52c51a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for matrx_batch-0.2.5-py3-none-any.whl:

Publisher: publish-package.yml on AI-Matrix-Engine/aidream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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