orditect-bridge-openai
OpenAI-compatible endpoint bridge for the Orditect ecosystem (bridge reference implementation, producer tier).
Purpose
- Reference bridge: the first external producer passing the protocol conformance suite under the producer profile.
- Governed LLM calls: semaphore, budget, audit, and content pointer-ization wrapped around any OpenAI-compatible endpoint (OpenAI, Azure, vLLM, Ollama, LM Studio, ...).
- Two call forms with one client: non-streaming
chat()and streamingstream()(implementsLLMSourceProtocolfor orditect-stream).
Boundary
This is a bridge, not a framework package: OpenAI-shaped vocabulary (model / messages / usage / finish_reason) lives here and never flows back into core / flow / stream / protocol.
Usage
from orditect.bridge.openai import GovernedLLMClient
from orditect.adapter.memory import MemoryStore
parts = MemoryStore()
llm = GovernedLLMClient(
"https://api.openai.com", api_key="sk-...",
governor=governor, resource="llm",
budget=ledger,
audit_writer=parts.audit,
content_writer=parts.content,
model="gpt-4o",
task_id="my-task",
)
result = await llm.chat(messages=[{"role": "user", "content": "hi"}])
# streaming (orditect-stream compatible)
async for chunk in llm.stream(messages=[...]):
...
Streaming termination discipline
stream() classifies every stream's ending and makes the classification
auditable:
| Ending | Detection | Behavior |
|---|---|---|
| completed | [DONE] sentinel or a finish_reason |
protocol finish chunk appended; audit carries termination=completed + finish_reason |
| truncated | connection closed without either marker | raises StreamTruncatedError (audit carries termination=truncated + chunk count) |
| empty | 200 OK with zero frames | raises StreamEmptyError (endpoint incompatibility, e.g. stream_options) |
A finish_reason="length" (max_tokens reached) is a protocol-completed
ending, NOT an exception — it is recorded in the audit payload so a
silently shortened body stays visible downstream.
Token usage is captured from the stream's tail chunk (which carries an
empty choices list), so cost_fn receives real token figures for
streams instead of None.
Testing
# unit + mock-SSE termination matrix (no network, no credentials)
python -m pytest tests -q -m "not live"
# live endpoint tests (skipped without .env)
# .env keys: LLM_BASE_URL / LLM_API_KEY / LLM_PUBLISH_MODEL
python -m pytest tests/test_stream_live.py -v -m live
Live stream probe
tests/probe_live_stream.py drives a real endpoint and prints every
chunk plus the resulting audit payload:
# full stream: complete body, finish chunk, termination=completed,
# real usage/cost in the audit payload
python -m tests.probe_live_stream
# max_tokens truncation: finish_reason=length (completed, auditable)
python -m tests.probe_live_stream --max-tokens 24 "long essay prompt"
# cancel beat: output stops after N chunks while consumption drains to
# the real terminal point; the drain window and the full token bill
# (cancel does NOT save tokens) show up in the summary
python -m tests.probe_live_stream --cancel-after 30
Reference output (dashscope, qwen thinking model):
# full stream
finish chunk: True
termination : completed
finish_reason : stop
usage : total_tokens=2582 cost_units: 2582
# cancel after chunk #30
cancelled at: 1.0s
drain window: 27.8s (consumption after cancel until stream end)
finish chunk: True
termination : completed
usage : total_tokens=3154 cost_units: 3154
The cancel comparison is the design statement in numbers: interrupting the consumer does not end the upstream call — the semaphore stays held until the API stream truly finishes, and the bill covers every token generated, drained or not.
Release files for orditect-bridge-openai 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| orditect_bridge_openai-0.1.7.tar.gz | 19.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| orditect_bridge_openai-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.4 kB
Release files / orditect_bridge_openai-0.1.7.tar.gz
| Download URL | orditect_bridge_openai-0.1.7.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0507ea2c8906ef86eb66a51d2deaabce089f28201e5a6b1b9c665d7f57c693ad
|
|
BLAKE2b-256 checksum How to use checksums |
b3802ff8755aba42a38dafc4fbfb4144e03689b1cc84e0ebbdae38901a28bc85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logRelease files / orditect_bridge_openai-0.1.7-py3-none-any.whl
| Download URL | orditect_bridge_openai-0.1.7-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9dd0ce6b1d2455b5be85e694617f83bab0239a9957e2af1e246d203bc96ee945
|
|
BLAKE2b-256 checksum How to use checksums |
ad68ae0cd220f2fc27028ad977984408b555d34b7c41ef985cbf0f8e36aad583
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency log