pledgegateway
v0.1.1
Published
PledgeGateway — Rust-native LLM gateway with prompt compression, caching, cost tracking. TypeScript SDK + CLI.
Maintainers
Readme
pledgegateway
TypeScript SDK for PledgeGateway — Rust-native LLM gateway with prompt compression, caching, and cost tracking.
Install
npm install pledgegatewayQuick Start
import { PledgeGateway } from "pledgegateway";
const gateway = new PledgeGateway({
baseUrl: process.env.PLEDGE_GATEWAY_URL || "http://localhost:8080",
apiKey: process.env.PLEDGE_GATEWAY_API_KEY,
});
// Chat completion
const response = await gateway.chatCompletions({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);React Hooks
import { useChat, useStreamingChat } from "pledgegateway/react";
function Chat() {
const { messages, input, setInput, send, isLoading } = useChat({
baseUrl: "http://localhost:8080",
model: "gpt-4o",
});
return (
<div>
{messages.map((m, i) => <p key={i}>{m.role}: {m.content}</p>)}
<input value={input} onChange={(e) => setInput(e.target.value)} />
<button onClick={send} disabled={isLoading}>Send</button>
</div>
);
}Next.js Middleware
// middleware.ts
import { createMiddleware } from "pledgegateway/middleware";
export const middleware = createMiddleware({
baseUrl: process.env.PLEDGE_GATEWAY_URL || "http://localhost:8080",
});
export const config = {
matcher: ["/api/llm/:path*"],
};API
PledgeGateway
chatCompletions(req)— Chat completionchatCompletionsStream(req)— Streaming chat (async iterator)embeddings(req)— Embeddingsstats()— Gateway statisticshealth()— Health checkmcp(method, params)— MCP JSON-RPC calla2a(method, params)— A2A JSON-RPC callpledgestackStatus()— PledgeStack integration statuspledgestackFlags()— Feature flags from PledgeStack
React Hooks
useChat(options)— Chat with message historyuseStreamingChat(options)— Streaming chat with SSEuseCompletion(options)— Single completionuseGateway(config)— Gateway client instanceuseGatewayStats(config)— Live stats polling
License
MIT
