Anthropic provider for lmux
Project description
lmux-anthropic
Anthropic provider for lmux. Wraps the anthropic SDK.
Supports chat completions and streaming.
Part of the lmux ecosystem: standardized interface, cost tracking on every response, and registry-based routing across providers.
Auth
Set ANTHROPIC_API_KEY in your environment. The default AnthropicEnvAuthProvider reads it automatically.
from lmux_anthropic import AnthropicProvider
provider = AnthropicProvider()
Usage
Chat
from lmux import UserMessage
response = provider.chat("claude-sonnet-4-20250514", [UserMessage(content="Hello")])
print(response.content)
print(response.cost)
Streaming
for chunk in provider.chat_stream("claude-sonnet-4-20250514", [UserMessage(content="Hello")]):
if chunk.delta:
print(chunk.delta, end="")
Async
All methods have async variants: achat, achat_stream.
Registry
Use with the lmux registry to route across multiple providers:
from lmux import Registry
registry = Registry()
registry.register("anthropic", provider)
response = registry.chat("anthropic/claude-sonnet-4-20250514", messages)
Provider Params
from lmux_anthropic import AnthropicParams
response = provider.chat(
"claude-sonnet-4-20250514",
messages,
provider_params=AnthropicParams(inference_geo="us"),
)
| Parameter | Type | Description |
|---|---|---|
thinking |
dict |
Extended thinking configuration |
metadata |
dict[str, str] |
Request metadata |
top_k |
int |
Top-k sampling |
service_tier |
"auto" | "standard_only" |
Service tier selection |
inference_geo |
"us" |
Inference geography (affects cost) |
cache_control |
dict |
Top-level prompt-cache control — auto-places a breakpoint on the last cacheable block (e.g. {"type": "ephemeral"}) |
Prompt Caching
Two ways to opt in:
- Top-level (auto-placement): pass
cache_controlviaAnthropicParams(above) to cache the full rendered prefix. - Explicit breakpoints: place
CachePointContentparts inUserMessagecontent. A cache point marks the end of the stable prefix; it attachescache_controlto the preceding content block. A cache point with no preceding block in its message applies to whatever came before it: the prior message's last block, or the system text seen so far (system text after the marker stays outside the cached prefix). A marker with nothing cacheable before it is dropped, and when two markers resolve to the same block the first one wins.
from lmux import CachePointContent, TextContent, UserMessage
messages = [
UserMessage(content=[TextContent(text=big_stable_context), CachePointContent(ttl="1h")]),
UserMessage(content="What changed since yesterday?"),
]
Cache reads/writes are reported on response.usage (cache_read_tokens, cache_creation_tokens, and the per-TTL cache_creation_tokens_by_ttl breakdown) and priced into response.cost, including the 2x write rate for ttl="1h".
Constructor Options
AnthropicProvider(
auth=..., # AuthProvider[str], default: AnthropicEnvAuthProvider()
base_url=..., # Optional base URL override
timeout=..., # Request timeout in seconds
max_retries=..., # Max retry attempts
default_max_tokens=..., # Default max tokens (default: 4096)
)
Project details
Release history Release notifications | RSS feed
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_anthropic-0.5.1.tar.gz.
File metadata
- Download URL: lmux_anthropic-0.5.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0709fb4d538fd4ab83ae97a8e711db0f362d0fbb6afbfc9223bad411d31e2559
|
|
| MD5 |
abd182ec07f37a48c2e2daf0a509b472
|
|
| BLAKE2b-256 |
8f2c21ef7cd53ae8278e5de20b661fbd2e7273823f8ceea08e999a895ba279ed
|
Provenance
The following attestation bundles were made for lmux_anthropic-0.5.1.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_anthropic-0.5.1.tar.gz -
Subject digest:
0709fb4d538fd4ab83ae97a8e711db0f362d0fbb6afbfc9223bad411d31e2559 - Sigstore transparency entry: 1771430857
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@61d14eca145cfc6bb0dd419df69f15e9a6b9664c -
Branch / Tag:
refs/tags/lmux-anthropic-v0.5.1 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@61d14eca145cfc6bb0dd419df69f15e9a6b9664c -
Trigger Event:
push
-
Statement type:
File details
Details for the file lmux_anthropic-0.5.1-py3-none-any.whl.
File metadata
- Download URL: lmux_anthropic-0.5.1-py3-none-any.whl
- Upload date:
- Size: 14.0 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 |
86c3df05525bc4931262b59f2fcecab085247e2c56f58c6c658eea3adfe98b65
|
|
| MD5 |
cf0ebfc14d6843e5c993b045dc143537
|
|
| BLAKE2b-256 |
0b0f7ce43747020780f09348ec7221eb156d8af33a7a9cbb88403517a5d1b2fb
|
Provenance
The following attestation bundles were made for lmux_anthropic-0.5.1-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_anthropic-0.5.1-py3-none-any.whl -
Subject digest:
86c3df05525bc4931262b59f2fcecab085247e2c56f58c6c658eea3adfe98b65 - Sigstore transparency entry: 1771430996
- Sigstore integration time:
-
Permalink:
cluebbehusen/lmux@61d14eca145cfc6bb0dd419df69f15e9a6b9664c -
Branch / Tag:
refs/tags/lmux-anthropic-v0.5.1 - Owner: https://github.com/cluebbehusen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@61d14eca145cfc6bb0dd419df69f15e9a6b9664c -
Trigger Event:
push
-
Statement type: