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.

referencesexamples.md

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

Genkit Examples

This reference contains minimal, reproducible examples (MREs) for common Genkit patterns.

Disclaimer: These examples use Google AI models (googleAI, gemini-*) for demonstration. The patterns apply to any provider. To use a different provider:

  1. Search the docs for the correct plugin: genkit docs:search "plugins".
  2. Install and configure the plugin.
  3. Swap the model reference in the code.

Basic Text Generation

import { genkit } from "genkit";
import { googleAI } from "@genkit-ai/google-genai";

const ai = genkit({
  plugins: [googleAI()],
});

const { text } = await ai.generate({
  model: googleAI.model('gemini-flash-latest'),
  prompt: 'Tell me a story in a pirate accent',
});

Structured Output

import { z } from 'genkit';

const JokeSchema = z.object({
  setup: z.string().describe('The setup of the joke'),
  punchline: z.string().describe('The punchline'),
});

const response = await ai.generate({
  model: googleAI.model('gemini-flash-latest'),
  prompt: 'Tell me a joke about developers.',
  output: { schema: JokeSchema },
});

// response.output is strongly typed
const joke = response.output; 
if (joke) {
  console.log(`${joke.setup} ... ${joke.punchline}`);
}

Streaming

const { stream, response } = ai.generateStream({
  model: googleAI.model('gemini-flash-latest'),
  prompt: 'Tell a long story about a developer using Genkit.',
});

for await (const chunk of stream) {
  console.log(chunk.text);
}

// Await the final response
const finalResponse = await response;
console.log('Complete:', finalResponse.text);

Advanced Configuration

Thinking Mode

Enable "thinking" process for complex reasoning tasks.

const response = await ai.generate({
  model: googleAI.model('gemini-pro-latest'),
  prompt: 'what is heavier, one kilo of steel or one kilo of feathers',
  config: {
    thinkingConfig: {
      thinkingLevel: 'HIGH', // or 'LOW'
      includeThoughts: true, // Returns thought process in response
    },
  },
});

Google Search Grounding

Enable models to access current information via Google Search.

const response = await ai.generate({
  model: googleAI.model('gemini-flash-latest'),
  prompt: 'What are the top tech news stories this week?',
  config: {
    googleSearchRetrieval: true,
  },
});

// Access grounding metadata (sources)
const groundingMetadata = (response.custom as any)?.candidates?.[0]?.groundingMetadata;
if (groundingMetadata) {
  console.log('Sources:', groundingMetadata.groundingChunks);
}

Multimodal Generation

Image Generation / Editing

Set responseModalities: ['TEXT', 'IMAGE'] when using image generation models. Image settings (aspect ratio, size) go in config.imageConfig.

// Generate an image
const { media } = await ai.generate({
  model: googleAI.model('gemini-nano-banana-2.1'),
  config: { responseModalities: ['TEXT', 'IMAGE'] },
  prompt: "generate a picture of a unicorn wearing a space suit on the moon",
});
// media.url contains the data URI
// Edit an image
const { media } = await ai.generate({
  model: googleAI.model('gemini-nano-banana-2.1'),
  config: { responseModalities: ['TEXT', 'IMAGE'] },
  prompt: [
    { text: "change the person's outfit to a banana costume" },
    { media: { url: "https://example.com/photo.jpg" } },
  ],
});

Speech Generation (TTS)

Generate audio from text.

import { Buffer } from 'node:buffer';
import { writeFile } from 'node:fs/promises';

const { media } = await ai.generate({
  model: googleAI.model('gemini-3.8-flash-tts'),
  config: {
    speechConfig: {
      voiceConfig: {
        prebuiltVoiceConfig: { voiceName: 'Algenib' }, // Options: 'Puck', 'Charon', 'Kore', etc.
      },
    },
  },
  prompt: 'Genkit is an amazing library',
});

// gemini-3.8-flash-tts returns a complete WAV file (audio/wav) as a data URI.
// Streamed requests return raw PCM chunks unless you set
// config.audioFormat: { mimeType: 'audio/wav' }.
if (media?.url) {
  const wav = Buffer.from(media.url.slice(media.url.indexOf(',') + 1), 'base64');
  await writeFile('output.wav', wav);
}

Older preview TTS models (gemini-2.5-*-preview-tts, gemini-3.1-flash-tts-preview) are deprecated and return raw PCM that needs conversion to WAV. Run genkit docs:search "speech audio" for conversion code.

Embeddings

const embedder = googleAI.embedder('gemini-embedding-001');

const embeddings = await ai.embed({ embedder, content: 'The sky is blue.' });
const vector = embeddings[0].embedding; // number[]

const batch = await ai.embedMany({
  embedder,
  content: ['The sky is blue.', 'Grass is green.'],
});

// Optional tuning (default is 3072 dimensions)
await ai.embed({
  embedder,
  content: 'The sky is blue.',
  options: { outputDimensionality: 768, taskType: 'RETRIEVAL_DOCUMENT' },
});

Common embedders: gemini-embedding-001 (text), gemini-embedding-2 (multimodal: text, image, video). Plain string ids (embedder: 'googleai/gemini-embedding-001') also work.

Multimodal input is passed as a document:

const imageEmbeddings = await ai.embed({
  embedder: googleAI.embedder('gemini-embedding-2'),
  content: {
    content: [{ media: { url: 'data:image/png;base64,...', contentType: 'image/png' } }],
  },
});

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.