Cost-shield foundation for AI workloads: OpenAI + Anthropic Batch APIs, live/batch urgency router, shared embedding cache.
Project description
matrx-batch
Cost-shield foundation for AI workloads in the Matrx ecosystem.
Three primitives:
- OpenAI Batch API + Anthropic Message Batches — submit JSONL, poll status, fetch results. Async wrappers over the provider SDKs.
- Urgency router —
BatchRouter.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. - Embedding cache — content-addressable (SHA256 of
model || text) reuse of embedding vectors across the org. Backed byrag.embedding_cachevia 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matrx_batch-0.1.0.tar.gz.
File metadata
- Download URL: matrx_batch-0.1.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a373ffefc233dd4d94ee7520f2d209576e63561f647fe0fab219688eb3f74c3e
|
|
| MD5 |
20c629cf69e7ff5bcecc15aeaa10cf03
|
|
| BLAKE2b-256 |
ca3ef280b56c41d565dac5261b61621d73b46bf588645c9e4666a10ea235ed8e
|
Provenance
The following attestation bundles were made for matrx_batch-0.1.0.tar.gz:
Publisher:
publish-package.yml on AI-Matrix-Engine/aidream
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matrx_batch-0.1.0.tar.gz -
Subject digest:
a373ffefc233dd4d94ee7520f2d209576e63561f647fe0fab219688eb3f74c3e - Sigstore transparency entry: 2145926003
- Sigstore integration time:
-
Permalink:
AI-Matrix-Engine/aidream@2c66d2a5016f6c8b1e48ee1346c15d2fb4403ddc -
Branch / Tag:
refs/tags/matrx-batch/v0.1.0 - Owner: https://github.com/AI-Matrix-Engine
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@2c66d2a5016f6c8b1e48ee1346c15d2fb4403ddc -
Trigger Event:
push
-
Statement type:
File details
Details for the file matrx_batch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: matrx_batch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
410c1c65dcca70dbc69f37ed516ada49852c52ba071d2b2b93e844e9c3c03db0
|
|
| MD5 |
1e4277171b4cadf473fb8eb67cf0fef0
|
|
| BLAKE2b-256 |
1d397533b1e75ff8df84b76db43dd9af67f1fe307612c982cf7a0cb8d803c9c7
|
Provenance
The following attestation bundles were made for matrx_batch-0.1.0-py3-none-any.whl:
Publisher:
publish-package.yml on AI-Matrix-Engine/aidream
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matrx_batch-0.1.0-py3-none-any.whl -
Subject digest:
410c1c65dcca70dbc69f37ed516ada49852c52ba071d2b2b93e844e9c3c03db0 - Sigstore transparency entry: 2145926011
- Sigstore integration time:
-
Permalink:
AI-Matrix-Engine/aidream@2c66d2a5016f6c8b1e48ee1346c15d2fb4403ddc -
Branch / Tag:
refs/tags/matrx-batch/v0.1.0 - Owner: https://github.com/AI-Matrix-Engine
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@2c66d2a5016f6c8b1e48ee1346c15d2fb4403ddc -
Trigger Event:
push
-
Statement type: