🀝 Anthropic Integration

Lucidic supports automatic tracking of Anthropic Claude completions in your agent sessions β€” with no extra instrumentation needed.


βš™οΈ How It Works

When you initialize the SDK with:

lai.init(..., providers=["anthropic"])

Lucidic will:

  • Monkey patch anthropic.Client().messages.create
  • Automatically capture each Claude completion as an Event
  • Attach the LLM call to the current active Step

βœ… What Gets Captured

We automatically capture the following when you pass it to anthropic.Client().messages.create:

  • Input: your prompt to Claude (e.g. "What's the capital of France?")
  • Model: the Claude model used (e.g. claude-3-opus, claude-3)
  • Output: the Claude response

Based on your input, we automatically calculate the following:

  • Cost: estimated based on input/output tokens

🧠 Why This Matters

LLM calls are a core part of most agent workflows β€” but without visibility, it’s impossible to debug or optimize:

  • Which call caused the failure?
  • Which step was it part of?
  • How much did it cost?
  • What was the actual response?

This integration gives you full transparency, with zero boilerplate.


πŸ§ͺ Example

import lucidicai as lai
import anthropic

lai.init(
    session_name="claude_task",
    agent_id="your-agent-id",
    lucidic_api_key="your-api-key",
    providers=["anthropic"]
)

client = anthropic.Anthropic()

lai.create_step(state="Planning", goal="Generate research questions")

# This call is automatically tracked!
response = client.messages.create(
    model="claude-3-opus",
    max_tokens=500,
    messages=[{"role": "user", "content": "What are 5 research ideas about climate change?"}]
)

lai.end_step(is_successful=True, action="Generated ideas")

πŸ› οΈ Notes

  • Requires anthropic Python SDK installed (pip install anthropic)
  • Only Client().messages.create is currently patched
  • You must have an active session and step for automatic event logging
  • You can still manually use create_event() or update_event() as needed