Skip to main content

rudderstack-ai

CI

What it is

Product analytics for the AI features of a Python backend. rudderstack-ai observes your OpenAI, OpenAI Agents SDK, Anthropic, Amazon Bedrock, Google Gen AI, LiteLLM, LangChain / LangGraph or Claude Agent SDK calls, and your MCP servers, and sends the standard AI events (spec v0.4) through the RudderStack client your app already uses.

your request handler ── ai_interaction ── wrapped client / LangChain handler / tracked_query
                              │
                              └─ your rudder-sdk-python client ─▶ RudderStack ─▶ warehouse, destinations, audiences

Server-side only. Events land alongside your product events with the same userId for funnels, retention and audiences ("users whose refund questions went unresolved").

Install

Python 3.12 or later. Install the extra for each library you use (extras and compatibility).

pip install "rudderstack-ai[openai]==0.15.0"  # or: uv add "rudderstack-ai[openai]==0.15.0"

No dependencies of its own. Events use your rudder-sdk-python client (rudderstack.analytics), 2.1.4 or later: earlier releases refuse a message over 32 KiB as they send it (ASCII-escaped, with their own fields), so a non-ASCII event within the budget can be refused. The package never creates one.

Quickstart

import rudderstack.analytics as rudder_analytics
from openai import OpenAI

import rudderstack.ai
from rudderstack.ai import ai_interaction
from rudderstack.ai.openai import wrap_openai

rudder_analytics.write_key = "<WRITE_KEY>"
rudder_analytics.dataPlaneUrl = "<DATA_PLANE_URL>"
rudderstack.ai.configure(analytics=rudder_analytics)  # once, at startup

client = wrap_openai(OpenAI())


def answer(user_id: str, chat_id: str, question: str) -> dict[str, str | None]:
    with ai_interaction(user_id=user_id, conversation_id=chat_id, feature="support_bot") as interaction:
        reply = client.chat.completions.create(
            model="gpt-4.1-mini", messages=[{"role": "user", "content": question}]
        )
        interaction.set_outcome("resolved")
    return {"answer": reply.choices[0].message.content, "interaction_id": interaction.id}

This sends ai_user_prompt_created and ai_response_received for the answer. Return interaction.id with the answer, then report what the user did with it through track_action().

In a script, worker or serverless handler, call rudderstack.ai.flush() before exiting (Serverless and workers).

Integrations

Use one integration per call path.

Integration Entry point Page
OpenAI / Azure / compatible gateways wrap_openai Reference
Anthropic wrap_anthropic Reference
Google Gen AI wrap_google_genai Reference
Bedrock Converse wrap_bedrock Reference
LangChain / LangGraph / Deep Agents RudderStackCallbackHandler Reference
Claude Agent SDK tracked_query, tracked_messages Reference
OpenAI Agents SDK tracked_run, tracked_run_sync, tracked_run_streamed Reference
CrewAI instrument_crewai Reference
LiteLLM instrument_litellm Reference
DSPy tools instrument_dspy Reference
MCP servers wrap_mcp_server Reference
Native OpenTelemetry frameworks register_tracing(product_events=True) Reference

Documentation

Page What it covers
API Configuration, identity, interactions, recording, streaming, flush, shutdown and troubleshooting
Events Event properties, classification, scores, sampling, pricing and credits
Integrations Adapters, extras, compatibility and known limits
MCP servers Setup, protocols, identity, tool events and observation limits
Tracing SDK spans, OpenTelemetry export, joins, setup and limits
Privacy Capture policy, masking, custom properties, serialization and limits
Migration Upgrade notes, recorder and exact migration-check commands
Client events Client/server ownership and joins
Performance Overhead, benchmarks, load, delivery and memory limits
Examples Runnable apps and test commands

examples/ includes an app per integration, a background agent, three tracing apps and a full-stack chat app using FastAPI, Anthropic and the RudderStack JavaScript SDK. Run with your API keys or offline with the bundled mock server.

Compatibility

Python 3.12 or later; tested in CI on 3.12, 3.13 and 3.14. See the supported and tested versions, adapter limits, MCP limits and tracing limits.

Contributing, security and license

See CONTRIBUTING.md and RELEASING.md. Report security issues as described in SECURITY.md.

MIT

Metadata

Release files for rudderstack-ai 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rudderstack-ai 0.16.0
File Size Uploaded Provenance Actions
rudderstack_ai-0.16.0.tar.gz 385.8 kB With provenance Details for rudderstack_ai-0.16.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rudderstack-ai 0.16.0
File Interpreter ABI Platform Actions
rudderstack_ai-0.16.0-py3-none-any.whl Python 3 none any Details for rudderstack_ai-0.16.0-py3-none-any.whl

Total release size: 798.4 kB

Release files / rudderstack_ai-0.16.0.tar.gz

Download URL rudderstack_ai-0.16.0.tar.gz
Size 385.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9f403e6b453e194259acb781881eea8c9a6b6cfe9307c7c352add1bc2939cf25
BLAKE2b-256 checksum
How to use checksums
a82b680ca87a66c95900929f6bb1fd9a1b98fe07d62f0afbb165939e800cb426
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / rudderstack_ai-0.16.0-py3-none-any.whl

Download URL rudderstack_ai-0.16.0-py3-none-any.whl
Size 412.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81a86c0a7db2375a611db7e7d5375744a37dd7931bf6086625082c7be770bf66
BLAKE2b-256 checksum
How to use checksums
43eb854fe5c0a49e1414ad2d184c1a81ec1410991054d470152da327482e5b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for rudderstack-ai 0.16.0

Provenance

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rudderstack_ai-0.16.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page