Key Types
App Key (X-App-Key)
- Required for write operations
- Identifies the application
- Used for app-level permissions
Agent Key (X-Agent-Key)
- App Key with Pay permission
- Enables autonomous agents to pay other apps inline
- Configurable spend limits and target app whitelisting
Configuration
TypeScript
App Key Permissions
App Keys support a four-tier permission system, allowing you to create keys with granular access control:Read
- Query data
- Read documents
- Access collections
- View indexes
Write
- Store data
- Update documents
- Delete documents
- Create collections
Admin
- Manage indexes
- Configure encryption
- App-level settings
- Full access
Pay
- Agent Key permission
- Pay other apps inline via USDC
- Configurable spend limits
- Target app whitelisting
| Permission Combination | Use Case |
|---|---|
| Read only | Public APIs, analytics dashboards |
| Read + Write | Standard application backend |
| Read + Write + Admin | Full application management |
| Write only | Data ingestion pipelines |
| Read + Write + Pay | Autonomous AI agents accessing paid data |
Agent Keys
An Agent Key is an App Key with thePay permission. It enables autonomous agents to pay other apps inline when storing or querying their data, using USDC.
Generating an Agent Key
Using an Agent Key
TypeScript
How Agent Auto-Pay Works
Writes: The broker handles payment automatically in a background task:PaymentRequiredError flow applies separately.
Pay Limits
All limits are optional — omit any to leave it uncapped. Limits are enforced fail-fast in order:| Limit | Enforced at | Effect |
|---|---|---|
expires_at | Pre-flight | Key stops working after this timestamp |
max_payment_per_tx | Per-write | Single write cannot exceed this amount (uUSDC) |
spend_allowance | Per-write | Cumulative lifetime cap (uUSDC) |
allowed_target_apps | Pre-flight | Whitelist of app IDs the key can pay into |
1 USDC = 1,000,000 uUSDC (6 decimals). A
max_payment_per_tx of 5_000_000 means 5 USDC.App Key Usage
The App Key (X-App-Key header) is required for all write operations:
- Creating documents
- Updating documents
- Deleting documents
- Creating indexes
- Creating collections
- Managing views
TypeScript
Managing App Keys
Generating a New Key
- Go to app.ondb.ai
- Log in to your account
- Select your application
- Navigate to the Security tab
- Enter a name for your key (e.g., “production-backend”, “staging-api”)
- Select the permissions (Read, Write, Admin)
- Click Generate New API Key
- Approve the transaction (small fee ~$0.001 USDC)
- Copy your key immediately - it will only be shown once
Listing Existing Keys
From the Security tab, click Load Keys to view all your active App Keys. For each key you can see:- Key Hash: First 16 characters of the key hash for identification
- Name: The name you assigned when creating the key
- Permissions: Visual badges showing Read/Write/Admin access
- Created: When the key was generated
- Last Used: Most recent API request with this key
Revoking a Key
If a key is compromised or no longer needed:- Go to the Security tab
- Click Load Keys to list all keys
- Find the key you want to revoke
- Click the Revoke button
- Confirm the revocation
- Approve the transaction
Revoked keys are immediately invalidated. Any applications using that key will receive authentication errors.
Security Best Practices
Key Management Guidelines
| Practice | Description |
|---|---|
| Use environment variables | Never hardcode keys in source code |
| Principle of least privilege | Create keys with only necessary permissions |
| Rotate keys regularly | Regenerate keys every 90 days |
| Separate environments | Use different keys for dev/staging/production |
| Monitor usage | Check “Last Used” to detect unauthorized access |
| Immediate revocation | Revoke compromised keys immediately |
Server-Side Configuration
TypeScript
HTTPS Only
Always use HTTPS when communicating with OnDB APIs. Never send App Keys over unencrypted connections.Next Steps
Security Settings
Authentication and authz grants
Collections & Indexes
Learn about organizing your data
Payment Flows
Understand payment options