Creates an Azure Functions handler for a Genkit flow.
This function wraps a Genkit flow to create an Azure Functions HTTP handler that:
The Genkit flow to wrap
A CallableAzureFunction with handler, flow, run, stream, and flowName
import { genkit, z } from 'genkit';
import { onCallGenkit, azureOpenAI, gpt4o } from 'genkitx-azure-openai';
const ai = genkit({
plugins: [azureOpenAI()],
model: gpt4o,
});
const myFlow = ai.defineFlow(
{ name: 'myFlow', inputSchema: z.string(), outputSchema: z.string() },
async (input) => {
const { text } = await ai.generate({ prompt: input });
return text;
}
);
// Automatically registered as POST /api/myFlow (uses flow name)
export const myFlowFn = onCallGenkit(myFlow);
import { UserFacingError } from 'genkit';
import type { ContextProvider } from 'genkit/context';
interface AuthContext {
auth: { user: { id: string; name: string } };
}
const authProvider: ContextProvider<AuthContext> = async (req) => {
const token = req.headers['authorization'];
if (!token) {
throw new UserFacingError('UNAUTHENTICATED', 'Missing auth token');
}
const user = await verifyToken(token);
return { auth: { user } };
};
// Registered as POST /api/myFlow (uses flow name)
export const mySecureFlowFn = onCallGenkit(
{ contextProvider: authProvider },
myFlow
);
Creates an Azure Functions handler for a Genkit flow with options.
Configuration options for the Azure Functions handler
The Genkit flow to wrap
A CallableAzureFunction with handler, flow, run, stream, and flowName
Creates an Azure Functions handler for a Genkit flow.
This function wraps a Genkit flow to create an Azure Functions HTTP handler that:
The Genkit flow to wrap
A CallableAzureFunction with handler, flow, run, stream, and flowName
import { genkit, z } from 'genkit';
import { onCallGenkit, azureOpenAI, gpt4o } from 'genkitx-azure-openai';
const ai = genkit({
plugins: [azureOpenAI()],
model: gpt4o,
});
const myFlow = ai.defineFlow(
{ name: 'myFlow', inputSchema: z.string(), outputSchema: z.string() },
async (input) => {
const { text } = await ai.generate({ prompt: input });
return text;
}
);
// Automatically registered as POST /api/myFlow (uses flow name)
export const myFlowFn = onCallGenkit(myFlow);
import { UserFacingError } from 'genkit';
import type { ContextProvider } from 'genkit/context';
interface AuthContext {
auth: { user: { id: string; name: string } };
}
const authProvider: ContextProvider<AuthContext> = async (req) => {
const token = req.headers['authorization'];
if (!token) {
throw new UserFacingError('UNAUTHENTICATED', 'Missing auth token');
}
const user = await verifyToken(token);
return { auth: { user } };
};
// Registered as POST /api/myFlow (uses flow name)
export const mySecureFlowFn = onCallGenkit(
{ contextProvider: authProvider },
myFlow
);
Implementation of onCallGenkit