Metadata-Version: 2.4
Name: lmux-aws-bedrock
Version: 0.4.2
Summary: AWS Bedrock provider for lmux
Keywords: llm,ai,aws,bedrock,language-model
Author: Connor Luebbehusen
Author-email: Connor Luebbehusen <connor@luebbehusen.dev>
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Dist: lmux
Requires-Dist: boto3~=1.42
Requires-Dist: aiobotocore~=3.3.0 ; extra == 'async'
Requires-Python: >=3.13
Project-URL: Homepage, https://github.com/cluebbehusen/lmux
Project-URL: Source, https://github.com/cluebbehusen/lmux/tree/main/packages/lmux-aws-bedrock
Project-URL: Issues, https://github.com/cluebbehusen/lmux/issues
Provides-Extra: async
Description-Content-Type: text/markdown

# lmux-aws-bedrock

AWS Bedrock provider for [lmux](https://github.com/cluebbehusen/lmux). Uses [boto3](https://pypi.org/project/boto3/), [aiobotocore](https://pypi.org/project/aiobotocore/), and the Converse API.

Supports chat completions, streaming, and embeddings.

Part of the [lmux](https://github.com/cluebbehusen/lmux) ecosystem: standardized interface, cost tracking on every response, and registry-based routing across providers.

## Optional Extras

- `lmux-aws-bedrock[async]`: async support via `aiobotocore`

## Auth

Uses boto3's default credential chain (env vars, AWS config, instance metadata). No extra setup needed if your AWS credentials are already configured.

```python
from lmux_aws_bedrock import BedrockProvider

provider = BedrockProvider()

# Or specify a region
provider = BedrockProvider(region="us-east-1")
```

For explicit session configuration:

```python
from lmux_aws_bedrock import BedrockSessionAuthProvider

provider = BedrockProvider(auth=BedrockSessionAuthProvider(profile_name="my-profile"))
```

## Usage

### Chat

```python
from lmux import UserMessage

response = provider.chat("anthropic.claude-sonnet-4-20250514-v1:0", [UserMessage(content="Hello")])
print(response.content)
print(response.cost)
```

### Streaming

```python
for chunk in provider.chat_stream("anthropic.claude-sonnet-4-20250514-v1:0", [UserMessage(content="Hello")]):
    if chunk.delta:
        print(chunk.delta, end="")
```

### Embeddings

```python
response = provider.embed("amazon.titan-embed-text-v2:0", "Hello")
print(response.embeddings)
```

### Async

Requires the `[async]` extra. All methods have async variants: `achat`, `achat_stream`, `aembed`.

Bedrock also supports lmux `response_format`, mapped to Converse `outputConfig.textFormat`.

### Registry

Use with the lmux registry to route across multiple providers:

```python
from lmux import Registry

registry = Registry()
registry.register("bedrock", provider)
response = registry.chat("bedrock/anthropic.claude-sonnet-4-20250514-v1:0", messages)
```

## Provider Params

```python
from lmux_aws_bedrock import BedrockParams, GuardrailConfig

response = provider.chat(
    "anthropic.claude-sonnet-4-20250514-v1:0",
    messages,
    provider_params=BedrockParams(
        guardrail_config=GuardrailConfig(
            guardrail_identifier="my-guardrail",
            guardrail_version="1",
        ),
    ),
)
```

| Parameter                               | Type              | Description                      |
| --------------------------------------- | ----------------- | -------------------------------- |
| `guardrail_config`                      | `GuardrailConfig` | Bedrock guardrail to apply       |
| `additional_model_request_fields`       | `dict`            | Extra fields passed to the model |
| `additional_model_response_field_paths` | `list[str]`       | Extra response fields to return  |

## Constructor Options

```python
BedrockProvider(
    auth=...,          # AuthProvider, default: BedrockEnvAuthProvider()
    region=...,        # AWS region
    endpoint_url=...,  # Custom endpoint URL
)
```
