Index of every page on this site: llms.txt
All skills
genkit-ai avatar

/developing-genkit-js

@d12c988
by Genkitgenkit-ai/skills40 stars
13
Run it yourself

Provides guidance on developing AI-powered applications using Genkit in Node.js/TypeScript. Use when the user asks about Genkit, AI agents, flows, or tools in JavaScript/TypeScript, or when encountering Genkit errors, validation issues, type errors, or API problems. Don't use for Genkit in Python, Go, or Dart.

Use this Skill: https://skilld.dev/gh/genkit-ai/skills/developing-genkit-js

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescommon-errors.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Common Errors & Pitfalls


When Typecheck Fails

Before searching source code or docs, check the sections below. Many type errors are caused by deprecated APIs or incorrect imports.

Genkit v1.x vs Pre-1.0 Migration

Genkit v1.x introduced significant API changes. This section covers critical syntax updates.

Package Imports

  • Correct (v1.x): Import core functionality (zod, genkit) from the main genkit package and plugins from their specific packages.

    import { z, genkit } from 'genkit';
    import { googleAI } from '@genkit-ai/google-genai';
  • Incorrect (Pre-1.0): Importing from @genkit-ai/ai, @genkit-ai/core, or @genkit-ai/flow. These packages are internal/deprecated for direct use.

    import { genkit } from "@genkit-ai/core"; // INCORRECT
    import { defineFlow } from "@genkit-ai/flow"; // INCORRECT

Model References

  • Correct: Use plugin-specific model factories or string identifiers (prefaced by plugin name).
    // Using model factory (v1.x - Preferred)
    await ai.generate({ model: googleAI.model('gemini-flash-latest'), ... });
    
    // Using string identifier
    await ai.generate({ model: 'googleai/gemini-flash-latest', ...});
    // Or
    await ai.generate({ model: 'vertexai/gemini-flash-latest', ...});
  • Incorrect: Using imported model objects directly or string identifiers without plugin name.
    await ai.generate({ model: gemini15Pro, ... }); // INCORRECT (Pre-1.0)
    await ai.generate({ model: 'gemini-flash-latest', ... }); // INCORRECT (No plugin prefix)

Model Selection (Gemini)

  • Preferred: Use latest model aliases (e.g. gemini-flash-latest) for best performance and features.
    model: googleAI.model('gemini-flash-latest') // PREFERRED
  • DEPRECATED: Versioned legacy models (like gemini-1.5-flash or gemini-2.5-flash) should be updated to latest aliases.
    model: googleAI.model('gemini-1.5-flash') // DEPRECATED (Use gemini-flash-latest instead)

Response Access

  • Correct (v1.x): Access properties directly.
    response.text; // CORRECT
    response.output; // CORRECT
  • Incorrect (Pre-1.0): Calling as methods.
    response.text(); // INCORRECT
    response.output(); // INCORRECT

Streaming Generation

  • Correct (v1.x): Do NOT await generateStream. Iterate over stream directly. Await response property for final result.
    const {stream, response} = ai.generateStream(...); // NO await here
    for await (const chunk of stream) { ... }          // Iterate stream
    const finalResponse = await response;              // Await response property
  • Incorrect (Pre-1.0): Calling stream as a function or awaiting the generator incorrectly.
    for await (const chunk of stream()) { ... } // INCORRECT
    await response();                           // INCORRECT

Initialization

  • Correct (v1.x): Instantiate genkit.
    const ai = genkit({ plugins: [...] });
  • Incorrect (Pre-1.0): Global configuration.
    configureGenkit({ plugins: [...] }); // INCORRECT

Flow Definitions

  • Correct (v1.x): Define flows on the ai instance.
    ai.defineFlow({...}, (input) => {...});
  • Incorrect (Pre-1.0): Importing defineFlow globally.
    import { defineFlow } from "@genkit-ai/flow"; // INCORRECT

You should never import @genkit-ai/flow, @genkit-ai/ai or @genkit-ai/core packages directly.

Zod and Schema Errors

  • Import Source: ALWAYS use import { z } from "genkit".
    • Using zod directly from zod package may cause instance mismatches or compatibility issues.
  • Supported Types: Stick to basic types: scalar (string, number, boolean), object, and array.
    • Avoid complex Zod features unless strictly necessary and verified.
  • Descriptions: Always use .describe('...') for fields in output schemas to guide the LLM.

