TypeScript SDK
Certified Vercel AI SDK, OpenAI Agents SDK, and Claude Agent SDK recipes.
Stacklink supplies executable, governed tools. Your selected agent harness owns the model call, tool loop, and final answer.
npm install @stacklink/sdkCreate a project API key in Stacklink Overview, keep it in STACKLINK_API_KEY, and use the complete recipe for your harness below. The API key is for code using the SDK; MCP app connections use OAuth instead.
Vercel AI SDK
Install the Stacklink SDK with the selected harness:
npm install @stacklink/sdk ai@^7.0.0 @ai-sdk/openai@^4.0.0Required environment: STACKLINK_API_KEY, OPENAI_API_KEY, OPENAI_MODEL.
STACKLINK_BASE_URL is optional and defaults to https://api.stacklink.in.
import { openai } from '@ai-sdk/openai';
import { ToolLoopAgent } from 'ai';
import { Stacklink } from '@stacklink/sdk';
import { createStacklinkVercelTools } from '@stacklink/sdk/vercel-ai';
async function main(): Promise<void> {
const stacklink = new Stacklink({
apiKey: requireEnvironment('STACKLINK_API_KEY'),
baseUrl: process.env.STACKLINK_BASE_URL ?? 'https://api.stacklink.in',
});
const session = await stacklink.create({
tenantId: 'acme',
userId: 'user_123',
modelSurface: { mode: 'router' },
});
try {
const agent = new ToolLoopAgent({
model: openai(requireEnvironment('OPENAI_MODEL')),
instructions: 'Use Stacklink search, exact contracts, connection management, and governed execution to complete the request.',
tools: createStacklinkVercelTools(session),
});
const result = await agent.generate({
prompt: 'Find the best Gmail tool for reading unread messages and explain the next required action.',
});
console.log(result.text);
} finally {
await session.close();
}
}
void main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
function requireEnvironment(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`${name} is required.`);
return value;
}OpenAI Agents SDK
Install the Stacklink SDK with the selected harness:
npm install @stacklink/sdk @openai/agents@^0.13.3Required environment: STACKLINK_API_KEY, OPENAI_API_KEY, OPENAI_MODEL.
STACKLINK_BASE_URL is optional and defaults to https://api.stacklink.in.
import { Agent, run } from '@openai/agents';
import { Stacklink } from '@stacklink/sdk';
import { createStacklinkOpenAIAgentsTools } from '@stacklink/sdk/openai-agents';
async function main(): Promise<void> {
const stacklink = new Stacklink({
apiKey: requireEnvironment('STACKLINK_API_KEY'),
baseUrl: process.env.STACKLINK_BASE_URL ?? 'https://api.stacklink.in',
});
const session = await stacklink.create({
tenantId: 'acme',
userId: 'user_123',
modelSurface: { mode: 'router' },
});
try {
const agent = new Agent({
name: 'Stacklink assistant',
model: requireEnvironment('OPENAI_MODEL'),
instructions: 'Use Stacklink search, exact contracts, connection management, and governed execution to complete the request.',
tools: createStacklinkOpenAIAgentsTools(session),
});
const result = await run(
agent,
'Find the best Gmail tool for reading unread messages and explain the next required action.',
);
console.log(result.finalOutput);
} finally {
await session.close();
}
}
void main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
function requireEnvironment(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`${name} is required.`);
return value;
}Claude Agent SDK
Install the Stacklink SDK with the selected harness:
npm install @stacklink/sdk @anthropic-ai/claude-agent-sdk@^0.3.214Required environment: STACKLINK_API_KEY, ANTHROPIC_API_KEY, CLAUDE_MODEL.
STACKLINK_BASE_URL is optional and defaults to https://api.stacklink.in.
import { query } from '@anthropic-ai/claude-agent-sdk';
import { Stacklink } from '@stacklink/sdk';
import { createStacklinkClaudeAgentToolConfig } from '@stacklink/sdk/claude-agent';
async function main(): Promise<void> {
const stacklink = new Stacklink({
apiKey: requireEnvironment('STACKLINK_API_KEY'),
baseUrl: process.env.STACKLINK_BASE_URL ?? 'https://api.stacklink.in',
});
const session = await stacklink.create({
tenantId: 'acme',
userId: 'user_123',
modelSurface: { mode: 'router' },
});
try {
const stacklinkTools = createStacklinkClaudeAgentToolConfig(session);
let finalOutput = '';
for await (const message of query({
prompt: 'Find the best Gmail tool for reading unread messages and explain the next required action.',
options: {
model: requireEnvironment('CLAUDE_MODEL'),
systemPrompt: 'Use Stacklink search, exact contracts, connection management, and governed execution to complete the request.',
tools: [],
maxTurns: 6,
...stacklinkTools,
},
})) {
if (message.type === 'result' && message.subtype === 'success') {
finalOutput = message.result;
}
}
console.log(finalOutput);
} finally {
await session.close();
}
}
void main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
function requireEnvironment(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`${name} is required.`);
return value;
}Source of truth
These examples are generated from the same executable files used by Stacklink Overview and release certification. npm and PyPI deliver the packages; this documentation remains the onboarding source of truth.