Creating Flows
Flows are observable, traceable AI workflows. They wrap your AI logic to provide type safety, debugging support, and easy deployment as HTTP endpoints.
Defining a flow
Section titled “Defining a flow”// Simple flow with typed input/outputFlow<String, String, Void> greetFlow = genkit.defineFlow( "greeting", String.class, String.class, name -> "Hello, " + name + "!");AI-powered flows
Section titled “AI-powered flows”// Flow with AI generation and context accessFlow<String, String, Void> jokeFlow = genkit.defineFlow( "tellJoke", String.class, String.class, (ctx, topic) -> { ModelResponse response = genkit.generate( GenerateOptions.builder() .model("openai/gpt-4o-mini") .prompt("Tell me a short, funny joke about: " + topic) .build()); return response.getText(); });Running flows
Section titled “Running flows”// Run a flow programmaticallyString result = genkit.runFlow("greeting", "World");// Returns: "Hello, World!"Flows as HTTP endpoints
Section titled “Flows as HTTP endpoints”When using the Jetty or Spring Boot plugins, all defined flows are automatically exposed as HTTP endpoints:
# Call a flow via HTTPcurl -X POST http://localhost:8080/api/flows/tellJoke \ -H "Content-Type: application/json" \ -d '{"data": "pirates"}'Why use flows?
Section titled “Why use flows?”- Type-safe inputs and outputs — Define clear schemas for your data
- Integrates with the Dev UI — Test and debug flows visually
- Easy deployment — Automatically exposed as HTTP endpoints
- Built-in tracing — Every flow execution is traced with OpenTelemetry
- Composable — Flows can call other flows
Next steps
Section titled “Next steps” Tool Calling Let models call your functions
Streaming Stream flow output in real-time
Dev UI & CLI Debug flows visually