Anthropic Integration
Add SOVR to Claude tool use.
Setup
typescript
import Anthropic from '@anthropic-ai/sdk';
import { SovrClient } from '@sovr/sdk';
const anthropic = new Anthropic();
const sovr = new SovrClient({
tenantId: process.env.SOVR_TENANT_ID!,
apiKey: process.env.SOVR_API_KEY!,
});Protected Execution
typescript
async function executeWithSovr(toolName: string, input: any) {
const check = await sovr.gate.check({
action: toolName,
context: input,
});
if (check.decision === 'allow') {
return await executeTool(toolName, input);
}
return { blocked: true, reason: check.reason };
}Full Example
typescript
const tools = [{
name: 'send_email',
input_schema: {
type: 'object',
properties: {
to: { type: 'string' },
subject: { type: 'string' },
},
},
}];
async function runAgent(prompt: string) {
let messages = [{ role: 'user', content: prompt }];
while (true) {
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 4096,
tools,
messages,
});
if (response.stop_reason === 'end_turn') {
return response.content;
}
if (response.stop_reason === 'tool_use') {
const results = [];
for (const block of response.content) {
if (block.type === 'tool_use') {
const result = await executeWithSovr(block.name, block.input);
results.push({
type: 'tool_result',
tool_use_id: block.id,
content: JSON.stringify(result),
});
}
}
messages.push({ role: 'assistant', content: response.content });
messages.push({ role: 'user', content: results });
}
}
}