Create civitai curl api get and post for load model safetensor using (UNR:AIR) code,
- User
Create civitai curl api get and post for load model safetensor using (UNR:AIR) code,
- Assistant
Create civitai curl api get and post for load model safetensor using (UNR:AIR) code,
To interact with the Civitai API using curl for getting details about a model and downloading its safetensor file using the (UNR:AIR) code, you can follow these steps:
Note: Replace YOUR_API_KEY with your actual API key if authentication is required. As of my knowledge cutoff in October 2023, the Civitai API does not require authentication for public model information and downloads.
First, use the Civitai API to search for the model with the (UNR:AIR) code. Since the colon : is a special character in URLs, you need to URL-encode it as %3A.
Command:
curl -s 'https://civitai.com/api/v1/models?query=UNR%3AAIR' > models.json
This command searches for models matching UNR:AIR and saves the JSON response to models.json.
You need the model ID to get detailed information. You can extract it using jq, a command-line JSON processor. If you don't have jq, you can install it or parse the JSON manually.
Command:
MODEL_ID=$(jq '.items[0].id' models.json)
echo "Model ID: $MODEL_ID"
This command retrieves the first model's ID from the search results.
Use the model ID to get detailed information about the model, including download URLs.
Command:
curl -s "https://civitai.com/api/v1/models/$MODEL_ID" > model_details.json
This saves the detailed model information to model_details.json.
Extract the download URL for the safetensor file from the model details.
Command:
DOWNLOAD_URL=$(jq -r '.modelVersions[0].files[] | select(.format == "SafeTensor") | .downloadUrl' model_details.json)
echo "Download URL: $DOWNLOAD_URL"
This command searches for the first file with the format SafeTensor and extracts its download URL.
Use the download URL to download the safetensor file.
Command:
curl -L -o 'model.safetensors' "$DOWNLOAD_URL"
-L tells curl to follow redirects.-o specifies the output filename.You can verify that the file has been downloaded correctly by checking its size or using a checksum.
Command:
ls -lh model.safetensors
Putting it all together in a script:
#!/bin/bash
# Search for the model
curl -s 'https://civitai.com/api/v1/models?query=UNR%3AAIR' > models.json
# Extract the model ID
MODEL_ID=$(jq '.items[0].id' models.json)
echo "Model ID: $MODEL_ID"
# Get detailed model information
curl -s "https://civitai.com/api/v1/models/$MODEL_ID" > model_details.json
# Extract the download URL
DOWNLOAD_URL=$(jq -r '.modelVersions[0].files[] | select(.format == "SafeTensor") | .downloadUrl' model_details.json)
echo "Download URL: $DOWNLOAD_URL"
# Download the safetensor file
curl -L -o 'model.safetensors' "$DOWNLOAD_URL"
# Verify the downloaded file
ls -lh model.safetensors
Authentication: If the API requires authentication for certain endpoints or actions, include your API key in the header.
Example with Authentication:
curl -H 'Authorization: Bearer YOUR_API_KEY' -s 'https://civitai.com/api/v1/models?query=UNR%3AAIR' > models.json
Handling Multiple Versions: If the model has multiple versions, you might want to iterate over modelVersions to select the desired one.
Error Handling: Add checks to ensure that the variables are not empty and handle cases where the model or file is not found.
As of October 2023, posting (uploading) a model to Civitai via the API is not typically supported for general users due to security and moderation policies. Model uploads are usually done through the website's interface, where additional information and validations are required.
If you have special permissions or Civitai has updated their API to allow uploads, you would need to:
Obtain an API Key with Upload Permissions: Ensure your API key has the necessary permissions.
Use the Correct Endpoint and Parameters: The API endpoint for uploading may require specific parameters and file handling, typically using multipart/form-data.
Construct the curl Command:
Example:
curl -X POST "https://civitai.com/api/v1/models" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "name=Model Name" \
-F "description=Description of the model" \
-F "files=@/path/to/model.safetensors"
Note: This is a hypothetical example. You must refer to the official API documentation or contact Civitai support for the correct procedure.
Always refer to the official Civitai API Documentation for the most up-to-date and accurate information.
Be mindful of Civitai's terms of service and respect any rate limits or usage policies.
Ensure you have the right to download and use the models, and comply with any licensing requirements.