cube-js/cube · error
Native api gateway is not enabled
Error message
Native api gateway is not enabled
What it means
getNativeGatewayPort returns the port of the native (Rust) API gateway, but that port is only assigned in the SQLServer constructor when the nativeApiGateway env flag is enabled. If the flag is off, gatewayPort stays undefined and this getter throws 'Native api gateway is not enabled'. It signals that code is asking for native-gateway functionality the deployment never enabled.
Source
Thrown at packages/cubejs-api-gateway/src/sql-server.ts:68
setupLogger(
({ event }) => apiGateway.log(event),
process.env.CUBEJS_LOG_LEVEL === 'trace' ? 'trace' : 'warn',
process.env.NODE_ENV === 'production'
);
// Actually, proxy is enabled in gateway
// But passing port into registerInterface will start native gateway
if (getEnv('nativeApiGateway')) {
this.gatewayPort = options.gatewayPort || 7575;
}
}
public getNativeGatewayPort(): number {
if (this.gatewayPort) {
return this.gatewayPort;
}
throw new Error('Native api gateway is not enabled');
}
private getSqlInterfaceInstance(): SqlInterfaceInstance {
if (!this.sqlInterfaceInstance) {
throw new Error('SQL interface is not initialized. Please enable the SQL interface in your settings.');
}
return this.sqlInterfaceInstance;
}
public async execSql(sqlQuery: string, stream: any, securityContext?: any, cacheMode?: CacheMode, timezone?: string, throwContinueWait?: boolean, requestId?: string) {
await execSql(this.getSqlInterfaceInstance(), sqlQuery, stream, securityContext, cacheMode, timezone, throwContinueWait, requestId);
}
public async sql4sql(sqlQuery: string, disablePostProcessing: boolean, securityContext?: unknown): Promise<Sql4SqlResponse> {
return sql4sql(this.getSqlInterfaceInstance(), sqlQuery, disablePostProcessing, securityContext);
}
View on GitHub (pinned to 7d981676b3)
Solutions
- Enable the native API gateway by setting the environment variable (nativeApiGateway / CUBEJS_NATIVE_API_GATEWAY=true).
- Explicitly configure the port via gatewayPort option (defaults to 7575) so the getter returns a known value.
- If the native gateway is intentionally disabled, remove or gate the code path that calls getNativeGatewayPort().
Example fix
// before const port = sqlServer.getNativeGatewayPort(); // after (env) process.env.CUBEJS_NATIVE_API_GATEWAY = 'true'; const port = sqlServer.getNativeGatewayPort();
Defensive patterns
Strategy: validation
Validate before calling
const nativeGatewayEnabled = () =>
['true', '1', 'on'].includes(String(process.env.CUBEJS_NATIVE_API_GATEWAY ?? process.env.nativeApiGateway ?? '').toLowerCase());
if (!nativeGatewayEnabled()) throw new Error('Enable CUBEJS_NATIVE_API_GATEWAY before using the native gateway'); Type guard
function hasNativeGateway(s: { getNativeGatewayPort?: () => number }): s is Required<{ getNativeGatewayPort: () => number }> {
return typeof (s as any).gatewayPort === 'number' || nativeGatewayEnabled();
} Try / catch
let port: number;
try {
port = sqlServer.getNativeGatewayPort();
} catch (e) {
if (e.message === 'Native api gateway is not enabled') {
port = 7575; // or bail out / fall back to REST gateway
} else throw e;
} Prevention
- Set CUBEJS_NATIVE_API_GATEWAY=true wherever the native gateway is required.
- Check env var presence in deployment config (Docker, k8s, serverless) before boot.
- Gate any getNativeGatewayPort() call behind a check that the feature is on.
- Log configuration at startup to catch missing flags early.
When it happens
Trigger: Calling getNativeGatewayPort() (directly or via code that proxies/queries the native gateway) on a SQLServer instance constructed without the nativeApiGateway env var set (CUBEJS_NATIVE_API_GATEWAY truthy).
Common situations: Running Cube from source or embedding @cubejs-server-core without the native gateway enabled while tooling (e.g. SQL API tooling, tests, custom integrations) assumes it; upgrading to a version where the native gateway is expected but not configured; forgetting to set the env var in a container or serverless deployment.
Related errors
- Either CUBEJS_DB_TYPE or CreateOptions.driverFactory must be
- CreateOptions.orchestratorOptions.rollupOnlyMode cannot be t
- CUBESTORE_COMPACTION_READINESS_CHUNKS_THRESHOLD ({}) must no
- Value "${input}" is not valid for ${envName}. ${description}
- Value "${input}" is not valid for ${envName}. Should be a po
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/04d952bb133a95f5.
Report an issue: GitHub.