This release is a pre-release and may not be stable for production use.
ByoAI Runtime (byoai-runtime)
Bring Your Own Infrastructure (BYOI). ByoAI Brings the Runtime.
ByoAI Runtime is an infrastructure-agnostic AI agent engine and workflow execution layer for Python. It connects directly to your existing Redis clusters, vector databases (pgvector, Pinecone, Qdrant), LLMs, and telemetry pipelines without requiring data migrations, vector re-indexing, database schema alterations, or vendor lock-in.
โก Why ByoAI Runtime?
Most AI frameworks force engineering teams to adapt their database schemas, re-embed millions of vectors, and rewrite state management logic. ByoAI Runtime adapts to your existing stack instead.
- ๐ Zero Vector Re-indexing (Schema Mapping): Connect directly to existing vector tables using declarative column mapping.
- ๐ฒ Cross-Provider AST Filter Parser: Pass unified JSON filters; ByoAI translates them on the fly into native target dialects (
pgvectorJSONB, Pinecone$eq, Qdrant payload filters). - ๐ Non-Invasive Cache Isolation: Isolates internal runtime keys (
byoai:*) while using pattern-mapped readers to read existing chat histories safely. - ๐ก๏ธ Resilient Provider Routing & Fallbacks: Native rate-limit management, retries, and dynamic model failovers (e.g., OpenAI โ Azure OpenAI โ Ollama).
- ๐ Zero-SaaS Telemetry: Native OpenTelemetry (OTLP) trace emission directly to your existing Grafana, Datadog, or Honeycomb collectors.
๐๏ธ Architecture & Execution Loop
ByoAI Runtime executes as an unopinionated, process-level orchestrator sitting above your existing production data layers:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ runtime.execute() โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ Redis Key Reader โ โ AST Filter Parser โ โ Dynamic Model Router โ
โ (App Chat Ingestion) โ โ (Schema Mapping DB) โ โ (Failover / Retry) โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
Existing Redis DB Existing Vector DB LLM APIs / Inference
(No keys overwritten) (No vector re-indexing) (Existing API keys)
๐ Quickstart
1. Installation
pip install --pre byoai-runtime
--pre is required while the package is in pre-release (0.1.0a1).
2. Hello world
import asyncio
from byoai import Runtime
async def main():
runtime = Runtime(llm={"provider": "openai", "model": "gpt-4o"}) # reads $OPENAI_API_KEY
result = await runtime.execute("What are our enterprise SLA terms?")
print(result.content, result.usage.total_tokens, result.cached)
await runtime.close()
asyncio.run(main())
No cache, no vector store, no telemetry โ just a provider. Everything else in this README is
opt-in: add cache=/vector_store=/semantic_cache=/telemetry= only for what you need, when
you need it. The next example shows all of them wired up against real infrastructure. See
Getting Started for environment
variables, system_prompt=, and async with Runtime(...).
3. Execution Example (Production Setup)
from byoai import Runtime
# Connect to existing infrastructure without altering schemas or keys
runtime = Runtime(
cache={
"provider": "redis",
"url": "redis://redis.internal:6379",
"namespace": "byoai:", # Isolates ByoAI state
"session_reader": {
"pattern": "app:users:{user_id}:chat_history", # Ingests existing history
"format": "json"
}
},
vector_store={
"provider": "pgvector",
"dsn": "postgresql://user:pass@localhost:5432/production_db",
"table": "document_embeddings",
"schema_map": {
"id": "doc_id",
"embedding": "embedding_v2",
"content": "raw_text",
"metadata": "payload_json"
}
},
llm={
"provider": "openai",
"model": "gpt-4o",
"fallback": {
"provider": "azure_openai",
"endpoint": "https://prod.openai.azure.com",
"deployment": "gpt-4-prod",
}
},
telemetry={
"provider": "opentelemetry",
"endpoint": "http://otel-collector.internal:4317" # your existing collector
},
)
# Execute through the runtime (async, from any async framework)
result = await runtime.execute(
"What are our enterprise SLA terms?",
user_id="usr_9912",
filters={"department": {"$eq": "legal"}} # Translated automatically to JSONB SQL
)
print(result.content, result.usage.total_tokens, result.cached)
4. Drop into an existing FastAPI app
from fastapi import Depends, FastAPI
from byoai import Runtime
from byoai.integrations.fastapi import attach, get_runtime, stream_response
app = FastAPI() # your existing app
attach(app, Runtime(llm={"provider": "openai", "model": "gpt-4o"}))
@app.post("/ask")
async def ask(body: dict, rt: Runtime = Depends(get_runtime)):
result = await rt.execute(body["query"])
return {"content": result.content, "usage": result.usage.__dict__}
@app.post("/ask/stream") # Server-Sent Events token streaming
async def ask_stream(body: dict, rt: Runtime = Depends(get_runtime)):
return stream_response(rt, body["query"])
See examples/fastapi_app/ for a runnable app with events, caching, and fallback.
5. Semantic (intent) caching
Serve similar questions from cache โ not just identical ones. One embedding call (~15ms) replaces the whole LLM round-trip when intent matches:
runtime = Runtime(
llm={"provider": "openai", "model": "gpt-4o"},
cache={"provider": "redis", "url": "redis://redis.internal:6379"}, # exact match
semantic_cache={"provider": "memory", "threshold": 0.92}, # intent match
embedder={"provider": "openai", "model": "text-embedding-3-small"},
)
await runtime.execute("What are our enterprise SLA terms?") # LLM call (~800ms)
await runtime.execute("Tell me about our enterprise SLAs") # intent hit (~16ms)
Measured ~50ร faster on intent hits; lookups stay sub-millisecond to ~30k
cached answers (benchmarks/RESULTS.md).
For production, back the intent cache with your existing Redis so hits are shared across every worker/replica and survive restarts:
semantic_cache={"provider": "redis", "url": "redis://redis.internal:6379",
"threshold": 0.92, "capacity": 10_000, "ttl": 3600}
Entries live in one byoai:-namespaced Redis stream; each worker keeps a
local numpy mirror and syncs incrementally, so similarity math never leaves
the process. Redis Cluster and Sentinel are supported everywhere Redis is
("mode": "cluster" or "mode": "sentinel" + sentinels/service_name).
๐ ๏ธ Core Capabilities
1. Zero-Migration Schema Mapping
No need to run migration scripts or duplicate tables. Define a schema_map during initialization to bridge ByoAI to your existing table structures:
vector_config = {
"provider": "pgvector",
"dsn": "...",
"table": "enterprise_knowledge",
"schema_map": {
"id": "uuid",
"embedding": "vector_768",
"content": "body_text",
"metadata": "attributes_json"
}
}
2. AST Filter Translation
Avoid provider-specific query lock-in. Pass standard logical filter expressions and ByoAI compiles them into native query dialects:
[ AST Filter Parser ]
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
pgvector (SQL / JSONB) Pinecone (JSON Dict) Qdrant (Payload Filter)
`attributes_json->>'dept' `{"dept": {"$eq": `FieldCondition(key="dept",
= 'legal'` "legal"}}` match=MatchValue("legal"))`
3. Non-Invasive State Management
ByoAI writes operational artifacts (semantic cache, execution traces, intent plans) under its isolated key namespace while reading existing user sessions read-only:
cache_config = {
"provider": "redis",
"url": "redis://localhost:6379",
"namespace": "byoai:", # All writes go to byoai:cache:*, byoai:planner:*
"session_reader": {
"pattern": "session:{user_id}:messages",
"format": "json"
}
}
๐ Framework Comparison
| Architectural Criteria | LangChain / LlamaIndex | LiteLLM / Portkey | ByoAI Runtime |
|---|---|---|---|
| Primary Focus | Framework Abstractions | API Gateway / Proxy | Unopinionated Agent Engine |
| Schema Migration | โ Required / Enforced | N/A | โ Zero-Migration (Schema Mapped) |
| Vector Re-indexing | โ Required | N/A | โ Direct Query over Existing Vectors |
| AST Metadata Translator | โ Provider-specific | N/A | โ Cross-Provider Dialect Translation |
| Existing Redis Reader | โ Overwrites / Requires SDK | โ N/A | โ Read-only Key Pattern Mapping |
| Observability | โ ๏ธ Pushes Proprietary SaaS | โ OTel Supported | โ OpenTelemetry Native (OTLP) |
| License | MIT | MIT / Commercial | Apache 2.0 (Enterprise Patent Shield) |
๐ฆ Supported Adapter Ecosystem
Cache & Memory
- Redis (Standalone, Cluster, Sentinel)
- Valkey
- In-Memory (Dev/Testing)
Vector Databases
- PostgreSQL + pgvector
- Pinecone
- Qdrant
- Anything else via a
byoai.vector_storesplugin โ see Vector stores.
LLM Providers
- OpenAI
- Anthropic (direct API, AWS Bedrock, or Google Vertex AI)
- Azure OpenAI
- Google Gemini
- Ollama / vLLM / LiteLLM
- OpenRouter / Any OpenAI-compatible REST endpoint
Observability
- OpenTelemetry (Datadog, Grafana, Honeycomb, Jaeger, New Relic) โ gRPC or HTTP OTLP.
Transports
One execution, five ways in โ all share the same payload/result dialect:
- FastAPI โ
byoai.integrations.fastapi(HTTP, SSE, WebSocket) - Robyn (Rust-powered) โ
byoai.integrations.robyn(HTTP, SSE, WebSocket) - MCP โ
byoai.integrations.mcp: expose the runtime as a tool any MCP client (Claude Desktop, another agent) can call, over stdio or streamable HTTP โ with a streaming tool variant (live token deltas as progress notifications) - Queue workers โ
byoai.workers:RuntimeWorker+RedisStreamQueue/MemoryJobQueue - Or embed
Runtimedirectly in any async Python process
Configuration
Every adapter's every setting โ timeouts, retry classification, connection pooling, TTLs, capacity bounds, batch sizes, and more โ is documented in CONFIGURATION.md.
๐งฉ Agent Context Cache
A standalone proxy, separate from Runtime, that sits in front of the
Anthropic API. Point Claude Code (or any Anthropic API client) at it and it
injects prompt-cache breakpoints and dedupes repeated large text blocks
within a session, cutting token spend without any client-side changes.
pip install --pre "byoai-runtime[agent-context-cache]"
byoai-cache # runs in the foreground
export ANTHROPIC_BASE_URL=http://localhost:8787
Prefer to keep it running without holding a terminal open? Start it detached:
byoai-cache start # background; survives closing the terminal
byoai-cache status # running (pid โฆ) โ http://localhost:8787
byoai-cache stop
start writes its pid and logs under ~/.byoai/ (proxy.pid, proxy.log).
Both byoai-cache and the longer byoai-agent-context-cache are the same
command. Override the bind address/port with --host / --port (or the
BYOAI_HOST / BYOAI_PORT env vars). It listens on :8787 by default and
uses Redis for session/dedup state if REDIS_URL is set (falls back to an
in-process store otherwise). Full env var reference in
CONFIGURATION.md.
Reaching the proxy from a remote client (ngrok)
localhost only works for a client on the same machine. To route a remote
client โ Claude's web/mobile apps, a phone, a cloud agent โ through the proxy,
expose it with a tunnel such as ngrok:
BYOAI_PROXY_TOKEN=$(openssl rand -hex 16) byoai-cache start # gate it first
ngrok http 8787 # public https URL
Set BYOAI_PROXY_TOKEN before exposing the proxy. Without it, a public URL
is an open relay to api.anthropic.com (and, if you configured the OpenAI-compat
backend, anyone could spend your BYOAI_OPENAI_COMPAT_API_KEY). With it set,
every request must carry the token, supplied either way:
- Header โ
x-byoai-proxy-token: <token>(for clients that allow custom headers). - URL path โ put the token in the base URL, for clients that only let you set
one:
ANTHROPIC_BASE_URL=https://<id>.ngrok-free.app/<token>. The leading/<token>segment is stripped before routing.
/health stays reachable without the token so a tunnel can probe liveness. For a
private, always-on setup between your own devices, Tailscale
(point clients at the proxy host's tailnet IP) avoids a public endpoint entirely.
Inspecting token-savings data
The proxy keeps a durable SQLite log of per-request usage and tokenizer-verified
benchmark samples at BYOAI_SQLITE_PATH (default ~/.byoai/byoai_runtime.db).
The /v1/stats, /v1/stats/benchmark, /v1/stats/permanent, and
/v1/stats/history endpoints expose these numbers as JSON. To browse the raw
tables without writing SQL, open the file in
sqlite-web, a small browser-based
SQLite viewer:
pip install sqlite-web
sqlite-web ~/.byoai/byoai_runtime.db # opens a UI at http://localhost:8080
sqlite-web is an optional dev convenience, not a dependency of byoai-runtime.
Keeping a long-running proxy small
Two things would otherwise grow with uptime, and both are now bounded.
The SQLite log is pruned to the last BYOAI_RETENTION_DAYS (default 90) once on
every start. A day of heavy Claude Code use adds a few thousand rows and under a
megabyte, so without a window the file reaches a few hundred MB a year and the
unfiltered
SUM() queries behind /v1/stats/permanent slow down as the table grows. To
prune a proxy that has been up for months without restarting it:
byoai-cache prune # delete old rows, then reclaim the freed space
byoai-cache prune --days 30
byoai-cache prune --no-vacuum # delete only; safe against a running proxy
Reclaiming space is skipped when fewer than 1,000 rows were deleted โ rewriting the whole file costs more than the space it returns. The command says so when it skips.
The delete itself is safe to run against a live proxy: WAL mode keeps in-flight
readers unblocked. Reclaiming the freed space is not โ VACUUM rewrites the
whole file under an exclusive lock, and a concurrent write from the running
proxy can fail with "database is locked". Either stop the proxy first, or pass
--no-vacuum and let the space be reused by future rows. Startup pruning never
vacuums for this reason.
Set BYOAI_RETENTION_DAYS=0 to keep every row.
In-process dedup state is capped on two axes: 500 concurrent sessions and 5,000 content hashes per session, oldest evicted first. Evicting a hash costs at most one re-send of a block nobody has referenced in a long time. Redis, when configured, holds the same state; the in-process copy is kept as a complete mirror so an outage degrades dedup quality instead of breaking requests. Those two caps are what bound it โ before them, a single long conversation could accumulate hashes for its entire 8-hour lifetime.
Contributing
ByoAI welcomes AI-assisted development as well as human contributions. See CONTRIBUTING.md for dev setup, checks, the AI-assisted-development policy, and the PR process, and our Code of Conduct. To report a vulnerability, see SECURITY.md rather than opening a public issue.
๐ License & Enterprise Security
byoai-runtime is distributed under the Apache License 2.0.
- Enterprise Safe: Permissive license with explicit patent grants and trademark protections. Pre-approved for enterprise compliance scanners (Snyk, FOSSA, Mend).
- Data Privacy: Runs strictly in-process within your infrastructure. Zero data is transmitted to external servers beyond your configured model and database providers.
๐ Community & Documentation
- Documentation: ravikings.github.io/byoai-runtime
- GitHub Repository: github.com/ravikings/byoai-runtime
- PyPI Package: pypi.org/project/byoai-runtime
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Security: SECURITY.md
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 byoai_runtime-0.1.0a2.tar.gz.
File metadata
- Download URL: byoai_runtime-0.1.0a2.tar.gz
- Upload date:
- Size: 257.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88cf7348e414d399c74e9b68d87767c8591707fb33e25bee396e5a65d68d11b2
|
|
| MD5 |
742154073d29a1036fd3dde6d09cf34f
|
|
| BLAKE2b-256 |
e9283d628adfd7cbd31b64a2c675488a6b277deaf1981643c8d5877972a41ee0
|
Provenance
The following attestation bundles were made for byoai_runtime-0.1.0a2.tar.gz:
Publisher:
publish.yml on ravikings/byoai-runtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
byoai_runtime-0.1.0a2.tar.gz -
Subject digest:
88cf7348e414d399c74e9b68d87767c8591707fb33e25bee396e5a65d68d11b2 - Sigstore transparency entry: 2372985916
- Sigstore integration time:
-
Permalink:
ravikings/byoai-runtime@94be7bcb9e35786de2f0da9c09f6eb64cc5fa260 -
Branch / Tag:
refs/tags/v0.1.0a2 - Owner: https://github.com/ravikings
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@94be7bcb9e35786de2f0da9c09f6eb64cc5fa260 -
Trigger Event:
release
-
Statement type:
File details
Details for the file byoai_runtime-0.1.0a2-py3-none-any.whl.
File metadata
- Download URL: byoai_runtime-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 158.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2426da8c8cd6e8a1dc47c5dbc04ad2dd1e20eb9c16e29a9569d703dfd3b8f97e
|
|
| MD5 |
3e4f2e48fb8477ada3ff68c78947ff23
|
|
| BLAKE2b-256 |
8ed7726fc07ef1ef77a1c5ebc64c4c922f0b8d85fc2de1519805e945137817cd
|
Provenance
The following attestation bundles were made for byoai_runtime-0.1.0a2-py3-none-any.whl:
Publisher:
publish.yml on ravikings/byoai-runtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
byoai_runtime-0.1.0a2-py3-none-any.whl -
Subject digest:
2426da8c8cd6e8a1dc47c5dbc04ad2dd1e20eb9c16e29a9569d703dfd3b8f97e - Sigstore transparency entry: 2372985925
- Sigstore integration time:
-
Permalink:
ravikings/byoai-runtime@94be7bcb9e35786de2f0da9c09f6eb64cc5fa260 -
Branch / Tag:
refs/tags/v0.1.0a2 - Owner: https://github.com/ravikings
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@94be7bcb9e35786de2f0da9c09f6eb64cc5fa260 -
Trigger Event:
release
-
Statement type: