Best Practices
What You’ll LearnThis guide covers:
- API key security and rotation
- Handling card credentials safely
- Attestation and intent best practices
- Webhook security and verification
- Agent and card lifecycle management
API Key Security
Do’s and Don’ts
Do: Use environment variables
Store API keys in environment variables or secret managers. Never hardcode keys.
Don't: Expose in client code
Never include API keys in frontend JavaScript, mobile apps, or public repositories.
Do: Use agent tokens for agents
Give AI agents their own scoped tokens instead of your master API key.
Don't: Share keys across environments
Use separate keys for development (
lk_dev_) and production (lk_live_).Key Rotation
Rotate API keys periodically and immediately if compromised:- Generate a new key in the dashboard
- Update your application to use the new key
- Verify the new key works
- Revoke the old key
Handling Card Credentials
Card credentials (PAN, CVV, expiry) are sensitive. Handle them carefully.Do’s and Don’ts
Do: Minimize exposure time
Request card details only when immediately needed for a transaction. Don’t cache them.
Don't: Log card details
Never log full PAN or CVV. At most, log last 4 digits.
Do: Use HTTPS only
All API calls must use HTTPS. Never transmit credentials over HTTP.
Don't: Store credentials
Don’t persist card details in databases, files, or caches. Request fresh credentials each time.
Credential Lifecycle
Browser-Based Agents
If your AI agent runs in a browser context:- Use LedgerOS-provided secure iframes (coming soon)
- Never expose credentials to JavaScript you don’t control
- Prefer server-side credential handling when possible
Attestation Best Practices
Attestation creates an audit trail linking credential access to stated intent.Accurate Attestations
Do: Be specific
Provide accurate, specific attestation data.
Don't: Be vague
Avoid generic attestations that don’t aid auditing.
Amount Accuracy
- Provide
expectedAmountas close to actual as possible - Include taxes and shipping in your estimate
- LedgerOS allows ~10% variance for intent matching
- Large mismatches trigger risk alerts
Merchant Text
- Use the merchant name as it appears in card network data
- “Amazon.com” not “Amazon” or “AMZN”
- Check transaction history for exact merchant strings
Intent Best Practices
Intents are required for all cards. Here’s how to use them effectively:Timing
- Declare intent close to when you’ll use the card
- Access card details shortly after declaring intent
- Complete the transaction within 24 hours of accessing details
One Intent Per Purchase
Intent Data Quality
Webhook Security
Signature Verification
Always verify webhook signatures:Idempotency
Webhooks may be delivered multiple times. Handle them idempotently:Respond Quickly
- Return 2xx within 30 seconds
- Process asynchronously if needed
- Failed webhooks are retried with exponential backoff
Agent Lifecycle
Agent Scope
Do: Scope agents narrowly
Register agents with specific, limited purposes.
Don't: Create catch-all agents
Avoid overly broad agents with high limits.
Agent Tokens
- Generate agent tokens for AI agents
- Agent tokens can only access agent-scoped tools
- Rotate tokens periodically
- Revoke tokens when agents are decommissioned
Deregistration
When an agent is no longer needed:- Close all active cards for the agent
- Deregister the agent via API
- Revoke any agent tokens
- Remove from your systems
Card Lifecycle
Card Types
| Scenario | Card Type | Why |
|---|---|---|
| One-time purchase | single | Auto-closes, limits exposure |
| Recurring purchases | multi | Reusable with velocity limits |
| Unknown usage pattern | single | Safer default |
Card Limits
Set appropriate limits:Close Unused Cards
- Close cards that won’t be used
- Single-use cards auto-close after settlement
- Regularly audit and close stale multi-use cards
Error Handling
Graceful Degradation
Retry Strategy
| Error Type | Retry? | Strategy |
|---|---|---|
| Rate limited (429) | Yes | Exponential backoff |
| Server error (5xx) | Yes | 3 retries, backoff |
| Auth error (401) | No | Check credentials |
| Validation error (400) | No | Fix request |
| Insufficient funds | No | User action needed |
Monitoring
What to Monitor
- API error rates and latency
- Transaction approval rates
- Intent match rates
- Webhook delivery success
- Agent spending vs limits
Alerts to Set Up
- High transaction decline rate
- Webhook delivery failures
- Agent approaching spending limit
- Unusual transaction patterns
- API errors spike