Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sidmanale643/northstar/llms.txt
Use this file to discover all available pages before exploring further.
northstar.auto_instrument() monkey-patches the OpenAI and Anthropic Python client libraries so that every LLM API call is captured as a model span inside the current NorthStar trace — without any changes to the call sites themselves. It must be called before northstar.init() and before any OpenAI or Anthropic client instances are created. Calling it after the libraries have already been imported and instantiated will still patch the class methods, but calling it first guarantees the patch is in place before any client object is used.
auto_instrument() patches class-level methods (Completions.create, AsyncCompletions.create, Responses.create, AsyncResponses.create, Messages.create, AsyncMessages.create). The patch is applied once per process and is idempotent.Quick Start
Anthropic Example
The example below mirrors the NorthStar quick-start. A singleclient.messages.create() call is automatically captured as a model span with all messages, token usage, and cost.
OpenAI Example
Auto-instrumentation covers both the Chat Completions API and the newer Responses API, including their async variants.What Is Captured
Every instrumented call records the following data automatically:| Field | Details |
|---|---|
| Request messages | The full messages array passed to the API, including system prompts |
| Tools / tool_choice | Tool schemas and any tool_choice constraint |
| Model-emitted tool calls | Tool call objects in the assistant message |
| Tool result messages | role: "tool" messages included in subsequent LLM requests |
| Output message | The first choice’s message (Chat Completions) or output_text (Responses API) |
| Token usage | input_tokens, output_tokens, total_tokens stored on the span’s attributes |
| USD cost | Computed via litellm pricing and stored as cost_usd on the span |
| Latency | Wall-clock time from request to response, stored as latency_ms |
| Exceptions | Any exception raised by the API call is recorded and the span is marked ERROR |
USD Cost Tracking
Cost computation requires thelitellm package, which is bundled in the pricing extra:
cost_usd will be absent from span attributes. The pricing_source attribute on the span will be "litellm" when pricing succeeds or "unknown" when the model is not found in litellm’s price list.
Covered Endpoints
| Library | Patched method | Sync | Async |
|---|---|---|---|
openai | chat.completions.create | ✓ | ✓ |
openai | responses.create | ✓ | ✓ |
anthropic | messages.create | ✓ | ✓ |
openai or anthropic package is not installed, the corresponding patch is silently skipped — no error is raised.