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:
openaipackage 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.
3
Verify in the dashboard
Run the script, then open Traces in the dashboard. You should see a trace 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.Trace grouping
Set a trace ID — theconversation_id field — before the first call of a session or run, from your session, thread, job, or run ID, so every call lands in one trace. 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 anyrole: "tool" result messages you send in follow-up calls.
Embeddings (Python only)
The Python SDK capturesclient.embeddings.create() calls. The Node.js SDK does not instrument embeddings — it captures chat completions only.
Python
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 traces appear in the dashboard. Initialize Moda before constructing the OpenAI client, and callmoda.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 trace. Set a trace ID before the first call of the session (see Trace 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
openaiclient. - Traces — how captured traces appear in the dashboard.