@krewe/langchain
v0.1.0
Published
LangChain.js bindings for the krewe pay-per-call AI inference network. Exposes Embeddings, an LLM, and Tools backed by /v2/predict on Base. Settles each call in USDC via x402 — no API keys.
Maintainers
Readme
@krewe/langchain
LangChain.js bindings for the krewe pay-per-call AI inference network on Base. Adds an Embeddings class, an LLM class, and three Tool instances backed by the krewe network's /v2/predict endpoint. Every call is paid in USDC via x402 (EIP-3009) — no API keys, no signup.
Status: v0.1.0 — first cut. SDK paths exercised against the live network; the LangChain class surface has not yet been validated inside a complete LangGraph or AgentExecutor flow. If you dogfood and hit issues, open an issue.
Install
pnpm add @krewe/langchain @langchain/coreEmbeddings
import { KreweEmbeddings } from "@krewe/langchain";
const embeddings = new KreweEmbeddings({
privateKey: process.env.AGENT_KEY as `0x${string}`, // Base wallet w/ USDC
});
const vec = await embeddings.embedQuery("krewe is a decentralized inference network");
const vecs = await embeddings.embedDocuments(["doc1 text", "doc2 text", "doc3 text"]);Cost: $0.01 USDC per embedding. Model: Xenova/all-MiniLM-L6-v2, 384-dim.
LLM (verified completion)
import { KreweLLM } from "@krewe/langchain";
const llm = new KreweLLM({
privateKey: process.env.AGENT_KEY as `0x${string}`,
maxTokens: 128,
stop: ["\n###"],
});
const text = await llm.invoke("Summarize: krewe is a decentralized AI network on Base.");
// → "krewe is a network that runs AI tasks across independent nodes..."Cost: $0.05 USDC per call. The completion is byte-equal-consensus across 3 miner nodes (deliberate non-streaming).
Tools (for AgentExecutor / LangGraph)
import { createKreweTools } from "@krewe/langchain";
import { AgentExecutor, createReactAgent } from "langchain/agents";
import { ChatOpenAI } from "@langchain/openai";
const tools = createKreweTools({ privateKey: process.env.AGENT_KEY as `0x${string}` });
const agent = createReactAgent({
llm: new ChatOpenAI({ model: "gpt-4o-mini" }),
tools: [tools.extractEntities, tools.scrapeUrl, tools.complete],
});
const exec = new AgentExecutor({ agent, tools: [tools.extractEntities, tools.scrapeUrl, tools.complete] });
const result = await exec.invoke({
input: "Pull every email from this page: https://www.krewe.world/build",
});Three tools available:
| Tool | Cost | Description |
|----------------------------|----------|------------------------------------------------|
| krewe_extract_entities | $0.005 | Emails / URLs / dates / numbers / phones |
| krewe_scrape_url | $0.020 | Fetch + clean a URL |
| krewe_complete | $0.050 | Verified SLM completion (LaMini-GPT-124M) |
Why this might be useful
- No API key dance. The agent's wallet is the auth. Drops into existing on-chain agents with zero plumbing.
- Per-call on-chain settlement. Every call leaves a Basescan tx hash you can audit.
- Verifiable inference (for
KreweLLM). Three independent miners must produce byte-identical output before the call settles — useful when a single LLM provider shouldn't be a single point of trust.
Links
- Source (MIT): https://github.com/krewe-AI/krewe/tree/main/clients/langchain
- Build docs (Eliza / LangChain / CrewAI): https://www.krewe.world/build
- npm SDK:
@krewe/x402-client
License
MIT.
