Edits history of script submission #12980 for ' Generate image from prompt (recraft)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Recraft = {
      apiKey: string;
    };
    /**
     * Generate image from prompt
     *
     */
    export async function main(
      auth: Recraft,
      body: {
        block_nsfw?: false | true;
        calculate_features?: false | true;
        controls?: {
          artistic_level?: number;
          background_color?: { rgb?: number[]; std?: number[]; weight?: number };
          colors?: { rgb?: number[]; std?: number[]; weight?: number }[];
          no_text?: false | true;
        };
        model?:
          | "refm1"
          | "recraft20b"
          | "recraftv2"
          | "recraftv3"
          | "flux1_1pro"
          | "flux1dev";
        n?: number;
        prompt: string;
        random_seed?: number;
        response_format?: "url" | "b64_json";
        size?:
          | "1024x1024"
          | "1365x1024"
          | "1024x1365"
          | "1536x1024"
          | "1024x1536"
          | "1820x1024"
          | "1024x1820"
          | "1024x2048"
          | "2048x1024"
          | "1434x1024"
          | "1024x1434"
          | "1024x1280"
          | "1280x1024"
          | "1024x1707"
          | "1707x1024";
        style?:
          | "digital_illustration"
          | "icon"
          | "realistic_image"
          | "vector_illustration";
        style_id?: string;
        substyle?:
          | "2d_art_poster"
          | "3d"
          | "80s"
          | "glow"
          | "grain"
          | "hand_drawn"
          | "infantile_sketch"
          | "kawaii"
          | "pixel_art"
          | "psychedelic"
          | "seamless"
          | "voxel"
          | "watercolor"
          | "broken_line"
          | "colored_outline"
          | "colored_shapes"
          | "colored_shapes_gradient"
          | "doodle_fill"
          | "doodle_offset_fill"
          | "offset_fill"
          | "outline"
          | "outline_gradient"
          | "uneven_fill"
          | "70s"
          | "cartoon"
          | "doodle_line_art"
          | "engraving"
          | "flat_2"
          | "line_art"
          | "linocut"
          | "b_and_w"
          | "enterprise"
          | "hard_flash"
          | "hdr"
          | "motion_blur"
          | "natural_light"
          | "studio_portrait"
          | "line_circuit"
          | "2d_art_poster_2"
          | "engraving_color"
          | "flat_air_art"
          | "hand_drawn_outline"
          | "handmade_3d"
          | "stickers_drawings";
        text_layout?: { bbox: number[][]; text: string }[];
      },
    ) {
      const url = new URL(`https://external.api.recraft.ai/v1/images/generations`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago