### Install ComfyUI Dependencies and Run Source: https://replicate.com/docs/guides/extend/comfyui.md This snippet shows how to clone the ComfyUI repository, set up a virtual environment, install Python dependencies, and start the ComfyUI application. ```bash git clone https://github.com/comfyanonymous/ComfyUI # Optional: You might want to use a virtual environment cd ComfyUI python -m venv venv source venv/bin/activate # Install ComfyUI dependencies pip install -r requirements.txt ``` ```bash python main.py ``` -------------------------------- ### Setup Replicate Environment Source: https://replicate.com/docs/guides/extend/comfyui.md Install the necessary Python client library and configure the API token environment variable required for authentication. ```bash pip install replicate export REPLICATE_API_TOKEN=r8-********************************* ``` -------------------------------- ### Install Replicate Python Client Source: https://replicate.com/docs/guides/push-a-model Install the Replicate Python client library using pip. ```bash pip install replicate ``` -------------------------------- ### Install and Run Vercel CLI Source: https://replicate.com/docs/get-started/nextjs Install the Vercel CLI globally and run it to initiate the deployment process, including login and app creation. ```bash npx vercel ``` -------------------------------- ### Install the Python Library Source: https://replicate.com/docs/get-started/python.md Install the official Replicate Python client library using pip. ```APIDOC ## Install the Python Library ### Description Install the open-source Python client for the Replicate API using pip. ### Method `pip` ### Endpoint N/A ### Parameters None ### Request Example ```plaintext pip install replicate ``` ### Response N/A ``` -------------------------------- ### Initialize Node.js Project and Install Replicate Client Source: https://replicate.com/docs/get-started/nodejs.md Manually set up a new Node.js project by creating a directory, initializing npm, setting the module type, and installing the official Replicate JavaScript client. ```shell mkdir my-replicate-app cd my-replicate-app npm init -y npm pkg set type=module npm install replicate ``` -------------------------------- ### Install Replicate Python Client Source: https://replicate.com/docs/guides/run/upscale-images-with-ai-models.md Commands to install the official Replicate Python package and configure the API token environment variable. ```bash pip install replicate export REPLICATE_API_TOKEN= ``` -------------------------------- ### List Examples for a Replicate Model Source: https://replicate.com/docs/reference/http.md Retrieves a list of example predictions made using a specific model. These examples are saved by the model author to illustrate the model's capabilities. The response is paginated. ```shell curl -s \ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \ https://api.replicate.com/v1/models/replicate/hello-world/examples ``` -------------------------------- ### Start Local Replicate MCP Server Source: https://replicate.com/docs/reference/mcp.md Use this command to start the local MCP server. It downloads and executes the replicate-mcp npm package. Press Ctrl+c to stop the server. ```plaintext npx -y replicate-mcp ``` -------------------------------- ### Install Cog Source: https://replicate.com/docs/guides/push-a-model Installs the Cog tool to your system. Ensure you have curl and appropriate permissions. ```bash sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m` sudo chmod +x /usr/local/bin/cog ``` -------------------------------- ### Install Cog on Linux Instance Source: https://replicate.com/docs/guides/build/get-a-gpu-on-lambda-labs.md Downloads and installs the latest version of the Cog binary to the system path and grants it execution permissions. ```sh sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m` sudo chmod +x /usr/local/bin/cog ``` -------------------------------- ### Install Deno Source: https://replicate.com/docs/reference/mcp.md This command installs Deno, a JavaScript and TypeScript runtime, which is required for executing code in the sandboxed environment when using Code mode. ```bash curl -fsSL https://deno.land/install.sh | sh ``` -------------------------------- ### Install Replicate Python Library Source: https://replicate.com/docs/get-started/python.md Installs the open-source Python client for the Replicate API using pip. This is the first step to programmatically interact with Replicate models. ```plaintext pip install replicate ``` -------------------------------- ### GET /v1/hardware Source: https://replicate.com/docs/reference/http.md Retrieve a list of available hardware configurations for running models. ```APIDOC ## GET /v1/hardware ### Description Returns a list of available hardware objects that can be used for model execution. ### Method GET ### Endpoint https://api.replicate.com/v1/hardware ### Response #### Success Response (200) - **name** (string) - The display name of the hardware. - **sku** (string) - The unique identifier/SKU for the hardware. #### Response Example [ {"name": "CPU", "sku": "cpu"}, {"name": "Nvidia T4 GPU", "sku": "gpu-t4"} ] ``` -------------------------------- ### Copy Environment Variables Example (Shell) Source: https://replicate.com/docs/guides/extend/openai-realtime.md Copies the example environment variables file to a new file named .dev.vars. This is a common practice to set up local development environment variables based on a template. ```shell cp .dev.vars.example .dev.vars ``` -------------------------------- ### GET /v1/hardware Source: https://replicate.com/docs/topics/models/create-a-model.md Retrieves a list of available hardware configurations for running models. ```APIDOC ## GET /v1/hardware ### Description Lists all available hardware types that can be used to run models on Replicate. ### Method GET ### Endpoint https://api.replicate.com/v1/hardware ### Response #### Success Response (200) - **name** (string) - The display name of the hardware. - **sku** (string) - The SKU identifier for the hardware. #### Response Example [ { "name": "Nvidia T4 GPU", "sku": "gpu-t4" }, { "name": "Nvidia A40 (Large) GPU", "sku": "gpu-a40-large" } ] ``` -------------------------------- ### Wrangler Dev Output Example (Plain Text) Source: https://replicate.com/docs/guides/extend/openai-realtime.md Example output from the 'npm run dev' command, showing the status of the local Cloudflare worker, available bindings (secrets), and the local server URL. It also provides interactive options for managing the development server. ```plaintext > openai-realtime@0.0.0 dev > wrangler dev Your worker has access to the following bindings: - Vars: - OPENAI_API_KEY: "(hidden)" - REPLICATE_API_TOKEN: "(hidden)" ⎔ Starting local server... [wrangler:inf] Ready on http://localhost:3000 ╭───────────────────────────╮ │ [b] open a browser │ │ [d] open devtools │ │ [l] turn off local mode │ │ [c] clear console │ │ [x] to exit │ ╰───────────────────────────╯ ``` -------------------------------- ### Initialize Vinext Project Source: https://replicate.com/docs/guides/run/vinext.md Commands to clone the starter repository and install the necessary project dependencies. ```shell git clone https://github.com/replicate/getting-started-vinext cd getting-started-vinext npm install ``` -------------------------------- ### GET /v1/models/{model_owner}/{model_name}/examples Source: https://replicate.com/docs/reference/http.md Lists example predictions made using a specific model. These examples illustrate the model's capabilities and are saved by the model author. ```APIDOC ## GET /v1/models/{model_owner}/{model_name}/examples ### Description Lists example predictions made using the model. These are predictions that were saved by the model author as illustrative examples of the model’s capabilities. If you want all the examples for a model, use this operation. If you just want the model’s default example, you can use the `models.get` operation instead. ### Method GET ### Endpoint https://api.replicate.com/v1/models/{model_owner}/{model_name}/examples ### Parameters #### Path Parameters - **model_owner** (string) - Required - The name of the user or organization that owns the model. - **model_name** (string) - Required - The name of the model. ### Request Example ```shell curl -s \ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \ https://api.replicate.com/v1/models/replicate/hello-world/examples ``` ### Response #### Success Response (200) A pagination object containing a list of example predictions. #### Response Example ```json { "next": "https://api.replicate.com/v1/models/replicate/hello-world/examples?cursor=...", "previous": "https://api.replicate.com/v1/models/replicate/hello-world/examples?cursor=...", "results": [...] } ``` ``` -------------------------------- ### Define Python Dependencies in cog.yaml Source: https://replicate.com/docs/guides/push-a-model Specifies the Python version and packages to be installed in the Docker image. Example uses PyTorch 2.3.1. ```yaml build: python_version: "3.12" python_packages: - "torch==2.3.1" ``` -------------------------------- ### Configure Webhook Events Filter (JSON) Source: https://replicate.com/docs/topics/webhooks/receive-webhook.md Example JSON payload to configure Replicate to send webhooks only for 'start' and 'completed' events. ```json { "input": { "text": "Alice" }, "webhook": "https://example.com/my-webhook", "webhook_events_filter": ["start", "completed"] } ``` -------------------------------- ### Stream File Data from Next.js Handler Source: https://replicate.com/docs/how-does-replicate-work Implement a Next.js API route to stream file data returned from a Replicate prediction. This example shows a basic GET handler. ```javascript export async function GET(request: Request) { const output = await replicate.run(...); return new Response(output); } ``` -------------------------------- ### Initialize Project Directory Source: https://replicate.com/docs/guides/run/discord-bot.md Commands to create a new project directory and navigate into it using the command line. ```shell mkdir flux-bot cd flux-bot ``` -------------------------------- ### Run Cog Model Prediction Source: https://replicate.com/docs/guides/build/get-a-gpu-on-brev.md Command to execute a Cog model and get predictions. It navigates to the model directory and uses `cog predict` with input arguments. The example shows predicting with the input text 'world'. ```plaintext cd my-model cog predict -i text="world" ``` -------------------------------- ### Run ControlNet Tile Upscaler with JavaScript Source: https://replicate.com/docs/guides/run/upscale-images-with-ai-models.md Demonstrates how to initialize the Replicate client in Node.js, execute the high-resolution ControlNet tile model with specific input parameters, and save the resulting image to the local filesystem. ```bash npm install replicate export REPLICATE_API_TOKEN= ``` ```javascript import Replicate from "replicate"; import fs from "fs/promises"; const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN, }); const output = await replicate.run( "batouresearch/high-resolution-controlnet-tile:latest", { input: { hdr: 0.2, image: "https://replicate.delivery/pbxt/K5vab12temDjc8jOnWFJ3p4RD7YWPQ3nuCyXpaRmN9yB8M1h/f84e7869-32ca-444b-a720-19e4325f4347.jpeg", steps: 20, prompt: "a woman wearing a colorful suit", scheduler: "DDIM", creativity: 0.6, guess_mode: false, resolution: 2560, resemblance: 0.4, guidance_scale: 5 } } ); fs.writeFileSync("output.png", output[0]); ``` -------------------------------- ### Example Training Request Body (JSON) Source: https://replicate.com/docs/reference/http.md A sample JSON object representing the data required to start a new model training job. It includes the destination for the trained model, the input data for training, and an optional webhook URL. ```json { "destination": "{new_owner}/{new_name}", "input": { "train_data": "https://example.com/my-input-images.zip" }, "webhook": "https://example.com/my-webhook" } ``` -------------------------------- ### Get Model Details using cURL Source: https://replicate.com/docs/reference/http.md This example shows how to retrieve information about a specific model using a cURL command. It requires the model owner and model name in the URL and uses the API token for authentication. The response is a JSON object containing model details. ```shell curl -s \n -H "Authorization: Bearer $REPLICATE_API_TOKEN" \n https://api.replicate.com/v1/models/replicate/hello-world ``` -------------------------------- ### Initialize Cog Project Source: https://replicate.com/docs/guides/build/push-a-model.md Navigate to your model directory and run the initialization command to generate the necessary configuration files. ```bash cd path/to/your/model cog init ``` -------------------------------- ### Scaffold Node.js Project with create-replicate Source: https://replicate.com/docs/get-started/nodejs.md Use the `create-replicate` npm package to quickly scaffold a new Node.js project configured to run models on Replicate. This command automates project setup, including writing starter code and installing dependencies. You can optionally specify a model to use. ```shell npx create-replicate npx create-replicate --model black-forest-labs/flux-schnell ``` -------------------------------- ### GET /v1/webhooks/default/secret Source: https://replicate.com/docs/reference/http.md Get the signing secret for the default webhook endpoint. ```APIDOC ## GET /v1/webhooks/default/secret ### Description Retrieves the signing secret used to verify that incoming webhook requests originate from Replicate. ### Method GET ### Endpoint https://api.replicate.com/v1/webhooks/default/secret ### Response #### Success Response (200) - **key** (string) - The webhook signing secret. #### Response Example { "key": "whsec_..." } ``` -------------------------------- ### Clone Starter Project (Shell) Source: https://replicate.com/docs/guides/extend/openai-realtime.md Clones the starter repository for the OpenAI Realtime project from GitHub using Git. This command downloads the project files to your local machine, setting up the initial project structure. ```shell git clone https://github.com/replicate/getting-started-openai-realtime openai-realtime-starter cd openai-realtime-starter ``` -------------------------------- ### Run Real-ESRGAN with Python Source: https://replicate.com/docs/guides/run/upscale-images-with-ai-models.md Example of using the Replicate Python client to run the Real-ESRGAN model. It takes an image URL as input and saves the resulting upscaled image to a local file. ```python import replicate output = replicate.run( "nightmareai/real-esrgan:latest", input={ "image": "https://replicate.delivery/pbxt/Ing7Fa4YMk6YtcoG1YZnaK3UwbgDB5guRc5M2dEjV6ODNLMl/cat.jpg", "scale": 2, "face_enhance": False } ) # Save the output image with open('output.png', 'wb') as f: f.write(output[0].read()) ``` -------------------------------- ### Run Real-ESRGAN with Python Source: https://replicate.com/docs/guides/run/upscale-images-with-ai-models.md This snippet shows how to install the Replicate Python client, set your API token, and run the Real-ESRGAN model to enhance an image. ```APIDOC ## Install and Setup ### Description Install the Replicate Python client and set your API token as an environment variable. ### Command ```bash pip install replicate export REPLICATE_API_TOKEN= ``` ## Run Real-ESRGAN ### Description This example demonstrates how to use the `replicate.run` function to process an image with the `nightmareai/real-esrgan` model, specifying input parameters like image URL, scale, and face enhancement. ### Method `replicate.run()` ### Endpoint `"nightmareai/real-esrgan:latest"` ### Parameters #### Input Parameters - **image** (string) - Required - The URL of the image to enhance. - **scale** (integer) - Optional - The scaling factor for the image. - **face_enhance** (boolean) - Optional - Whether to enable face enhancement using GFPGAN. ### Request Example ```python import replicate output = replicate.run( "nightmareai/real-esrgan:latest", input={ "image": "https://replicate.delivery/pbxt/Ing7Fa4YMk6YtcoG1YZnaK3UwbgDB5guRc5M2dEjV6ODNLMl/cat.jpg", "scale": 2, "face_enhance": False } ) ``` ### Response #### Success Response (200) - **output** (list of file objects) - A list containing the enhanced image file(s). ### Response Example ```python # Save the output image with open('output.png', 'wb') as f: f.write(output[0].read()) ``` ``` -------------------------------- ### Update Installed Agent Skills Source: https://replicate.com/docs/reference/skills.md Pulls the latest versions of all agent skills that have been previously installed. ```plaintext npx skills update ``` -------------------------------- ### Run Ultimate SD Upscale with Python Source: https://replicate.com/docs/guides/run/upscale-images-with-ai-models.md Shows how to use the Replicate Python client to run the Ultimate SD Upscale model. It includes the necessary installation steps and the model execution call with prompt and denoising configurations. ```bash pip install replicate export REPLICATE_API_TOKEN= ``` ```python import replicate output = replicate.run( "fewjative/ultimate-sd-upscale:latest", input={ "image": "https://replicate.delivery/pbxt/KKOaCNy9baG5cUZfK3YvvePBqZeTxyvytifSo7pFOKLySQN2/ComfyUI_00004_.png", "steps": 20, "denoise": 0.4, "scheduler": "karras", "upscale_by": 2, "negative_prompt": "ugly, broken, weird", "positive_prompt": "a portrait photo of a cat in a green hoodie", } ) ``` -------------------------------- ### Install Cog CLI Source: https://replicate.com/docs/guides/build/optimize-models-with-pruna.md Installs the Cog tool for containerizing and deploying machine learning models. ```bash sh <(curl -fsSL https://cog.run/install.sh) ``` -------------------------------- ### Handle File Outputs (Python) Source: https://replicate.com/docs/get-started/python.md Explains how to manage models that produce file outputs, such as images or audio. It shows how to save a single generated image and how to handle multiple file outputs. ```python output = replicate.run( "black-forest-labs/flux-schnell", input={"prompt": "A majestic lion"} ) # Save the generated image with open('lion.png', 'wb') as f: f.write(output[0].read()) print("Image saved as lion.png") # Handle multiple outputs output = replicate.run( "black-forest-labs/flux-schnell", input={"prompt": "A majestic lion", "num_outputs": 2} ) for idx, file_output in enumerate(output): with open(f'output_{idx}.png', 'wb') as f: f.write(file_output.read()) ``` -------------------------------- ### Install Brev CLI Source: https://replicate.com/docs/guides/build/get-a-gpu-on-brev.md Installs the Brev command-line interface using Homebrew for macOS or Linux systems. ```bash brew install brevdev/homebrew-brev/brev ``` -------------------------------- ### Initialize Cog Project Source: https://replicate.com/docs/guides/build/optimize-models-with-pruna.md Creates a new directory and initializes a Cog project structure. ```bash mkdir my-pruna-model cd my-pruna-model cog init ``` -------------------------------- ### Replicate Prediction Object Example (JSON) Source: https://replicate.com/docs/topics/webhooks/receive-webhook.md An example of the JSON object representing an unfinished prediction, as sent in webhook requests. ```json { "id": "ufawqhfynnddngldkgtslldrkq", "version": "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", "created_at": "2022-04-26T22:13:06.224088Z", "started_at": null, "completed_at": null, "status": "starting", "input": { "text": "Alice" }, "output": null, "error": null, "logs": null, "metrics": {} } ``` -------------------------------- ### Run Model with Local File Input (Python) Source: https://replicate.com/docs/get-started/python.md Shows how to use a local file, like an image, as input to a Replicate model. This example uses the LLaVA vision model with a local image file. ```python import replicate image = open("my_fridge.jpg", "rb") output = replicate.run( "yorickvp/llava-13b:a0fdc44e4f2e1f20f2bb4e27846899953ac8e66c5886c5878fa1d6b73ce009e5", input={ "image": image, "prompt": "Here's what's in my fridge. What can I make for dinner tonight?" } ) print(output) # You have a well-stocked refrigerator filled with various fruits, vegetables, and ... ``` -------------------------------- ### Run Real-ESRGAN with JavaScript Source: https://replicate.com/docs/guides/run/upscale-images-with-ai-models.md Demonstrates how to use the Replicate JavaScript client to perform image upscaling using the Real-ESRGAN model. It includes installation, environment configuration, and the API call to process an image URL. ```bash npm install replicate export REPLICATE_API_TOKEN=[your-api-token] ``` ```javascript import Replicate from "replicate"; const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN, }); const output = await replicate.run( "nightmareai/real-esrgan:latest", { input: { image: "https://replicate.delivery/pbxt/Ing7Fa4YMk6YtcoG1YZnaK3UwbgDB5guRc5M2dEjV6ODNLMl/cat.jpg", scale: 2, face_enhance: false } } ); console.log(output); ``` -------------------------------- ### Install and configure Replicate CLI Source: https://replicate.com/docs/guides/run/make-art-with-stable-diffusion.md Commands to install the Replicate CLI on macOS and set the required API token environment variable. ```shell brew tap replicate/tap brew install replicate ``` ```plaintext export REPLICATE_API_TOKEN=... ``` -------------------------------- ### Create GitHub Repository and Push Code Source: https://replicate.com/docs/get-started/nextjs Use the GitHub CLI to create a new public repository and push your local code to it. Use the `--private` flag for private repositories. ```bash gh repo create my-replicate-app --public --push --source=. ``` -------------------------------- ### Run a Public Model with Text Prompt (Python) Source: https://replicate.com/docs/get-started/python.md Demonstrates how to run a public Replicate model, such as black-forest-labs/flux-schnell, using a text prompt and saving the generated image output. ```python import replicate output = replicate.run( "black-forest-labs/flux-schnell", input={"prompt": "an iguana on the beach, pointillism"} ) # Save the generated image with open('output.png', 'wb') as f: f.write(output[0].read()) print(f"Image saved as output.png") ``` -------------------------------- ### Example secret list output Source: https://replicate.com/docs/guides/cloudflare-image-cache Example output from `npx wrangler secret list`, showing the names and types of secrets configured for the worker. ```json [ { "name": "CLOUDFLARE_ACCOUNT_ID", "type": "secret_text" }, { "name": "CLOUDFLARE_API_TOKEN", "type": "secret_text" }, { "name": "CLOUDFLARE_IMAGE_ACCOUNT_HASH", "type": "secret_text" }, { "name": "REPLICATE_API_TOKEN", "type": "secret_text" } ] ``` -------------------------------- ### Create a deployment using the Replicate API Source: https://replicate.com/docs/topics/deployments/create-a-deployment.md This snippet demonstrates how to create a new model deployment by sending a POST request to the Replicate API. It requires an API token for authentication and a JSON payload specifying the model, version, and hardware configuration. ```shell curl -s \ -X POST \ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "my-app-image-generator", "model": "some-org/some-model", "version": "da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf", "hardware": "gpu-t4", "min_instances": 1, "max_instances": 5 }' \ https://api.replicate.com/v1/deployments ``` -------------------------------- ### Install Replicate npm Package Source: https://replicate.com/docs/guides/extend/cloudflare-image-cache.md Installs the Replicate npm package, which is necessary for interacting with Replicate's API from your Node.js or JavaScript environment. ```shell npm install replicate ```