Skip to main content

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, CachePointContent)
  • AssistantMessage: assistant message with optional tool calls and provider continuation state
  • ToolMessage: tool result

Responses

  • ChatResponse: chat completion result with content, usage, cost, model, provider, finish_reason, optional provider_metadata, and optional provider continuation state
  • ChatChunk: streaming chunk with delta, tool_call_deltas, usage, cost, plus the serving model/provider stamped on the terminal chunk and optional metadata and continuation state
  • EmbeddingResponse: embedding result with embeddings, usage, cost
  • ResponseResponse: Responses API result with output_text, usage, cost
  • ResponseInputMessage: 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 configuration
  • PricingSchedule: 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 price
  • calculate_cost(): calculates cost from usage and pricing; pass as_of=<date> to bill at the rate in effect on that day (defaults to the latest schedule)

Tools

  • Tool: function tool definition
  • ToolChoice / ToolChoiceFunction: control whether and which tool the model calls
  • ToolCall / ToolCallDelta: tool call in responses and streaming
  • FunctionDefinition / FunctionCallResult / FunctionCallDelta

Response Format

  • TextResponseFormat / JsonObjectResponseFormat / JsonSchemaResponseFormat

Protocols

from lmux import CompletionProvider, EmbeddingProvider, ResponsesProvider, PricingProvider, AsyncCloseable
  • 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
  • AsyncCloseable: 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:

  • 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

Metadata

Release files for lmux 0.12.0

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 0.12.0
File Size Uploaded
lmux-0.12.0.tar.gz 16.0 kB Details

Built distribution (wheel)

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

Total release size: 36.0 kB

Release files / lmux-0.12.0.tar.gz

Download URL lmux-0.12.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
900ab1ae521b88b2788cf458d6c1695129e0ac0a7b7c646ba778314a8721bf75
BLAKE2b-256 checksum
How to use checksums
20feed5ce30c238afc3e67548fa9038abfa9f12ae6776590c742e5d44c217bca
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 Jul 31, 2026.

Transparency log

Release files / lmux-0.12.0-py3-none-any.whl

Download URL lmux-0.12.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
713a952c44af93ecbc67574c83779fe4421e4ca2f1199a9a507353e58a2aed63
BLAKE2b-256 checksum
How to use checksums
3fe87d8ac2e497b719b3ea2f014eb00aecde0e817a87158f79288b0b67ad9d56
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 Jul 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files

0.11.0

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.2

2 release files

0.5.1

2 release files

0.5.0

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