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)

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

lmux_openai-0.9.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lmux_openai-0.9.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file lmux_openai-0.9.0.tar.gz.

File metadata

  • Download URL: lmux_openai-0.9.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for lmux_openai-0.9.0.tar.gz
Algorithm Hash digest
SHA256 1edda45c7a8cc8e14d9c6d930df36dd322e17a89cf51da6788c92a0f98a03724
MD5 2a9ccb9a3e1592af64344fa26bf25ecf
BLAKE2b-256 ed3aa71ac9eb1a8ae87aace836968d954e64904b569ac69353dce77e10e1caf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmux_openai-0.9.0.tar.gz:

Publisher: publish.yml on cluebbehusen/lmux

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lmux_openai-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: lmux_openai-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for lmux_openai-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6925e665d9486a6f98a6be4395399a3798e22757cf3fde0cfbb45038b095a9bd
MD5 aa17ffce87eca7e0e803049a195f2e98
BLAKE2b-256 5c60fc6156b5ccdcf5cbf70912719d2ca040fbb9e8f504298b2eeb720015feaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmux_openai-0.9.0-py3-none-any.whl:

Publisher: publish.yml on cluebbehusen/lmux

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.10.1

2 files

0.10.0

2 files

This release

0.9.0 This release

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 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