Skip to main content

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 message
  • DeveloperMessage: developer message (for o-series models)
  • UserMessage: user message, supports text and multimodal content (TextContent, ImageContent)
  • AssistantMessage: assistant message with optional tool calls
  • ToolMessage: tool result

Responses

  • ChatResponse: chat completion result with content, usage, cost, model, provider, finish_reason
  • ChatChunk: streaming chunk with delta, tool_call_deltas, usage, cost
  • EmbeddingResponse: embedding result with embeddings, usage, cost
  • ResponseResponse: Responses API result with output_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 configuration
  • per_million_tokens(): converts per-million price to per-token price
  • calculate_cost(): calculates cost from usage and pricing

Tools

  • Tool: function tool definition
  • ToolCall / ToolCallDelta: tool call in responses and streaming
  • FunctionDefinition / FunctionCallResult / FunctionCallDelta

Response Format

  • TextResponseFormat / JsonObjectResponseFormat / JsonSchemaResponseFormat

Protocols

from lmux import CompletionProvider, EmbeddingProvider, ResponsesProvider, PricingProvider
  • CompletionProvider[ParamsT]: chat, achat, chat_stream, achat_stream
  • EmbeddingProvider[ParamsT]: embed, aembed
  • ResponsesProvider[ParamsT]: create_response, acreate_response
  • PricingProvider: register_pricing
  • AuthProvider[AuthT]: get_credentials, aget_credentials

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)

Exceptions

All exceptions inherit from LmuxError and carry optional provider and status_code fields:

  • AuthenticationError
  • RateLimitError (with retry_after)
  • InvalidRequestError
  • NotFoundError
  • ProviderError
  • TimeoutError
  • UnsupportedFeatureError

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

lmux-0.3.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

lmux-0.3.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file lmux-0.3.0.tar.gz.

File metadata

  • Download URL: lmux-0.3.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lmux-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8c169c6756af7dc4fa7763b94a6c4d776c89a7b32f30eacc759886aba835af30
MD5 2544a29c551938815d8809182d52f3b8
BLAKE2b-256 49b53f68e1d73afe2f143affaae031924528c428bafdba9be7b52851994ac3a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmux-0.3.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-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lmux-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lmux-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db8fee98c7b0001ff2ecda3d28db187a9b8e774ba237a876f95fce084361e9eb
MD5 afe9fffac0f837f3fab419369be8d834
BLAKE2b-256 daf6cf0fa209f0f14549634db91952b15e9662612e5bb3a1454a0341cada3e93

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmux-0.3.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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page