Skip to main content

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 passes through as the breakpoint's ttl: "30m" (the default) or "12h", which the Responses API accepts and bills at a higher cache-write rate. Cost reflects the per-TTL split OpenAI reports in usage.

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, gpt-5.6, and gpt-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.

Metadata

Release files for lmux-openai 0.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lmux-openai 0.11.1
File Size Uploaded Provenance Actions
lmux_openai-0.11.1.tar.gz 17.6 kB With provenance Details for lmux_openai-0.11.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lmux-openai 0.11.1
File Interpreter ABI Platform Actions
lmux_openai-0.11.1-py3-none-any.whl Python 3 none any Details for lmux_openai-0.11.1-py3-none-any.whl

Total release size: 37.5 kB

Release files / lmux_openai-0.11.1.tar.gz

Download URL lmux_openai-0.11.1.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
20aafec8a2928da8b941f19a0c0a5b677bcafdef28d636c02ba1ef49dc64cd21
BLAKE2b-256 checksum
How to use checksums
e1de83a6f21097b4e2c073d3f1103dfdf1051c27b7d12cb57caa9507f8278ca5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Nov 18, 2026.

Transparency log

Release files / lmux_openai-0.11.1-py3-none-any.whl

Download URL lmux_openai-0.11.1-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed42b7b8abfec43cd0ebd0faa522aaa86889f6fd970f8e875146bece24d135cb
BLAKE2b-256 checksum
How to use checksums
486972717da27e10c15c06ecd8f09a9c371539205c24743642ac34add2b9a83c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Nov 18, 2026.

Transparency log

Security for lmux-openai 0.11.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lmux_openai-0.11.1.tar.gz

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 Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page