Platform client
Use a server-only API key to create connections and issue browser access.
createDomain0PlatformClient() targets the hosted public platform boundary.
It sends your key in x-api-key; Domain0 derives application and tenant
ownership from that key.
import { createDomain0PlatformClient } from 'domain0'
const platform = createDomain0PlatformClient({
baseUrl: 'https://domain0.dev/api/domain0/',
apiKey: process.env.DOMAIN0_API_KEY!,
})Server only
Never construct this client in a Client Component, browser bundle, mobile webview, or public edge response. A Domain0 API key is long-lived authority for its bound application.
Create a connection
const { connection } = await platform.createConnection({
intent: {
domain: 'customer.example',
records: [
{
host: 'app',
type: 'CNAME',
value: 'edge.your-product.com',
ttl: 300,
},
],
},
})The public request does not accept applicationId, tenantId, or a caller
supplied command ID. The platform owns those fields at this boundary.
Issue browser access
const access = await platform.issueConnectionToken(connection.id, {
origin: 'https://app.your-product.com',
})The returned bearer token expires quickly and is restricted to the exact connection and origin. Return it only to the browser session that will open the flow.
Refresh safely
If the dialog remains open near token expiry, ask your server for another token for the same connection. Pass an async token resolver to the browser client so concurrent requests share your refresh promise.