Skip to content

@askdb/client API reference

Reference · @askdb/client

@askdb/client is a config-driven facade over @askdb/core. createAskDb() resolves the schema, model, and dialect from askdb.config.* once; call sites pass only a question. Use it when you want the shortest path from config to SQL. Use @askdb/core directly when you construct the model yourself, serve multiple schemas, or want zero dependency on @askdb/config.

Builds a client bound to a config snapshot and AI provider registry. The schema, model, and dialect are resolved lazily on the first ask() call and cached for the process lifetime. Call reload() to clear the cache.

import { createAskDb } from "@askdb/client";
import { bootstrapAskDbEnv, getAskDbRuntimeConfig } from "@askdb/config";
import { openaiProvider } from "@askdb/ai-openai";
bootstrapAskDbEnv({ cwd: process.cwd() });
const askdb = createAskDb({
config: getAskDbRuntimeConfig(),
providers: [openaiProvider],
schema: { path: "./my-app.schema" },
});
FieldTypeRequiredDescription
configAskDbRuntimeConfigyesRuntime config snapshot from getAskDbRuntimeConfig(). Call bootstrapAskDbEnv() at startup first.
providersAiProviderAdaptersone ofProvider adapters, e.g. [openaiProvider] from @askdb/ai-openai. The client builds the registry internally — the common path.
registryAiRegistryone ofPrebuilt registry from createAiRegistry(...) — advanced alternative to providers (e.g. to share one registry across clients). Pass exactly one of the two.
schemaSchemaSourcenoDefault schema source. Falls back to host.schemaJson, then host.schemaPath, from askdb.config.ts.
dialectBuiltInDialectIdnoDefault dialect override. Falls back to config.nlToSql.dialectschema.provider"postgres".
unknownDialect"throw" | "fallback-postgres"noWhat to do when schema.provider is not a recognized built-in dialect id. Default "throw".
onResolve(info: ResolveInfo) => voidnoHook fired on every ask() call once resolution completes. Useful for logging which dialect and model were chosen. ResolveInfo has dialect and modelSource.

Accepted forms for the schema option and per-call overrides:

{ path: string } // directory, bundle file, or schema.json path
{ json: string } // raw JSON string
{ schema: AnyNormalizedSchema} // pre-loaded schema object

const { sql, usage, unboundSql, params, preparedQuery } = await askdb.ask(
"How many orders shipped last month?",
);

Runs the same pipeline as @askdb/core’s ask(). Returns AskPipelineResult — see @askdb/core API → Result. The facade forwards options and returns the core result verbatim, including optional unboundSql / params / parameters / preparedQuery when parameterize is on (default). Rebind locally with bindPreparedQuery from @askdb/core — it does not authorize tenant IDs.

All AskPipelineOptions fields can be overridden per call. In addition, schema, model, and dialect can be swapped for a single request:

FieldTypeDescription
schemaSchemaSource | AnyNormalizedSchemaOverride the default schema for this call only.
modelAskDbLanguageModelOverride the default model for this call only.
dialectAskDialectInputOverride the dialect for this call only.
explainbooleanInclude guardrail metadata in the result.
omitSensitiveIdentifiersFromNlToSqlPromptbooleanStrip sensitive identifiers from the DDL prompt.
modeAskDbModeV1Trust boundary override.
tenantScopeTenantScopeRequired when the schema has a tenant policy.
tenantSqlModeTenantSqlOutputMode"sql-only" or "sql-params".
parameterizebooleanDefault true. Set false to skip unbound SQL / parameter manifest output tokens.
retrieverRetrieverRAG retriever.
retrievalKnumberTop-k for the retriever.
retrievalThresholdChunksnumberChunk count threshold for triggering retrieval.
totalSchemaChunkCountnumberTotal indexed chunk count; from buildSchemaIndex result stats.
loggerAskDbLoggerPer-call structured logger.
depsAskGenerateDeps{ generateText? } for testing.

askdb.reload();

Drops the cached schema and model. The next ask() call re-resolves them from config. Useful in tests or in processes that hot-reload their config without restarting.