agentmetrics-anthropic
AgentMetrics integration for Claude Managed Agents (Python). Wrap your session event stream with one tracker and every session reports back to your dashboard when it terminates showing latency, cost, token counts with cache, tool calls, and errors.
Install
pip install agentmetrics-anthropic
Quickstart
import anthropic
from agentmetrics_anthropic import AgentMetricsSessionTracker
client = anthropic.Anthropic()
tracker = AgentMetricsSessionTracker(
agent_id="my-claude-agent",
base_url="http://localhost:8099",
)
# Sync stream
with tracker.stream(client, session_id="sess_...") as stream:
for event in stream:
pass # handle events as normal
tracker.flush()
Async
async with tracker.astream(client, session_id="sess_...") as stream:
async for event in stream:
pass
await tracker.flush()
API
AgentMetricsSessionTracker(agent_id, base_url)
| Parameter | Default | Description |
|---|---|---|
agent_id |
"anthropic-agent" |
Label shown in the dashboard |
base_url |
"http://localhost:8099" |
AgentMetrics server address |
.stream(client, session_id, **kwargs)
Returns a sync context manager. Yields the same events as client.beta.sessions.events.stream(). Emits a run summary on session.status_terminated.
.astream(client, session_id, **kwargs)
Async version of .stream().
.flush(timeout=10.0)
Blocks until all in-flight HTTP requests complete. Call before process exit.
What gets tracked
Each session emits one event to /v1/events when it terminates:
| Field | Description |
|---|---|
status |
success or failed |
duration_ms |
Wall-clock session duration |
input_tokens / output_tokens |
Aggregated across all LLM calls |
cache_read_tokens / cache_write_tokens |
Cache token counts |
llm_calls |
Number of LLM requests in the session |
tool_calls / tool_errors |
Tool usage counts |
tool_names |
Set of tools invoked |
model |
Model name from the first LLM call |
estimated_cost_usd |
Computed from token counts and model pricing |
error |
First 500 chars of the error message on failure |
License
Metadata
Release files for agentmetrics-anthropic 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| agentmetrics_anthropic-0.2.0.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentmetrics_anthropic-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 kB
Release files / agentmetrics_anthropic-0.2.0.tar.gz
| Download URL | agentmetrics_anthropic-0.2.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
99d43ec2b36b5f98824fd7544b186648c889922f863dd38357c2cb954f2f1d51
|
|
BLAKE2b-256 checksum How to use checksums |
5e29f72153ed13fd0380770f01255425dee26983e5b3eb97faf1b77e82102e05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / agentmetrics_anthropic-0.2.0-py3-none-any.whl
| Download URL | agentmetrics_anthropic-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8c4b24dccf457dde919c3b2e1a8443610c229597dd95124b50f3ddcfccf410a
|
|
BLAKE2b-256 checksum How to use checksums |
2c6598b23262e4dd59a1cc351c89056e9c87bd05f530211674efd797b268f06d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|