Prerequisites
Choose your language:- Python
- JavaScript
- Java
- Python 3.9 or higher
- An OpenAI API key (or another LLM provider)
Installation
Install OpenInference instrumentation
Install the OpenInference instrumentation library for your framework:
- Python
- JavaScript
- Java
Replace
openinference-instrumentation-openai with the instrumentation for your framework:- LangChain:
openinference-instrumentation-langchain - LlamaIndex:
openinference-instrumentation-llama-index - Anthropic:
openinference-instrumentation-anthropic - See all Python instrumentations
Start Phoenix server
Phoenix is an open-source AI observability platform that runs entirely on your machine. Start the server to collect traces:Phoenix will start on
- Python
- JavaScript
- Java
http://localhost:6006. Open this URL in your browser.Instrument your application
Create a file with the following code to instrument your first LLM call:
- Python
- JavaScript
- Java
Create Run the application:
app.py:app.py
What’s captured?
OpenInference automatically captures:Messages
Full conversation history including system prompts, user messages, and assistant responses
Token counts
Prompt tokens, completion tokens, cached tokens, and reasoning tokens
Model parameters
Temperature, max tokens, top-p, and other invocation parameters
Costs
Estimated costs for prompt and completion tokens in USD
Timing
Start time, end time, and duration with nanosecond precision
Errors
Exception messages and stack traces when calls fail
Advanced example with context
Add session tracking, user IDs, and custom metadata to your traces:- Python
- JavaScript
- Java
Streaming example
OpenInference supports streaming LLM responses:- Python
- JavaScript
Set
stream_options={"include_usage": True} to capture token counts when streaming (requires openai>=1.26).Next steps
Python instrumentations
Explore all 30+ Python instrumentation libraries
JavaScript instrumentations
Explore JavaScript/TypeScript instrumentations
Privacy controls
Configure data masking and PII protection
Concepts
Learn about traces, spans, and attributes
