@inpolicy/sdk
v0.1.1
Published
Official TypeScript SDK for the InPolicy AI Governance API. Pre-inference policy injection and post-inference output checking for any AI agent.
Readme
@inpolicy/sdk
Official TypeScript SDK for the InPolicy AI Governance API.
InPolicy turns the policies you already author into runtime guardrails for AI agents. The SDK gives you two intervention points on every inference:
- Before —
recordTurn()returns the policies that apply to the current conversation and aninjectionBlockto drop into your system prompt. - After —
checkOutput()reviews the model's draft against active policies and returns violations, a risk score, and an optional suggested redaction.
Install
npm install @inpolicy/sdk
# or
pnpm add @inpolicy/sdkQuickstart
import { InPolicyClient } from '@inpolicy/sdk';
const ip = new InPolicyClient({
apiKey: process.env.INPOLICY_API_KEY!,
});
// Before generation: get policy context
const state = await ip.recordTurn({
sessionId: 'sess_user_123',
turn: { role: 'user', content: 'Can I share our pricing with this prospect?' },
});
// Prepend state.injectionBlock to your system prompt
const completion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: `${SYSTEM_PROMPT}\n\n${state.injectionBlock}` },
{ role: 'user', content: '...' },
],
});
// After generation: check the output
const verdict = await ip.postInference({
sessionId: 'sess_user_123',
output: completion.choices[0].message.content!,
});
if (!verdict.safe) {
// Surface violations, use verdict.suggestedRedaction, or block
}Configuration
| Option | Default | Notes |
|---|---|---|
| apiKey | — | Required. Get from app.inpolicy.ai → Settings → API Keys. |
| baseUrl | https://api.inpolicy.ai/api/v1 | Override for self-hosted backends. |
| timeoutMs | 30000 | Per-call timeout. |
| maxRetries | 2 | Auto-retries on 5xx with exponential backoff. |
API surface
The client exposes the full governance + programmatic-policy-management API:
recordTurn,getConversationState,endConversation— conversation lifecyclepreInference,postInference— single-shot variantscheckToolCall— tool-call governance (opt-in per API key)streamCheckOutput,streamCheckOutputOnce,finalizeStreamingCheck— streaming check_outputlistPolicies,getPolicy,bulkUpsertPolicies,updatePolicy,deletePolicy,publishPolicy— policy cataloguploadDocument,getDocument,waitForDocument— document upload + AI extraction
See the API reference for full request/response shapes.
Related packages
@inpolicy/mcp-server— MCP server for Claude Desktop, Claude Code, Cursor@inpolicy/policy-admin-mcp— MCP server for managing the policy catalog conversationally@inpolicy/cli— CLI for GitOps / CI / shell
License
MIT
