Genkit JavaScript and TypeScript
Genkit APIs and plugins evolve quickly. Use the project lockfile, installed package source/types, tests, and current official Genkit documentation as the source of truth.
Guardrails
- Inspect
package.json, lockfile, runtime, Genkit/CLI/plugin versions, imports, configured provider/model, flows, tools, and deployment target.
- Do not run global installs,
@latest, network installers, or broad upgrades implicitly.
- Preserve the existing provider. If none exists, compare options by deployment, privacy, region, capability, latency, and cost; do not select one by default.
- Keep the exact model ID in validated configuration and verify that the installed plugin supports required tools, structured output, streaming, multimodal input, and embeddings.
- Keep secrets out of client bundles, source, logs, examples, and prompts.
Implementation
- Register only needed plugins and use symbols that exist in the installed version.
- Define typed input/output schemas and validate application invariants after generation.
- Keep prompts and untrusted user/retrieved data separated.
- Give tools strict object schemas, least privilege, authorization, timeouts, idempotency, and approval for costly/destructive/external effects.
- Bound tool rounds, retries, concurrency, tokens, time, and spend.
- Keep HTTP/auth concerns outside model decisions and return safe errors.
- Add telemetry that records flow/tool status, latency, usage, and request IDs without leaking sensitive payloads.
Conceptual configuration:
const modelId = process.env.GENKIT_MODEL_ID;
if (!modelId) throw new Error('GENKIT_MODEL_ID is required');
// Initialize the already selected provider plugin and pass modelId using
// the API supported by the installed Genkit version.
Verify
Run typecheck/lint/tests, input/output schema tests, mocked provider/tool tests, cancellation/timeouts/retries, authorization and injection tests, and a Dev UI check when installed. A live provider smoke test requires authorized credentials/network/cost. Report installed versions, configured provider/model source, exact commands, and skipped checks.
1---2name: developing-genkit-js3description: Build and troubleshoot Genkit applications in JavaScript or TypeScript with installed-version-first APIs, provider-neutral model configuration, flows.4license: MIT5---67# Genkit JavaScript and TypeScript89Genkit APIs and plugins evolve quickly. Use the project lockfile, installed package source/types, tests, and current official Genkit documentation as the source of truth.1011## Guardrails1213- Inspect `package.json`, lockfile, runtime, Genkit/CLI/plugin versions, imports, configured provider/model, flows, tools, and deployment target.14- Do not run global installs, `@latest`, network installers, or broad upgrades implicitly.15- Preserve the existing provider. If none exists, compare options by deployment, privacy, region, capability, latency, and cost; do not select one by default.16- Keep the exact model ID in validated configuration and verify that the installed plugin supports required tools, structured output, streaming, multimodal input, and embeddings.17- Keep secrets out of client bundles, source, logs, examples, and prompts.1819## Implementation20211. Register only needed plugins and use symbols that exist in the installed version.222. Define typed input/output schemas and validate application invariants after generation.233. Keep prompts and untrusted user/retrieved data separated.244. Give tools strict object schemas, least privilege, authorization, timeouts, idempotency, and approval for costly/destructive/external effects.255. Bound tool rounds, retries, concurrency, tokens, time, and spend.266. Keep HTTP/auth concerns outside model decisions and return safe errors.277. Add telemetry that records flow/tool status, latency, usage, and request IDs without leaking sensitive payloads.2829Conceptual configuration:3031```ts32const modelId = process.env.GENKIT_MODEL_ID;33if (!modelId) throw new Error('GENKIT_MODEL_ID is required');34// Initialize the already selected provider plugin and pass modelId using35// the API supported by the installed Genkit version.36```3738## Verify3940Run typecheck/lint/tests, input/output schema tests, mocked provider/tool tests, cancellation/timeouts/retries, authorization and injection tests, and a Dev UI check when installed. A live provider smoke test requires authorized credentials/network/cost. Report installed versions, configured provider/model source, exact commands, and skipped checks.