Skip to main content
Glama

run_model

Execute AI image generation models on Fal.ai by specifying model endpoints and custom input parameters, enabling workflow automation and real-time processing.

Instructions

Run any Fal.ai model with custom parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
model_idYesThe Fal.ai model endpoint ID
inputYesInput parameters for the model
streamNoWhether to stream results

Implementation Reference

  • Handler function for 'run_model' tool: parses input with RunModelSchema, then either streams or subscribes to the specified Fal.ai model using fal.stream or fal.subscribe, returning JSON results.
    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),
            },
          ],
        };
      }
    }
  • Zod schema defining input parameters for the 'run_model' tool: model_id, input, and optional stream flag.
    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)
    Tool registration 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"],
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gravicity-archive/fal-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server