Tool Usage

  • Tool Not Found: Ensure tools are registered in the tools array of generate or provided via plugins.
  • MCP Tools: Use the ServerName:tool_name format when referencing MCP tools.

Handling Failures in Tool Loops

  • Don't throw away finished tool rounds. By default generate() throws on a model/tool/middleware failure or at maxTurns. Since genkit 1.43.0, throwOnError: false returns the failure on the response along with messages up to the last completed tool round, so you can retry without re-running tools that already succeeded:
    const opts = { model: googleAI.model('gemini-flash-latest'), tools: [getWeather], throwOnError: false };
    let res = await ai.generate({ ...opts, prompt: 'What should I wear in Tokyo?' });
    if (res.finishReason === 'failed' || res.finishReason === 'aborted') {
      console.warn(res.error?.status, res.error?.message); // e.g. INTERNAL, tool "getWeather" failed
      res = await ai.generate({ ...opts, messages: res.messages }); // safe to resend
    }
    aborted means the caller stopped it (abort signal, timeout, maxTurns); failed means something broke. Errors before the request resolves (unknown model/tool, invalid options) still throw.
  • Agents: retry a failed turn with send({}). A failed agent turn throws AgentError (from genkit/beta/client), but the chat has already adopted the resume point. await chat.send({}) re-runs the turn from there:
    try {
      await chat.send('Book the full itinerary.');
    } catch (err) {
      if (err instanceof AgentError) await chat.send({});
      else throw err;
    }
  • Recoverable domain errors belong in tool output. Return { ok: false, reason: '...' } from the tool when the model can fix the input; throw only when the system can't continue.

Multimodal and Image Generation

  • Missing responseModalities: When using image generation models (like gemini-nano-banana-2.1), you MUST specify the response modalities in the config.
    config: {
      responseModalities: ["TEXT", "IMAGE"]
    }
    Failure to do so will result in errors or incorrect output format.

Audio and Speech Generation

  • Raw PCM Data vs MP3: Some providers (e.g., Google GenAI) return raw PCM data, while others (e.g., OpenAI) return MP3.
    • DO NOT assume MP3 format.
    • DO NOT embed raw PCM in HTML audio tags.
    • Action: Run genkit docs:search "speech audio" to find provider-specific conversion steps (e.g., PCM to WAV).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts13d5 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    The skill is a comprehensive development guide for the Genkit JS framework. It provides technical instructions, code examples, and troubleshooting steps. All referenced tools and packages are official or standard industry dependencies. No security risks were identified.

  • Socket13d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

  • Runlayer8mo

    6 files scanned · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d12c988. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 2 weeks ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}
  • TypeScript
  • genkit
  • nodejs
  • ai-agents
  • flows
  • llm
  • google-ai
  • openai
  • anthropic

README badge

README badge for genkit-ai/skills/developing-genkit-js

Develop AI-powered applications using Genkit in Node.js and TypeScript, including flows, tools, and multi-model integrations. Covers Genkit CLI setup, flow definition with schema validation, provider selection (Google AI, OpenAI, Anthropic, Ollama), and error troubleshooting for version 1.29.0 and later.

Generated from the current SKILL.md.

What Genkit CLI version does this skill require?
Minimum CLI version 1.29.0. Verify with `genkit --version` and upgrade with `npm install -g genkit-cli@^1.29.0` if needed.
Does this skill cover pre-1.0 Genkit or older versions?
No. Genkit went through a major breaking API change. This skill assumes v1.x (1.29.0+) and will not reliably handle pre-1.0 code or deprecated APIs.
What AI providers does this skill support?
Genkit is provider-agnostic and supports Google AI, OpenAI, Anthropic, Ollama, and others. The skill defaults to Google AI if no provider is specified.
How should I troubleshoot Genkit errors?
Always read the Common Errors reference first to identify known patterns and their fixes. Use `genkit docs:search` only if the error is not documented there.
Does this skill work with Next.js, Firebase, or Express?
Yes. The skill detects your framework via package.json and adapts the implementation to framework-specific patterns like @genkit-ai/next or @genkit-ai/firebase.

Generated from the current SKILL.md. These answers refresh after source changes.