Skip to main content
This page shows how to capture OpenAI API traffic with Moda. Once the SDK is initialized, calls made with the official openai client are captured automatically — no changes to the calls themselves.

Prerequisites

  • A Moda API key (created in the dashboard at Settings → Ingestion keys; shown once at creation)
  • An OpenAI API key
  • Python 3.10 or later, or Node.js 18 or later
  • Node.js only: openai package version 4.0.0 or later

Setup

1

Install the packages

2

Initialize Moda before creating the client

Initialize the SDK first, then construct the OpenAI 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 gpt-4o and token counts. Analysis signals (emotion, tool failures) 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

Streaming chat completions are captured automatically. The SDK records the complete response after the stream finishes, so consume the entire stream.

Tool use

Function calling is captured automatically, including the tool call arguments in the assistant message and any role: "tool" result messages you send in follow-up calls.

Embeddings (Python only)

The Python SDK captures client.embeddings.create() calls. The Node.js SDK does not instrument embeddings — it captures chat completions only.
Python
To capture embeddings from a Node.js app, send them yourself via OpenTelemetry or the HTTP API.

Support matrix

OpenAI-compatible endpoints reached through the openai client with a custom base URL are also captured — see Azure OpenAI and OpenRouter.

Troubleshooting

No conversations appear in the dashboard. Initialize Moda before constructing the OpenAI 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. Embeddings calls are missing in Node.js. Expected — the Node.js SDK instruments chat completions only. Use the Python SDK, OpenTelemetry, or the HTTP API. 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.
  • OpenRouter — capture other models through the same openai client.
  • Conversations — how captured conversations appear in the dashboard.