Skip to main content
Monitor Anthropic’s official Python SDK by wrapping the client once with lunary.monitor(client).
1

Install both packages

Python

Learn how to set up the Python SDK.
2

Monitor Anthropic

Wrap Anthropic or AsyncAnthropic once, then keep using the Anthropic client as usual.
3

Supported surface

The monitored client supports the current Anthropic Messages API surface:
  • client.messages.create(...)
  • Raw streaming via client.messages.create(..., stream=True)
  • client.messages.parse(...)
  • client.messages.stream(...)
  • client.beta.messages.create(...)
  • client.beta.messages.parse(...)
  • client.beta.messages.stream(...)
  • client.beta.messages.tool_runner(...)
  • The same monitored surface on AsyncAnthropic
Tool-runner loops appear in Lunary as one LLM run per underlying Anthropic request. Raw streams and helper streams keep the normal Anthropic SDK lifecycle, and Lunary preserves Anthropic content blocks in the run details, including thinking, redacted_thinking, tool_use, tool_result, server_tool_use, and web_search_tool_result, along with token usage and cached input tokens.
4

Typical usage

Structured outputs with Lunary context:
Raw streaming and helper streams:
Beta tool-runner loops:
Anthropic validates the provider-side metadata object. Use Anthropic-supported fields such as user_id there, and use Lunary’s tags, user_id, and user_props for observability context. For Anthropic beta features that require betas=[...], pass the beta headers exactly as Anthropic documents.