run_model
Execute any Fal.ai model with custom inputs to generate AI images, supporting real-time streaming and workflow integration.
Instructions
Run any Fal.ai model with custom parameters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Input parameters for the model | |
| model_id | Yes | The Fal.ai model endpoint ID | |
| stream | No | Whether to stream results |
Implementation Reference
- src/index.ts:286-322 (handler)Handler for run_model tool: parses input using RunModelSchema, then either streams or subscribes to fal.ai model execution based on stream flag, and returns JSON stringified result.case "run_model": { const params = RunModelSchema.parse(args); if (params.stream) { const stream = await fal.stream(params.model_id, { input: params.input, }); const events: any[] = []; for await (const event of stream) { events.push(event); } return { content: [ { type: "text", text: JSON.stringify(events, null, 2), }, ], }; } else { const result = await fal.subscribe(params.model_id, { input: params.input, logs: true, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } }
- src/index.ts:71-75 (schema)Zod schema defining input for run_model: model_id (required), input (required), stream (optional boolean).const RunModelSchema = z.object({ model_id: z.string().describe("The Fal.ai model endpoint ID (e.g., 'fal-ai/flux/dev')"), input: z.record(z.any()).describe("Input parameters for the model"), stream: z.boolean().default(false).optional().describe("Whether to stream results"), });
- src/index.ts:138-160 (registration)Registration of run_model tool in the list of tools returned by ListToolsRequestHandler, including name, description, and inputSchema matching the Zod schema.{ name: "run_model", description: "Run any Fal.ai model with custom parameters", inputSchema: { type: "object", properties: { model_id: { type: "string", description: "The Fal.ai model endpoint ID", }, input: { type: "object", description: "Input parameters for the model", }, stream: { type: "boolean", description: "Whether to stream results", default: false, }, }, required: ["model_id", "input"], }, },