Core types, protocols, and utilities for the lmux language model multiplexer
Project description
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)AssistantMessage: assistant message with optional tool callsToolMessage: tool result
Responses
ChatResponse: chat completion result withcontent,usage,cost,model,provider,finish_reasonChatChunk: streaming chunk withdelta,tool_call_deltas,usage,costEmbeddingResponse: embedding result withembeddings,usage,costResponseResponse: Responses API result withoutput_text,usage,cost
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 configurationper_million_tokens(): converts per-million price to per-token pricecalculate_cost(): calculates cost from usage and pricing
Tools
Tool: function tool definitionToolCall/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()
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
Project details
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.5.2.tar.gz.
File metadata
- Download URL: lmux-0.5.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae8cc19825e15de3ea22ac0fa996f494aa282b60cfa30461f2276c7ee05b7d02
|
|
| MD5 |
48ee0b6fc4751d3839609d48c86511b8
|
|
| BLAKE2b-256 |
08a8a1fa0be52bb6c6a6d329fbeda9eb77fd4f15139c584b7d17af40e64ee088
|
Provenance
The following attestation bundles were made for lmux-0.5.2.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.5.2.tar.gz -
Subject digest:
ae8cc19825e15de3ea22ac0fa996f494aa282b60cfa30461f2276c7ee05b7d02 - Sigstore transparency entry: 1237894879
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@8fc73c942c90b25b45f8cc2e223ad3f630c8bf5a -
Branch / Tag:
refs/tags/lmux-v0.5.2 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8fc73c942c90b25b45f8cc2e223ad3f630c8bf5a -
Trigger Event:
push
-
Statement type:
File details
Details for the file lmux-0.5.2-py3-none-any.whl.
File metadata
- Download URL: lmux-0.5.2-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c55b0f74f5b998403abd21092052fa726cd2097dc655c0b017971ab6048d5efa
|
|
| MD5 |
de6ba953347aa0d2f8eb91ecb25c23ef
|
|
| BLAKE2b-256 |
b817b143da16414932156302066ad2a40113de761eaf51cd79ea76ef022505f1
|
Provenance
The following attestation bundles were made for lmux-0.5.2-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.5.2-py3-none-any.whl -
Subject digest:
c55b0f74f5b998403abd21092052fa726cd2097dc655c0b017971ab6048d5efa - Sigstore transparency entry: 1237894884
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@8fc73c942c90b25b45f8cc2e223ad3f630c8bf5a -
Branch / Tag:
refs/tags/lmux-v0.5.2 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8fc73c942c90b25b45f8cc2e223ad3f630c8bf5a -
Trigger Event:
push
-
Statement type: