lmux
Core types, protocols, and utilities for the lmux ecosystem.
You don't need to install this directly; provider packages (e.g., lmux-openai) include it as a dependency. Install it only if you're building a custom provider.
Types
Messages
SystemMessage: system/instruction messageDeveloperMessage: developer message (for o-series models)UserMessage: user message, supports text and multimodal content (TextContent,ImageContent,CachePointContent)AssistantMessage: assistant message with optional tool calls and provider continuation stateToolMessage: tool result
Responses
ChatResponse: chat completion result withcontent,usage,cost,model,provider,finish_reason, optionalprovider_metadata, and optional provider continuation stateChatChunk: streaming chunk withdelta,tool_call_deltas,usage,cost, plus the servingmodel/providerstamped on the terminal chunk and optional metadata and continuation stateEmbeddingResponse: embedding result withembeddings,usage,costResponseResponse: Responses API result withoutput_text,usage,costResponseInputMessage: Responses API message input, supporting text and multimodal content (TextContent,ImageContent,CachePointContent)
Provider continuations
Some provider protocols return opaque, signed state that must be sent back unchanged to continue a tool-use turn. Providers that support this attach a ProviderContinuation to the response and terminal stream chunk. Use response.to_assistant_message() to preserve it:
response = provider.chat(model, messages, tools=tools)
messages.append(response.to_assistant_message())
messages.append(ToolMessage(content=tool_result, tool_call_id=tool_call_id))
Each provider package owns its continuation namespace and payload. When an assistant message returns to the matching provider, that provider may treat the continuation as authoritative instead of rebuilding the turn from normalized content and tool calls. Other providers ignore it and use the normalized fields, so the message remains portable.
Treat continuation data as opaque: preserve it unchanged or set it to None. It can include full reasoning text and signatures, may be large or sensitive, and is included by model_dump() and model_dump_json().
Cost
Usage: token counts (input_tokens,output_tokens,cache_read_tokens,cache_creation_tokens)Cost: cost breakdown (input_cost,output_cost,total_cost, plus cache costs)ModelPricing/PricingTier: tiered pricing configurationPricingSchedule: dated price overrides for models whose rate changes on a known date (e.g. an introductory rate)per_million_tokens(): converts per-million price to per-token pricecalculate_cost(): calculates cost from usage and pricing; passas_of=<date>to bill at the rate in effect on that day (defaults to the latest schedule)
Tools
Tool: function tool definitionToolChoice/ToolChoiceFunction: control whether and which tool the model callsToolCall/ToolCallDelta: tool call in responses and streamingFunctionDefinition/FunctionCallResult/FunctionCallDelta
Response Format
TextResponseFormat/JsonObjectResponseFormat/JsonSchemaResponseFormat
Protocols
from lmux import CompletionProvider, EmbeddingProvider, ResponsesProvider, PricingProvider, AsyncCloseable
CompletionProvider[ParamsT]:chat,achat,chat_stream,achat_streamEmbeddingProvider[ParamsT]:embed,aembedResponsesProvider[ParamsT]:create_response,acreate_responsePricingProvider:register_pricingAuthProvider[AuthT]:get_credentials,aget_credentialsAsyncCloseable:aclose
All are @runtime_checkable, so you can use isinstance() to check support.
Registry
Route "prefix/model" strings to provider instances:
from lmux import Registry
registry = Registry()
registry.register("openai", openai_provider)
registry.register("anthropic", anthropic_provider)
response = registry.chat("openai/gpt-4o", messages)
response = registry.chat("anthropic/claude-sonnet-4-20250514", messages)
# Close all providers that implement AsyncCloseable
await registry.aclose()
registry.registered_prefixes returns a frozenset of the registered prefixes, useful for a composite provider that validates its delegation targets.
Exceptions
All exceptions inherit from LmuxError and carry optional provider and status_code fields:
AuthenticationErrorRateLimitError(withretry_after)InvalidRequestErrorNotFoundErrorProviderErrorTimeoutErrorUnsupportedFeatureError
MockProvider
Built-in mock for testing. Implements all protocols with configurable responses and call tracking.
from lmux import MockProvider, ChatResponse
mock = MockProvider(chat_responses=[ChatResponse(...)])
response = mock.chat("any-model", messages)
assert len(mock.calls) == 1
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-0.12.0.tar.gz.
File metadata
- Download URL: lmux-0.12.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
900ab1ae521b88b2788cf458d6c1695129e0ac0a7b7c646ba778314a8721bf75
|
|
| MD5 |
00db76677f0f8c8e0c799850914e75ad
|
|
| BLAKE2b-256 |
20feed5ce30c238afc3e67548fa9038abfa9f12ae6776590c742e5d44c217bca
|
Provenance
The following attestation bundles were made for lmux-0.12.0.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-0.12.0.tar.gz -
Subject digest:
900ab1ae521b88b2788cf458d6c1695129e0ac0a7b7c646ba778314a8721bf75 - Sigstore transparency entry: 2306929838
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@c330796afb2e901072be42c1b674ec37e9713307 -
Branch / Tag:
refs/tags/lmux-v0.12.0 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c330796afb2e901072be42c1b674ec37e9713307 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lmux-0.12.0-py3-none-any.whl.
File metadata
- Download URL: lmux-0.12.0-py3-none-any.whl
- Upload date:
- Size: 19.9 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 |
713a952c44af93ecbc67574c83779fe4421e4ca2f1199a9a507353e58a2aed63
|
|
| MD5 |
1b0919afcab22a7eba829faa4dbaceed
|
|
| BLAKE2b-256 |
3fe87d8ac2e497b719b3ea2f014eb00aecde0e817a87158f79288b0b67ad9d56
|
Provenance
The following attestation bundles were made for lmux-0.12.0-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-0.12.0-py3-none-any.whl -
Subject digest:
713a952c44af93ecbc67574c83779fe4421e4ca2f1199a9a507353e58a2aed63 - Sigstore transparency entry: 2306929853
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@c330796afb2e901072be42c1b674ec37e9713307 -
Branch / Tag:
refs/tags/lmux-v0.12.0 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c330796afb2e901072be42c1b674ec37e9713307 -
Trigger Event:
push
-
Statement type: