Metadata-Version: 2.4
Name: agentmeter-sdk
Version: 0.1.0
Summary: Track LLM costs per user. Open source SDK for AgentMeter.
Author: Edesto
License: MIT
Project-URL: Homepage, https://agentmeter.com
Project-URL: Repository, https://github.com/GregorKonzett/agentmeter-sdk
Project-URL: Documentation, https://github.com/GregorKonzett/agentmeter-sdk#readme
Project-URL: Issues, https://github.com/GregorKonzett/agentmeter-sdk/issues
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28.0
Provides-Extra: openai
Requires-Dist: openai>=1.0.0; extra == "openai"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
Provides-Extra: all
Requires-Dist: openai>=1.0.0; extra == "all"
Requires-Dist: anthropic>=0.18.0; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: pytest-mock>=3.10; extra == "dev"
Requires-Dist: responses>=0.23; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: openai>=1.0.0; extra == "dev"
Requires-Dist: anthropic>=0.18.0; extra == "dev"

# AgentMeter SDK

Track LLM costs per user. The official Python SDK for [AgentMeter](https://agentmeter.com).

AgentMeter automatically tracks token usage across OpenAI and Anthropic API calls, attributes costs to individual users, and reports them to your AgentMeter dashboard.

## Installation

```bash
pip install agentmeter-sdk
```

With provider-specific extras:

```bash
pip install agentmeter-sdk[openai]
pip install agentmeter-sdk[anthropic]
pip install agentmeter-sdk[all]
```

## Quick Start

```python
import agentmeter

# Initialize before creating any LLM clients
agentmeter.init(api_key="am_live_xxx")

from openai import OpenAI
client = OpenAI()

# Wrap LLM calls with identify() to attribute usage to a user
with agentmeter.identify(user_id="user_123"):
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}],
    )
```

That's it. Token usage is automatically captured and sent to your AgentMeter dashboard.

## Usage

### Initialization

Call `agentmeter.init()` **before** creating any LLM client instances. This patches the OpenAI and Anthropic libraries to capture usage data.

```python
agentmeter.init(
    api_key="am_live_xxx",   # Required. Get this from your dashboard.
    enabled=True,            # Disable to turn off tracking (e.g. in tests).
    debug=False,             # Print events to console instead of sending them.
)
```

### Identifying Users

Use `identify()` as a context manager or decorator to associate LLM calls with a user:

```python
# Context manager
with agentmeter.identify(user_id="user_123"):
    response = client.chat.completions.create(...)

# Decorator
@agentmeter.identify(user_id="user_123")
def handle_request():
    return client.chat.completions.create(...)
```

You can optionally pass a `session_id` to group multiple LLM calls into a single session:

```python
with agentmeter.identify(user_id="user_123", session_id="sess_abc"):
    response = client.chat.completions.create(...)
```

### Supported Providers

| Provider   | Sync | Async | Streaming |
|------------|------|-------|-----------|
| OpenAI     | Yes  | Yes   | Yes       |
| Anthropic  | Yes  | Yes   | Yes       |

### Shutdown

Flush pending events before your process exits:

```python
agentmeter.shutdown()
```

## License

MIT
