Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Gate LangChain model access to subscribers
npm install @stellartools/langchain-adapter @langchain/core
import { HumanMessage } from "@langchain/core/messages"; import { ChatOpenAI } from "@langchain/openai"; import { shield } from "@stellartools/langchain-adapter"; const model = shield(new ChatOpenAI({ model: "gpt-4o" }), { apiKey: process.env.STELLAR_TOOLS_API_KEY!, customerId: "cus_xxx", productId: "prod_xxx", cacheTTL: 120_000, }); const result = await model.invoke([new HumanMessage("Hello")]);
shield
Runnable
import { StringOutputParser } from "@langchain/core/output_parsers"; import { ChatPromptTemplate } from "@langchain/core/prompts"; const chain = ChatPromptTemplate.fromMessages([["human", "{question}"]]) .pipe( shield(new ChatOpenAI(), { apiKey: process.env.STELLAR_TOOLS_API_KEY!, customerId: "cus_xxx", productId: "prod_xxx", cacheTTL: 120_000, }) ) .pipe(new StringOutputParser()); const answer = await chain.invoke({ question: "What is Stellar?" });
ShieldError
import { ShieldError, shield } from "@stellartools/langchain-adapter"; try { const result = await model.invoke([new HumanMessage("Hello")]); } catch (err) { if (err instanceof ShieldError) { return res.status(403).json({ error: err.message }); } throw err; }