Skip to main content

Admin SDK

Admin SDKs run on your backend server and authenticate with a Service Key. They bypass access rules and unlock server-only features like Admin Auth, Raw SQL, Broadcast, Functions, Analytics, and Cloudflare native resources.

Admin SDKs are available in 12 languages: JavaScript, Dart, Kotlin, Java, Scala, Python, Go, PHP, Rust, C#, Ruby, and Elixir.

At a Glance

Client SDKAdmin SDK
Runs onBrowser, Mobile, Game EngineBackend server, Cloud function, CLI
Auth methodUser token (JWT)Service Key
Access RulesAppliedBypassed
User auth (signUp/signIn)
Admin auth (createUser/deleteUser)
Realtime (onSnapshot)
Raw SQL
Push send / logs
Functions / webhooks invoke
Analytics / event queries
KV / D1 / Vectorize
warning

Never expose the Service Key in client-side code. It has full admin access to your backend, including user management and raw SQL execution.

For installation instructions, see SDK Overview — select the "Admin SDK" tab for each language.


Admin-Only Features

These features require a Service Key and are only available in admin mode.

Admin Auth

Manage users programmatically — create, update, delete, set custom claims.

const user = await admin.auth.createUser({
email: 'admin@example.com',
password: 'securePassword',
displayName: 'Admin',
role: 'admin',
});

await admin.auth.setCustomClaims('user-id', { plan: 'pro' });
await admin.auth.revokeAllSessions('user-id');

Raw SQL

Execute raw SQL queries against your database.

const rows = await admin.sql('posts',
'SELECT authorId, COUNT(*) as cnt FROM posts GROUP BY authorId ORDER BY cnt DESC LIMIT ?',
[10]
);

Server-Side Broadcast

Send broadcast messages from your server to all connected clients.

await admin.broadcast('notifications', 'alert', {
message: 'System maintenance in 5 minutes',
});

Cloudflare Native Resources (KV / D1 / Vectorize)

Access user-defined Cloudflare KV, D1 databases, and Vectorize indexes directly from your server code. Resources must be declared in edgebase.config.ts — only allowlisted bindings are accessible.

// KV — cache, session store, feature flags
await admin.kv('cache').set('key', 'value', { ttl: 300 });
const val = await admin.kv('cache').get('key');
await admin.kv('cache').delete('key');
const list = await admin.kv('cache').list({ prefix: 'user:' });

// D1 — analytics, logs, relational queries
const rows = await admin.d1('analytics').exec(
'SELECT * FROM events WHERE type = ?',
['pageview']
);

// Vectorize — semantic search, RAG, recommendations
await admin.vector('embeddings').upsert([
{ id: 'doc-1', values: [0.1, 0.2, ...], metadata: { title: 'Hello' } },
]);
const results = await admin.vector('embeddings').search(
[0.1, 0.2, ...],
{ topK: 10, filter: { type: 'article' } }
);
Local Development

KV and D1 work fully in local/Docker environments via Miniflare emulation. Vectorize is Edge-only — local calls return stub responses with a console warning.


Choosing the Right SDK

Web App (React, Vue, Svelte)

Use the JavaScript SDK in client mode for the frontend. If you need server-side rendering (SSR) or API routes, use server mode in your backend.

Mobile App (Flutter)

Use the Dart SDK in client mode. For background processing or admin tasks, use server mode in your Dart backend.

Mobile App (React Native)

Use the React Native SDK in client mode.

Mobile App (iOS native)

Use the Swift SDK in client mode.

Mobile App (Android native)

Use the Kotlin SDK in client mode.

Game (Unity)

Use the C# SDK — client mode for Unity, admin mode for ASP.NET Core / .NET backend servers.

Game (Unreal Engine)

Use the C++ SDK — client only. For admin operations, use a separate backend.

Backend API / Microservice

Use Go, PHP, Rust, Ruby, Scala, or Elixir SDK. These are server-only and authenticate with a Service Key.

Scripts / Automation / ML

Use the Python, Ruby, or Elixir SDK with a service key. These are all strong fits for scripts, automation, and data tasks.


Next Steps