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 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, 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.10.4

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.10.4
File Size Uploaded
lmux_openai-0.10.4.tar.gz 16.0 kB Details

Built distribution (wheel)

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

Total release size: 35.2 kB

Release files / lmux_openai-0.10.4.tar.gz

Download URL lmux_openai-0.10.4.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a1a7fb7a6b791970e587749d060156bcaf061ad182f9879ba98bfd85a970485e
BLAKE2b-256 checksum
How to use checksums
4a3d86cf4a5ec74487188697f898b0acdf179bf40ae456915798706304b75e14
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 Sep 22, 2026.

Transparency log

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

Download URL lmux_openai-0.10.4-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
612282da5f205bc765e902fadfb215608eaee159a0708b1d19ec500ecc66af74
BLAKE2b-256 checksum
How to use checksums
8e7a1b4c467b9df8d4607187dad9f2a03a81a391dd73a74f204b10927e5cb227
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 Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.10.5

2 release files

This release

0.10.4 This release

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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