Skip to content

Set Up Authentication

Configure API keys and secure access to your DeltaBase instance

First, you need an API key. During early access, we’ll send you one manually.

Join the Discord and ask for access: https://discord.gg/nibbio

Once you have your key, store it securely.

Never hardcode API keys. Use environment variables:

.env
DELTABASE_API_KEY=dbk_your_actual_key_here
DELTABASE_URL=https://api.delta-base.com
import { DeltaBase } from '@delta-base/server';
const deltabase = new DeltaBase({
apiKey: process.env.DELTABASE_API_KEY!,
baseUrl: process.env.DELTABASE_URL || 'https://api.delta-base.com'
});

If you’re building a SaaS app, you’ll want tenant isolation:

// Each tenant gets their own event store
const getTenantEventStore = (tenantId: string) => {
return deltabase.getEventStore(`tenant-${tenantId}`);
};
// Usage in your API
app.use('/api', async (req, res, next) => {
const tenantId = req.headers['x-tenant-id'];
if (!tenantId) {
return res.status(400).json({ error: 'Tenant ID required' });
}
req.eventStore = getTenantEventStore(tenantId);
next();
});

Handle auth errors gracefully:

try {
await eventStore.appendToStream('stream-1', [event]);
} catch (error) {
if (error.status === 401) {
console.error('Invalid API key');
// Refresh key or redirect to login
} else if (error.status === 403) {
console.error('Insufficient permissions');
// Show error to user
} else {
console.error('Unexpected error:', error);
}
}

When you need to rotate keys:

  1. Get new key from DeltaBase team
  2. Update environment variable
  3. Restart your application
  4. Old key is automatically revoked

That’s it. No complex OAuth flows. No token management. Just works.