avatar

ShīnChvën ✨

Effective Accelerationism

Powered by Druid

How to Download AI Models from CivitAI Using Cookies in Your Code

Sat Jan 06 2024

Introduction

CivitAI is a platform that offers a variety of models, which can be downloaded and used for various AI tasks. However, sometimes you need to be logged in to download certain models, which can be straightforward when you're using a web browser but a bit tricky when you want to automate the process through code or a terminal. Fortunately, there's a workaround: using cookies to authenticate your download request. This is especially useful if you want to integrate model downloads into your scripts or workflows.

In this post, we'll walk you through the steps to get the necessary cookies and use them to download models from CivitAI using the command line.

Step 1: Get Cookies

First things first, you need to obtain the cookies that will authenticate your download request. This is how you can prove to CivitAI that you have the right to access the models.

Using Browser Extensions

The easiest method to get these cookies is by using browser extensions. Depending on your preferred browser, you can choose from several options:

These extensions allow you to view and export the cookies used by websites, including CivitAI, when you're logged in.

Exporting Cookies

After installing the extension, log in to CivitAI and use the extension to export the cookies. Make sure to export them in the Netscape HTTP Cookie File format. This is a standard format that command-line tools can understand.

Once you have exported the cookies, save the file as cookies.txt on your local machine. Make sure to keep this file secure, as it contains your authentication information.

Step 2: Download Models

With your cookies ready, you can now proceed to download the models using the wget command. This is a powerful utility available on most Unix-like systems that can download files from the web.

Here's the syntax you'll use:

wget --load-cookies cookies.txt <model_url> -O <output_filename>

Replace <model_url> with the actual URL of the model you wish to download and <output_filename> with the desired name for the downloaded file.

Conclusion

Downloading AI models from CivitAI doesn't have to be a manual process. By using cookies for authentication, you can automate downloads and integrate them into your workflows or scripts. This can save you time and help maintain a smooth development process.

Remember to handle your cookies carefully and only use them on secure, trusted systems. With this method, you'll be able to access the models you need, when you need them, without the hassle of manual downloads.