Skip to main content

Overview

Moda automatically tracks your Anthropic Claude API calls. Messages, streaming, extended thinking, tool use, and content blocks are all captured with no additional code required.

Setup

pip install moda-ai anthropic
import moda
from anthropic import Anthropic

moda.init("YOUR_MODA_API_KEY")

client = Anthropic()
response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

moda.flush()

Supported Features

FeatureCaptured
MessagesYes
Streaming (messages.stream)Yes
Extended thinkingYes (captured as thinking content blocks)
Tool useYes (captured as tool_use / tool_result content blocks)
System promptsYes
Content blocks (text, image)Yes
Token usageYes (input, output, reasoning tokens)
Model nameYes (request and response)

Extended Thinking

When using extended thinking, reasoning tokens and thinking content blocks are automatically captured.
response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000,
    },
    messages=[{"role": "user", "content": "Explain quantum computing"}]
)
Moda captures:
  • The thinking content as thinking content blocks
  • Reasoning token count for cost tracking
  • The final text response

Tool Use

Anthropic tool use is automatically captured with full request/response details:
response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    tools=[{
        "name": "get_weather",
        "description": "Get the weather for a location",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            }
        }
    }],
    messages=[{"role": "user", "content": "What's the weather in London?"}]
)

Streaming

Streaming is fully supported:
with client.messages.stream(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Count to 5"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="")

Troubleshooting

Data not appearing?
  • Ensure moda.init() is called before creating the Anthropic client
  • Call moda.flush() (Python) or await Moda.flush() (Node.js) before exit
  • Verify your API key is correct
Extended thinking not captured?
  • Ensure you’re using a model that supports extended thinking
  • Check that the thinking parameter is properly configured
For full SDK documentation, see the Python SDK or Node.js SDK guides.