NorthStar is designed to be operational in minutes. You install one package, set two environment variables, add two lines of initialization code, and every LLM call your agent makes is automatically captured — messages, token usage, USD cost, latency, and errors included. This guide walks you from a blank terminal to a fully traced agent run.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.
Install the SDK
Install
northstar-ai from PyPI. The uv package manager is recommended for speed, but pip works equally well.Set your environment variables
NorthStar needs two credentials: an API key and your Supabase project reference. Set them as environment variables before starting your agent process.You can also place these in a
.env file at your project root — NorthStar uses python-dotenv and will pick them up automatically.Both
NORTHSTAR_API_KEY and NORTHSTAR_PROJECT_ID are required for the SDK to send data. If either is missing, the SDK falls back to no-op mode and your agent continues normally.Initialize with auto-instrumentation
Call
northstar.auto_instrument() before creating your LLM client, then call northstar.init() with your credentials. Both calls must happen once at application startup.auto_instrument() patches the OpenAI chat/responses endpoints and Anthropic messages.create. It captures:- Request messages, tools, and tool choice
- Model-emitted tool calls and tool result messages included in later requests
- Output messages and token usage
- USD cost (when the
pricingextra is installed) - Latency and exceptions
Run a traced agent
With auto-instrumentation active you can run your agent as normal — every LLM call is captured automatically. Use the Manual tracing with decorators:Use Context manager form with explicit input/output:
@northstar.trace decorator to wrap your top-level agent function and the @northstar.observe decorator to create child spans around any sub-step.Auto-instrumented Anthropic example:@northstar.trace to start a root run and @northstar.observe to nest child spans inside it. You can log events, metrics, and metadata anywhere inside the active trace.Flush and view your traces
The SDK batches records and sends them on a background thread. Call Once flushed, open your NorthStar dashboard to see the session, run, spans, and any events or metrics you logged.
northstar.flush() at the end of a script (or test) to drain the queue synchronously before the process exits.Manual Model Call Recording
When you’re not using auto-instrumentation, or when you want more control over what gets recorded, use thenorthstar.model_call() context manager inside an active trace to capture LLM input messages, output messages, and token usage manually.
northstar.model_call() opens a span of kind MODEL inside the active run. The ModelSpan object it yields exposes three methods:
| Method | Purpose |
|---|---|
llm.record_input_messages(messages) | Record the list of messages sent to the model |
llm.record_output_message(message) | Record the model’s response message |
llm.record_usage(prompt_tokens=..., completion_tokens=...) | Record token counts (cost is computed automatically when pricing extra is installed) |
Log Correlation
Callnorthstar.current_trace_id() anywhere inside an active @northstar.trace context to get the current run ID as a string. Attach it to your application log lines so you can jump from a log entry directly to the corresponding trace in the dashboard.