Skip to main content
This page shows how to capture Anthropic API traffic with Moda. Once the SDK is initialized, calls made with the official anthropic (Python) or @anthropic-ai/sdk (Node.js) client are captured automatically, including streaming, tool use, and extended thinking.

Prerequisites

  • A Moda API key (created in the dashboard at Settings → Ingestion keys; shown once at creation)
  • An Anthropic API key
  • Python 3.10 or later, or Node.js 18 or later
  • Node.js only: @anthropic-ai/sdk version 0.18.0 or later

Setup

1

Install the packages

2

Initialize Moda before creating the client

Initialize the SDK first, then construct the Anthropic client. Flush before your process exits so buffered data is sent.
In Node.js, Moda.init() is async and the API key argument is required (it is not read from MODA_API_KEY). If Moda.init() is not awaited, calls made before initialization completes are not captured. In Python, moda.init() is synchronous and also reads the MODA_API_KEY environment variable, so moda.init() with no arguments works when that variable is set.
3

Verify in the dashboard

Run the script, then open Conversations in the dashboard. You should see a conversation with ID session_123 containing the user message and the assistant reply, with model claude-sonnet-4-20250514 and token counts. Analysis signals typically appear within minutes of ingest.

Conversation grouping

Set a conversation ID before the first call of a session — from your session, thread, or run ID — so every call in the session lands in one conversation. Use moda.conversation_id (Python) or Moda.conversationId / Moda.withConversationId() (Node.js). See the Python SDK and the Node.js SDK for the full context APIs.

Streaming

Both messages.stream() and messages.create(..., stream=True) are captured. The SDK records the complete response after the stream finishes, so consume the entire stream.

Tool use

Tool calls are captured automatically: tool_use blocks in assistant messages, and the tool_result blocks you send back in follow-up messages.

Extended thinking

When extended thinking is enabled, thinking content blocks are captured alongside the final text response, in both non-streaming and streaming calls.

Support matrix

Troubleshooting

No conversations appear in the dashboard. Initialize Moda before constructing the Anthropic client, and call moda.flush() (Python) or await Moda.flush() (Node.js) before the process exits. In Node.js, confirm Moda.init() is awaited and the API key starts with moda_sk_. Streaming calls show no assistant message. The response is recorded only after the stream ends. Consume the stream fully; a stream that is abandoned partway is not captured completely. Thinking blocks are missing. Extended thinking requires a model that supports it and the thinking parameter with type: "enabled" and a budget_tokens value. Every request creates a new conversation. Set a conversation ID before the first call of the session (see Conversation grouping above).

Next steps

  • Python SDK — init options, context managers, and instrument controls.
  • Node.js SDK — init options, scoped context, and manual tracing.
  • Amazon Bedrock — capturing Claude models served through Bedrock.
  • Claude Agent SDK — capturing agents built on the Claude Agent SDK (Python).