Skip to main content
NIM (NVIDIA Inference Microservices) serves models behind an OpenAI-compatible /v1/chat/completions API, so the client you patch is the ordinary openai Python client pointed at a NIM endpoint - a NIM container on your own GPUs (http://localhost:8000/v1) or NVIDIA’s hosted API (https://integrate.api.nvidia.com/v1). What this integration adds over patching the OpenAI client is attribution: traces are stamped framework: "nvidia-nim", so NIM traffic gets its own row in Monitor’s Platforms chart and the framework filters instead of blending into openai. Install the integration extra (it installs the openai client package; there is no separate NIM SDK dependency):

Usage

Call patch_nim_client() once after creating the client. All subsequent chat.completions.create() calls are traced automatically; no changes to individual API calls are needed. Works with both openai.OpenAI and openai.AsyncOpenAI.
A local NIM container needs no real API key; NVIDIA’s hosted endpoint takes your NVIDIA API key (NGC key).

What gets traced

By default, each chat.completions.create() call produces its own trace. NIM reports no prompt-cache fields, so cacheReadTokens/cacheWriteTokens stay unset.

Streaming

Calls made with stream=True are traced too. The patch returns a transparent proxy over the provider’s stream: iterating it, using it as a context manager, calling close(), and reading its attributes all pass straight through to the real stream, and the trace is assembled from the chunks your code actually consumes.
What a streamed trace carries: If your code stops reading early (break) or an error interrupts the stream, the trace records what was streamed up to that point, and an error is recorded as the trace’s error. A stream that is dropped without being closed still records what it saw when it is garbage-collected.

Multi-call agentic loops

Wrap a multi-call loop in with tracer.trace(...) to collapse every chat.completions.create() call made inside it into one trace instead of one trace per call:
Each call inside the span attaches as a real "LLM Call N" child span carrying the NIM model, tokens, and the nvidia-nim label. A patched call made outside any active span opens its own root trace, stamped with span kind llm - it is a bare model call. The patch sees only the model calls. Tool executions and retrievals around them are plain Python code, so record them manually with tracer.trace_tool_call() and tracer.trace_retrieval() - see the Anthropic integration’s tool-use example for the pattern (identical API, different client).

Cost tracking

NIM is typically self-hosted, so there is no per-token provider price to look up. If you want dollar estimates on NIM traces anyway (an internal chargeback rate, or NVIDIA’s hosted API pricing), add the model id to the pricing catalog - unpriced models show no cost rather than a fake $0.00. A NIM endpoint can also serve as a judge or Playground model: register it as a custom provider model with its base_url in the same catalog.

Other routes to AgentX

patch_nim_client is for the raw client. NIM traffic also arrives through integrations you may already run - pick one layer per LLM call so nothing is traced twice:
  • LiteLLM: the nvidia_nim/<model> provider is traced by AgentXLiteLLMLogger (labeled litellm).
  • LangChain: ChatNVIDIA from langchain-nvidia-ai-endpoints is an ordinary chat model, traced by AgentXCallbackHandler (labeled langchain).
  • OpenTelemetry: anything in the NIM/NeMo ecosystem that exports OTLP lands through the OpenTelemetry endpoint.

patch_nim_client() reference

Patching is idempotent, and the guard is shared with patch_openai_client: whichever of the two patched a given client first wins, so patch each client with the integration that matches where its base_url actually points.
Call tracer.flush() before your process exits in scripts or one-shot jobs. In long-running servers it is not required: traces drain automatically in the background.