lmux-openai
OpenAI provider for lmux. Talks to the OpenAI REST API directly over httpx.
Supports chat completions, streaming, embeddings, and the Responses API.
Part of the lmux ecosystem: standardized interface, cost tracking on every response, and registry-based routing across providers.
Auth
Set OPENAI_API_KEY in your environment. The default OpenAIEnvAuthProvider reads it automatically.
from lmux_openai import OpenAIProvider
provider = OpenAIProvider()
Or pass a custom auth provider:
provider = OpenAIProvider(auth=my_auth_provider)
Usage
Chat
from lmux import UserMessage
response = provider.chat("gpt-4o", [UserMessage(content="Hello")])
print(response.content)
print(response.cost)
Streaming
for chunk in provider.chat_stream("gpt-4o", [UserMessage(content="Hello")]):
if chunk.delta:
print(chunk.delta, end="")
Embeddings
response = provider.embed("text-embedding-3-small", "Hello")
print(response.embeddings)
Responses API
response = provider.create_response("gpt-4o", "Hello")
print(response.output_text)
Explicit prompt caching
GPT-5.6 and later models accept explicit cache breakpoints in both Chat Completions and Responses. Place CachePointContent after the stable content block you want cached:
from lmux import CachePointContent, ResponseInputMessage, TextContent
from lmux_openai import OpenAIParams
input_items = [
ResponseInputMessage(
role="developer",
content=[TextContent(text=stable_instructions), CachePointContent()],
),
ResponseInputMessage(role="user", content="What changed?"),
]
response = provider.create_response(
"gpt-5.6-terra",
input_items,
provider_params=OpenAIParams(prompt_cache_key="knowledge-base-v1"),
)
When at least one breakpoint is present, lmux sets prompt_cache_options.mode to "explicit", disabling OpenAI's implicit breakpoint so only the marked prefixes are read or written. Cache points are dropped for older models, which continue using automatic prompt caching. CachePointContent.ttl is not mapped because OpenAI's TTL is request-wide and currently fixed at "30m".
Async
All methods have async variants: achat, achat_stream, aembed, acreate_response.
Registry
Use with the lmux registry to route across multiple providers:
from lmux import Registry
registry = Registry()
registry.register("openai", provider)
response = registry.chat("openai/gpt-4o", messages)
Provider Params
Pass OpenAI-specific parameters via provider_params:
from lmux_openai import OpenAIParams
response = provider.chat(
"o3",
messages,
provider_params=OpenAIParams(reasoning_effort="high", service_tier="flex"),
)
| Parameter | Type | Description |
|---|---|---|
service_tier |
"auto" | "default" | "flex" |
Service tier selection |
reasoning_effort |
"low" | "medium" | "high" |
Reasoning effort for o-series models |
seed |
int |
Deterministic sampling seed |
user |
str |
End-user identifier |
prompt_cache_key |
str |
Prompt-cache routing key for better hit rates (chat + responses) |
prompt_cache_retention |
"in_memory" | "24h" |
Prompt-cache retention; legacy, pre-gpt-5.6 (chat + responses) |
Constructor Options
OpenAIProvider(
auth=..., # AuthProvider[str], default: OpenAIEnvAuthProvider()
base_url=..., # Optional base URL override
timeout=..., # Request timeout in seconds
max_retries=..., # Max retry attempts
data_residency=..., # bool, default: False — apply 10% uplift for regional endpoints
organization=..., # Optional org id -> OpenAI-Organization header
project=..., # Optional project id -> OpenAI-Project header
default_headers=..., # Optional Mapping[str, str] added to every request
transport=..., # Optional httpx.BaseTransport for the sync client (proxies, testing)
async_transport=..., # Optional httpx.AsyncBaseTransport for the async client
)
lmux does not read OpenAI's OPENAI_BASE_URL / OPENAI_ORG_ID / OPENAI_PROJECT_ID
environment variables (only the API key, via OpenAIEnvAuthProvider). Pass base_url,
organization, and project explicitly instead.
Custom Headers
default_headers applies to every request — useful for gateways and proxies (e.g. a
Helicone-Auth token). lmux-managed headers (Authorization, Content-Type,
OpenAI-Organization, OpenAI-Project) take precedence and cannot be overridden by
default_headers; use organization / project for those.
provider = OpenAIProvider(
organization="org-abc",
project="proj-123",
default_headers={"Helicone-Auth": "Bearer sk-helicone-..."},
)
Data Residency
OpenAI charges a 10% uplift on the gpt-5.4, gpt-5.5, and gpt-5.6 families when requests go through a regional processing (data residency) endpoint.
Data residency is selected at the transport layer (regional hostname like eu.api.openai.com), not via a per-request parameter. Set data_residency=True on the provider so lmux applies the uplift to the reported cost.
provider = OpenAIProvider(
base_url="https://eu.api.openai.com/v1",
data_residency=True,
)
The uplift is only applied to eligible models (checked via regional_uplift_applies); other models (e.g. gpt-4o, embeddings) return their standard cost even when data_residency=True.
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 lmux_openai-0.10.1.tar.gz.
File metadata
- Download URL: lmux_openai-0.10.1.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52d8e95269ce2bef58018b0a9f4344bd71e0a8ee54b91d9ae036f0e941b1362e
|
|
| MD5 |
ab1fbde0d55b4d036d7c5f0037536c08
|
|
| BLAKE2b-256 |
5310793da80e3b488cc7abe4ad171860cf14e53c64905a97ed42132a6f5c585b
|
Provenance
The following attestation bundles were made for lmux_openai-0.10.1.tar.gz:
Publisher:
publish.yml on cluebbehusen/lmux
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmux_openai-0.10.1.tar.gz -
Subject digest:
52d8e95269ce2bef58018b0a9f4344bd71e0a8ee54b91d9ae036f0e941b1362e - Sigstore transparency entry: 2497964771
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@a82022f50a928478f691b1bb7f4c14a2edb71e31 -
Branch / Tag:
refs/tags/lmux-openai-v0.10.1 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a82022f50a928478f691b1bb7f4c14a2edb71e31 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lmux_openai-0.10.1-py3-none-any.whl.
File metadata
- Download URL: lmux_openai-0.10.1-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2955f40b3329f152ec570550a335ad2a7ba78f3e11b3aa6bafea9598bb27d9d9
|
|
| MD5 |
3a9e69e98b54dff6c450a74a7e5080cf
|
|
| BLAKE2b-256 |
5b4fe681b748dbdce48557b09a71973c5b747d8e45905500991c8e393f68d2e2
|
Provenance
The following attestation bundles were made for lmux_openai-0.10.1-py3-none-any.whl:
Publisher:
publish.yml on cluebbehusen/lmux
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmux_openai-0.10.1-py3-none-any.whl -
Subject digest:
2955f40b3329f152ec570550a335ad2a7ba78f3e11b3aa6bafea9598bb27d9d9 - Sigstore transparency entry: 2497965172
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@a82022f50a928478f691b1bb7f4c14a2edb71e31 -
Branch / Tag:
refs/tags/lmux-openai-v0.10.1 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a82022f50a928478f691b1bb7f4c14a2edb71e31 -
Trigger Event:
push
-
Statement type: