SDK · Python 3.10+ / Node 18+
LangChain AI ads integration.
A LangChain callback handler and chain wrapper for monetizing LangChain-powered AI apps. Python and TypeScript.
Install
# Python pip install surfacedd-langchain # TypeScript npm install @surfacedd/langchain
Import
# Python
from surfacedd_langchain import SurfaceddCallbackHandler
# TS
import { SurfaceddCallbackHandler } from "@surfacedd/langchain"Initialize
handler = SurfaceddCallbackHandler(app_id='app_xxx')
Fetch a sponsored answer
result = chain.invoke({'input': user_query}, {'callbacks': [handler]})Features
- Python and TypeScript parity
- Callback handler (works with any chain or agent)
- LangGraph node for advanced workflows
- Tool-call ads for agent action recommendations
- Streaming-safe: ads surface after final answer, not mid-tool-call
Install in three steps
- Install. Python: pip install surfacedd-langchain. TypeScript: npm install @surfacedd/langchain.
- Attach the callback handler. Instantiate SurfaceddCallbackHandler(app_id) and pass it via callbacks=[handler] on any chain.invoke() or agent.run() call.
- Render in your UI. The handler emits on_sponsored_surface events. Consume them in your UI layer and render a clearly-labeled sponsored block.
Frequently asked questions
Does it work with LangGraph?
Yes. We publish a dedicated SurfaceddNode for LangGraph that attaches to any state graph and injects sponsored surfaces at the response node.
Can I monetize agent tool calls?
Yes. Tool-call ads recommend sponsored tools for commercial actions (e.g., "book via Surfacedd Hotel Partner" inside a travel agent). Label compliance and user control are built in.
Does it slow down my chain?
The callback adds a single async fetch after the chain completes — typical overhead is 60–120ms on mid-scenario infrastructure. Set non_blocking=True to run the ad fetch in parallel with rendering.
Related SDKs
Ready to ship ads in your LangChain app?
Join the waitlist for SDK access. 60% revenue share, no minimums, no contracts.