Metadata-Version: 2.4
Name: rudderstack-ai
Version: 0.17.0
Summary: Automatic RudderStack AI events and MCP server events (spec v0.4) for OpenAI, the OpenAI Agents SDK, Anthropic, Amazon Bedrock, Google Gen AI, LiteLLM, LangChain and the Claude Agent SDK.
Keywords: rudderstack,analytics,ai,llm,openai,anthropic,gemini,google,litellm,openrouter,langchain,claude,mcp
Author: RudderStack
Author-email: RudderStack <sdk@rudderstack.com>
License-Expression: MIT
License-File: LICENSE.md
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: rudderstack-ai[openai,anthropic,bedrock,google-genai,langchain,claude-agent-sdk,openai-agents,litellm,dspy,mcp] ; extra == 'all'
Requires-Dist: anthropic>=1.0.0,<2 ; extra == 'anthropic'
Requires-Dist: boto3>=1.37.24,<2 ; extra == 'bedrock'
Requires-Dist: botocore>=1.37.24,<2 ; extra == 'bedrock'
Requires-Dist: jsonschema>=4.18.0,<5 ; extra == 'check'
Requires-Dist: claude-agent-sdk>=0.2.82,<0.3 ; extra == 'claude-agent-sdk'
Requires-Dist: crewai>=1.15.39,<2 ; extra == 'crewai'
Requires-Dist: dspy>=3.4.1,<4 ; extra == 'dspy'
Requires-Dist: google-genai>=2.0.0,<3 ; extra == 'google-genai'
Requires-Dist: langchain-core>=1.2.0,<2 ; extra == 'langchain'
Requires-Dist: litellm>=1.88.6,<2 ; extra == 'litellm'
Requires-Dist: mcp>=1.30.0,<3 ; extra == 'mcp'
Requires-Dist: openai>=2.0.0,<4 ; extra == 'openai'
Requires-Dist: openai-agents>=0.8.4,<0.27 ; extra == 'openai-agents'
Requires-Dist: opentelemetry-api>=1.30.0,<2 ; extra == 'tracing'
Requires-Dist: opentelemetry-sdk>=1.30.0,<2 ; extra == 'tracing'
Requires-Dist: opentelemetry-exporter-otlp-proto-common>=1.30.0,<2 ; extra == 'tracing'
Maintainer: RudderStack
Maintainer-email: RudderStack <sdk@rudderstack.com>
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/rudderlabs/ai-sdk-python
Project-URL: Repository, https://github.com/rudderlabs/ai-sdk-python
Project-URL: Issues, https://github.com/rudderlabs/ai-sdk-python/issues
Project-URL: Changelog, https://github.com/rudderlabs/ai-sdk-python/blob/main/CHANGELOG.md
Provides-Extra: all
Provides-Extra: anthropic
Provides-Extra: bedrock
Provides-Extra: check
Provides-Extra: claude-agent-sdk
Provides-Extra: crewai
Provides-Extra: dspy
Provides-Extra: google-genai
Provides-Extra: langchain
Provides-Extra: litellm
Provides-Extra: mcp
Provides-Extra: openai
Provides-Extra: openai-agents
Provides-Extra: tracing
Description-Content-Type: text/markdown

# rudderstack-ai

[![CI](https://github.com/rudderlabs/ai-sdk-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rudderlabs/ai-sdk-python/actions/workflows/ci.yml)

## 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)](spec/ai-events-v0.4.schema.json) through the
RudderStack client your app already uses.

```text
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](docs/integrations.md#installation-extras)).

```bash
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`](https://github.com/rudderlabs/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

```python
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()](docs/events.md#ai_user_action).

In a script, worker or serverless handler, call `rudderstack.ai.flush()` before exiting
([Serverless and workers](docs/api.md#serverless-and-workers)).

## Integrations

Use one integration per call path.

| Integration | Entry point | Page |
| --- | --- | --- |
| OpenAI / Azure / compatible gateways | `wrap_openai` | [Reference](docs/integrations.md#openai) |
| Anthropic | `wrap_anthropic` | [Reference](docs/integrations.md#anthropic) |
| Google Gen AI | `wrap_google_genai` | [Reference](docs/integrations.md#google-gen-ai-gemini-and-vertex-ai) |
| Bedrock Converse | `wrap_bedrock` | [Reference](docs/integrations.md#amazon-bedrock-converse) |
| LangChain / LangGraph / Deep Agents | `RudderStackCallbackHandler` | [Reference](docs/integrations.md#langchain-and-langgraph) |
| Claude Agent SDK | `tracked_query`, `tracked_messages` | [Reference](docs/integrations.md#claude-agent-sdk) |
| OpenAI Agents SDK | `tracked_run`, `tracked_run_sync`, `tracked_run_streamed` | [Reference](docs/integrations.md#openai-agents-sdk) |
| CrewAI | `instrument_crewai` | [Reference](docs/integrations.md#crewai) |
| LiteLLM | `instrument_litellm` | [Reference](docs/integrations.md#litellm) |
| DSPy tools | `instrument_dspy` | [Reference](docs/integrations.md#dspy) |
| MCP servers | `wrap_mcp_server` | [Reference](docs/mcp.md) |
| Native OpenTelemetry frameworks | `register_tracing(product_events=True)` | [Reference](docs/tracing.md#frameworks-through-opentelemetry) |

## Documentation

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

[`examples/`](examples/README.md) 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](docs/integrations.md#compatibility), [adapter
limits](docs/integrations.md#known-limitations), [MCP limits](docs/mcp.md#limits) and
[tracing limits](docs/tracing.md#one-span-per-call-with-the-span-processor).

## Contributing, security and license

See [CONTRIBUTING.md](CONTRIBUTING.md) and [RELEASING.md](RELEASING.md).
Report security issues as described in [SECURITY.md](SECURITY.md).

[MIT](LICENSE.md)
