Anthropic Claude Integration
Protect Claude workflows by scanning inputs with KoreShield and routing requests through the proxy.Installation
npm install koreshield @anthropic-ai/sdk
Basic Integration
import { Koreshield } from "koreshield";
import Anthropic from "@anthropic-ai/sdk";
const koreshield = new Koreshield({
apiKey: process.env.KORESHIELD_API_KEY
});
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY
});
export async function secureClaude(userMessage: string) {
const scan = await koreshield.scan({ content: userMessage });
if (scan.threat_detected) {
throw new Error(`Threat: ${scan.threat_type}`);
}
const message = await anthropic.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1024,
messages: [{ role: "user", content: userMessage }]
});
return message.content[0].text;
}
Proxy Mode
const response = await fetch("http://localhost:8000/v1/chat/completions", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
model: "claude-3-5-sonnet-20241022",
messages: [{ role: "user", content: "Summarize the incident." }]
})
});
Streaming
const stream = await anthropic.messages.stream({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1024,
messages: [{ role: "user", content: "Draft a security summary." }]
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
Tool Use
const tools: Anthropic.Tool[] = [
{
name: "search_database",
description: "Search the database",
input_schema: {
type: "object",
properties: { query: { type: "string" } },
required: ["query"]
}
}
];
const message = await anthropic.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1024,
messages: [{ role: "user", content: "Search for user 123" }],
tools
});
System Prompts and Multi-Turn
{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "system", "content": "You are a compliance assistant."},
{"role": "user", "content": "Summarize the incident."},
{"role": "assistant", "content": "Summary..."},
{"role": "user", "content": "List next steps."}
]
}
Error Handling
403indicates a blocked request due to policy enforcement429or5xxtypically indicates provider or rate-limit issues
Security Controls
security:
sensitivity: high
default_action: block
features:
sanitization: true
detection: true
policy_enforcement: true
Next Steps
Configuration
Configure providers and security settings
Python SDK
Try RAG protections