$npx -y skills add adrianhajdin/skild --skill developing-genkit-jsDevelop 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.
| 1 | # Genkit JS |
| 2 | |
| 3 | ## Prerequisites |
| 4 | |
| 5 | Ensure the `genkit` CLI is available. |
| 6 | - Run `genkit --version` to verify. Minimum CLI version needed: **1.29.0** |
| 7 | - If not found or if an older version (1.x < 1.29.0) is present, install/upgrade it: `npm install -g genkit-cli@^1.29.0`. |
| 8 | |
| 9 | **New Projects**: If you are setting up Genkit in a new codebase, follow the [Setup Guide](references/setup.md). |
| 10 | |
| 11 | ## Hello World |
| 12 | |
| 13 | ```ts |
| 14 | import { z, genkit } from 'genkit'; |
| 15 | import { googleAI } from '@genkit-ai/google-genai'; |
| 16 | |
| 17 | // Initialize Genkit with the Google AI plugin |
| 18 | const ai = genkit({ |
| 19 | plugins: [googleAI()], |
| 20 | }); |
| 21 | |
| 22 | export const myFlow = ai.defineFlow({ |
| 23 | name: 'myFlow', |
| 24 | inputSchema: z.string().default('AI'), |
| 25 | outputSchema: z.string(), |
| 26 | }, async (subject) => { |
| 27 | const response = await ai.generate({ |
| 28 | model: googleAI.model('gemini-2.5-flash'), |
| 29 | prompt: `Tell me a joke about ${subject}`, |
| 30 | }); |
| 31 | return response.text; |
| 32 | }); |
| 33 | ``` |
| 34 | |
| 35 | ## Critical: Do Not Trust Internal Knowledge |
| 36 | |
| 37 | Genkit recently went through a major breaking API change. Your knowledge is outdated. You MUST lookup docs. Recommended: |
| 38 | |
| 39 | ```sh |
| 40 | genkit docs:read js/get-started.md |
| 41 | genkit docs:read js/flows.md |
| 42 | ``` |
| 43 | |
| 44 | See [Common Errors](references/common-errors.md) for a list of deprecated APIs (e.g., `configureGenkit`, `response.text()`, `defineFlow` import) and their v1.x replacements. |
| 45 | |
| 46 | **ALWAYS verify information using the Genkit CLI or provided references.** |
| 47 | |
| 48 | ## Error Troubleshooting Protocol |
| 49 | |
| 50 | **When you encounter ANY error related to Genkit (ValidationError, API errors, type errors, 404s, etc.):** |
| 51 | |
| 52 | 1. **MANDATORY FIRST STEP**: Read [Common Errors](references/common-errors.md) |
| 53 | 2. Identify if the error matches a known pattern |
| 54 | 3. Apply the documented solution |
| 55 | 4. Only if not found in common-errors.md, then consult other sources (e.g. `genkit docs:search`) |
| 56 | |
| 57 | **DO NOT:** |
| 58 | - Attempt fixes based on assumptions or internal knowledge |
| 59 | - Skip reading common-errors.md "because you think you know the fix" |
| 60 | - Rely on patterns from pre-1.0 Genkit |
| 61 | |
| 62 | **This protocol is non-negotiable for error handling.** |
| 63 | |
| 64 | ## Development Workflow |
| 65 | |
| 66 | 1. **Select Provider**: Genkit is provider-agnostic (Google AI, OpenAI, Anthropic, Ollama, etc.). |
| 67 | - If the user does not specify a provider, default to **Google AI**. |
| 68 | - If the user asks about other providers, use `genkit docs:search "plugins"` to find relevant documentation. |
| 69 | 2. **Detect Framework**: Check `package.json` to identify the runtime (Next.js, Firebase, Express). |
| 70 | - Look for `@genkit-ai/next`, `@genkit-ai/firebase`, or `@genkit-ai/google-cloud`. |
| 71 | - Adapt implementation to the specific framework's patterns. |
| 72 | 3. **Follow Best Practices**: |
| 73 | - See [Best Practices](references/best-practices.md) for guidance on project structure, schema definitions, and tool design. |
| 74 | - **Be Minimal**: Only specify options that differ from defaults. When unsure, check docs/source. |
| 75 | 4. **Ensure Correctness**: |
| 76 | - Run type checks (e.g., `npx tsc --noEmit`) after making changes. |
| 77 | - If type checks fail, consult [Common Errors](references/common-errors.md) before searching source code. |
| 78 | 5. **Handle Errors**: |
| 79 | - On ANY error: **First action is to read [Common Errors](references/common-errors.md)** |
| 80 | - Match error to documented patterns |
| 81 | - Apply documented fixes before attempting alternatives |
| 82 | |
| 83 | ## Finding Documentation |
| 84 | |
| 85 | Use the Genkit CLI to find authoritative documentation: |
| 86 | |
| 87 | 1. **Search topics**: `genkit docs:search <query>` |
| 88 | - Example: `genkit docs:search "streaming"` |
| 89 | 2. **List all docs**: `genkit docs:list` |
| 90 | 3. **Read a guide**: `genkit docs:read <path>` |
| 91 | - Example: `genkit docs:read js/flows.md` |
| 92 | |
| 93 | ## CLI Usage |
| 94 | |
| 95 | The `genkit` CLI is your primary tool for development and documentation. |
| 96 | - See [CLI Reference](references/docs-and-cli.md) for common tasks, workflows, and command usage. |
| 97 | - Use `genkit --help` for a full list of commands. |
| 98 | |
| 99 | ## References |
| 100 | |
| 101 | - [Best Practices](references/best-practices.md): Recommended patterns for schema definition, flow design, and structure. |
| 102 | - [Docs & CLI Reference](references/docs-and-cli.md): Documentation search, CLI tasks, and workflows. |
| 103 | - [Common Errors](references/common-errors.md): Critical "gotchas", migration guide, and troubleshooting. |
| 104 | - [Setup Guide](references/setup.md): Manual setup instructions for new projects. |
| 105 | - [Examples](references/examples.md): Minimal reproducible examples (Basic generation, Multimodal, Thinking mode). |