SDK Wrappers
agents-chain ships Proxy wrappers for the OpenAI and Anthropic SDKs. These intercept API calls and gate them through the auth pipeline.
OpenAI Wrapper
import OpenAI from 'openai';
import { AppChain } from 'agents-chain';
const chain = await AppChain.create({
providerName: 'openai-service',
issuer: 'https://myservice.com',
capabilities: [
{
name: 'chat.completions.create',
description: 'Create a chat completion',
inputSchema: { type: 'object', properties: {} },
outputSchema: { type: 'object' },
},
],
});
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const grants = [
{ capability: 'chat.completions.create', status: 'active' },
];
// Wrap the SDK — method paths are mapped to capability names
const secured = chain.openai(openai, grants);
// This goes through the auth pipeline before reaching OpenAI
const response = await secured.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }],
});
Anthropic Wrapper
import Anthropic from '@anthropic-ai/sdk';
import { AppChain } from 'agents-chain';
const chain = await AppChain.create({
providerName: 'anthropic-service',
issuer: 'https://myservice.com',
capabilities: [
{
name: 'messages.create',
description: 'Create a message',
inputSchema: { type: 'object', properties: {} },
outputSchema: { type: 'object' },
},
],
});
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const grants = [
{ capability: 'messages.create', status: 'active' },
];
const secured = chain.anthropic(anthropic, grants);
const response = await secured.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
How It Works
The wrappers use JavaScript Proxy to intercept nested property access. When you call secured.chat.completions.create(args), the wrapper:
- Maps the path
chat.completions.createto a capability name - Runs the full auth pipeline (token mint → 11-step verify → constraints)
- Calls the real SDK method if auth passes
- Records the call in the audit log
Constraint enforcement works on the SDK call arguments. You can restrict which models, parameters, or inputs an agent is allowed to use.