Getting Started
Get started with Anchor in minutes. This guide will walk you through creating your first agent, configuring policies, and storing data with automatic enforcement.
1. Get an API Key
Sign up at app.getanchor.dev to get your API key and workspace ID.
2. Install the SDK
Python
pip install anchoraiTypeScript/JavaScript
npm install anchorai3. Create Your First Agent
Python
from anchor import Anchor
anchor = Anchor(api_key="your-api-key")
# Create an agent
agent = anchor.agents.create("support-bot", metadata={"environment": "production"})
print(f"Agent ID: {agent.id}")TypeScript
import { Anchor } from 'anchorai';
const anchor = new Anchor({ apiKey: 'your-api-key' });
// Create an agent
const agent = await anchor.agents.create('support-bot', { environment: 'production' });
console.log(`Agent ID: ${agent.id}`);4. Configure Policies
Policies automatically block certain data from being stored. Configure policies to prevent PII, secrets, and other sensitive data.
Python
anchor.config.update(agent.id, {
"policies": {
"block_pii": True,
"block_secrets": True,
"retention_days": 90
}
})TypeScript
await anchor.config.update(agent.id, {
policies: {
block_pii: true,
block_secrets: true,
retention_days: 90
}
});5. Store Data
Store data with automatic policy enforcement. Anchor checks every write against your policies before storage.
Python
# Allowed - just a preference
result = anchor.data.write(agent.id, "user:123:preference", "dark_mode")
print(result.allowed) # True
# Blocked - email is PII
result = anchor.data.write(agent.id, "user:123:email", "john@example.com")
print(result.allowed) # False
print(result.blocked_by) # "policy:block_pii"TypeScript
// Allowed - just a preference
const result = await anchor.data.write(agent.id, 'user:123:preference', 'dark_mode');
console.log(result.allowed); // true
// Blocked - email is PII
const blocked = await anchor.data.write(agent.id, 'user:123:email', 'john@example.com');
console.log(blocked.allowed); // false
console.log(blocked.blockedBy); // "policy:block_pii"6. Verify Audit Trail
Every operation is logged to the audit trail. Verify the integrity of your audit logs.
Python
verification = anchor.audit.verify(agent.id)
print(verification.valid) # True if chain intactTypeScript
const verification = await anchor.audit.verify(agent.id);
console.log(verification.valid); // true if chain intact