pip install amplitude-ai==1.15.0 Copy PIP instructions
Agent analytics for Amplitude. Track every LLM call, user message, tool call, and quality signal as events in your Amplitude project — then build funnels, cohorts, and retention charts across AI and product behavior alongside your existing product events.
The canonical SDK reference lives in Amplitude Docs:
That page covers installation, the full event taxonomy, sessions, tools, spans, scores, multi-agent delegation, streaming, edge runtimes, provider-specific notes (OpenAI, AzureOpenAI, Anthropic, Gemini, Bedrock, Mistral, Anthropic Managed Agents), cost and prompt-cache handling, privacy modes, content shaping, verification with MockAmplitudeAI, and the complete API.
import os from amplitude_ai import AmplitudeAI from amplitude_ai.providers.openai import OpenAI ai = AmplitudeAI(api_key=os.environ["AMPLITUDE_AI_API_KEY"]) openai = OpenAI(amplitude=ai, api_key=os.environ["OPENAI_API_KEY"]) agent = ai.agent("my-agent") async def handle_chat(user_id: str, session_id: str, messages: list): session = agent.session(user_id=user_id, session_id=session_id) with session.run() as s: s.track_user_message(messages[-1]["content"]) response = await openai.chat.completions.create(model="gpt-4o", messages=messages) return response.choices[0].message.content ai.flush() Emits [Agent] User Message, [Agent] AI Response, and [Agent] Session End — tied to user_id and session_id. Auto-captures model, tokens, cost, and latency on the AI Response. Read the SDK reference for the rest.
Each wrapper records request, response, tokens, latency, and cost automatically:
from amplitude_ai.providers import openai, anthropic, azure_openai, gemini, bedrock, mistral See Auto-instrument provider calls for the full table and per-provider notes (Anthropic Managed Agents).
Provider wrappers + delegation: Inside session.run_as() / session.arun_as(), provider wrappers suppress auto [Agent] User Message emission so that internal role: "user" prompts in delegation calls don't create spurious user turns.
OpenAI-compatible gateways and OTEL partners — no special SDK build required:
For OTLP partners, emit at least these three GenAI attributes so cost and model fill rates work: gen_ai.request.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens.
Tag gateway traffic with context={"ingestion_path": "gateway", "gateway": "openrouter"|"litellm"|"requesty"} (existing [Agent] Context — no new schema fields). Full recipes: amplitude-ai.md Works with.
Use the existing OpenAI-compatible wrapper; there is no separate providers/fireworks.py:
from amplitude_ai import wrap from openai import OpenAI client = wrap( OpenAI( api_key=os.environ["FIREWORKS_API_KEY"], base_url="https://api.fireworks.ai/inference/v1", ), amplitude=ai, ) Within an Agent Analytics session, Chat Completions and Responses API calls capture the provider-owned response ID on the assistant event. Path B remains Fireworks-managed OTLP using gen_ai.response.id; it does not require the AI SDK.
When a single user action triggers multiple parallel LLM calls, use arun_as() to delegate:
async with orchestrator.session(session_id=sid) as s: s.new_trace() s.track_user_message("Generate plan from quiz results", context=state) async def run_child(child): async with s.arun_as(child) as _cs: return await client.chat.completions.create(model="gpt-4o", messages=[...]) a, b = await asyncio.gather(run_child(scorer), run_child(matcher)) s.track_ai_message(content=assemble(a, b), model="gpt-4o", provider="openai") This ensures one trace, one user turn, one AI response — regardless of how many internal LLM calls are dispatched. See Step 3g-b in the instrumentation guide for details.
amplitude-ai Paste the printed prompt into Cursor, Claude Code, GitHub Copilot, or Codex. The agent reads the in-repo instrumentation guide (amplitude-ai.md), scans your project, discovers your LLM call sites, and instruments everything — provider wrappers, sessions, multi-agent delegation, tools, scoring, and a verification test.
Three content modes control what reaches Amplitude:
Full details and per-provider redaction recipes at Choose a privacy mode.
Route all instrumentation through OpenTelemetry spans. The SDK's AmplitudeEventSpanProcessor maps GenAI semantic convention spans into [Agent] events. Provider wrappers and decorators continue to work — de-duplication prevents double-counting.
ai = AmplitudeAI(api_key=os.environ["AMPLITUDE_AI_API_KEY"]) ai.enable_otel(default_user_id="fallback-uid") Requires optional deps: pip install opentelemetry-api opentelemetry-sdk
Use @observe(type="tool"|"agent"|"llm"|"span") to create typed OTEL spans that map to the corresponding [Agent] event types. Use ai.using_attributes() to propagate context to spans within a block.
MockAmplitudeAI.summary() prints a fill-rate report showing which of the key Agent Analytics fields (identity, session, model, provider, latency, tokens, cost) are populated across your captured events:
from amplitude_ai.testing import MockAmplitudeAI mock = MockAmplitudeAI() agent = mock.agent("test-agent") with agent.session(user_id="u1", session_id="s1") as s: s.track_user_message("hello") s.track_ai_message("response", "gpt-4o-mini", "openai", 150) print(mock.summary())
Two rules apply to every [Agent] * event and every property listed below — read them before interpreting event_time or [Agent] Latency Ms:
Streaming. For streaming responses, the SDK emits [Agent] AI Response at stream finalize (last token received). [Agent] Latency Ms covers the full stream duration. [Agent] TTFB Ms covers only the time to the first token — measure perceived responsiveness with TTFB, and total generation time with Latency Ms.
Latency-less events. [Agent] User Message, [Agent] Session End, and [Agent] Score do not carry [Agent] Latency Ms. Ingest treats these as point-in-time (span.start_time == span.end_time == event_time).
Event-specific properties for [Agent] User Message (in addition to common properties above).
[Agent] Session Record is emitted automatically by the server-side enrichment pipeline — do not send this event from your code.
[Agent] Topic Classification is DEPRECATED — replaced by [Agent] Evaluator Result. Retained in the catalog for historical data only; the enrichment pipeline no longer emits this event.
[Agent] Evaluator Result is emitted automatically by the server-side enrichment pipeline — do not send this event from your code.
About this README. The long-form SDK reference previously hosted here moved to the canonical docs page so npm, PyPI, and the in-product docs surface stay aligned. The full instrumentation guide consumed by AI coding agents is preserved at amplitude-ai.md in this repo.
all anthropic azure bedrock crewai dev docs fastapi gemini langchain llamaindex mcp mistral openai openai-agents otel tokens
agents ai amplitude analytics anthropic llm observability openai
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.




