Build Custom Solutions with Flux.1 Schnell

Building solutions with Flux.1 [Schnell] takes minutes on NeurochainAI. Follow the simple steps below and add image generation powered to any solution you develop. Inference of images is run on NeurochainAI's Distributed Inference Network (DIN).

The FLUX.1 AI model is optimized using the GGUF method on NeurochainAI, which stands for GPT-Generated Unified Format. For those unfamiliar with the GGUF method, it significantly enhances the efficiency and compatibility of large language models (LLMs) by compressing them for faster loading and operation on local devices with limited resources. This format not only standardizes model packaging for improved cross-platform usability but also supports easy customization, allowing users to modify models on consumer-grade hardware without extensive retraining, thus broadening access to advanced AI functionalities.

In optimizing the model, we applied 8-bit, 6-bit, and 4-bit weight quantization, finding that the 8-bit format delivers performance nearly indistinguishable from 16-bit weights while cutting computation costs in half.

As mentioned above, the adoption of GGUF by NeurochainAI for the FLUX.1 AI model signifies a shift towards more efficient, scalable, cost-effective, and versatile AI inference solutions. It enables faster load times, easier data handling, and fosters future innovations in model development without sacrificing compatibility.

Pricing for FLUX.1 [Schnell] on NeurochainAI

Access the FLUX.1 [Schnell] model on NeurochainAI's Distributed Inference Network for ONLY $10, which will get you 10,000 generated images.

FLUX.1 [Schnell] Step-by-Step Guide

This guide will walk you through setting up Flux.1 Schnell on NeurochainAI. Follow these steps to integrate and test the Flux model using NCN Credits and the API Key.


Step 1: Access the NeurochainAI App

  1. Login using your email or wallet to access the NeurochainAI dashboard.


Step 2: Add NCN Credits

To use Flux.1 Schnell for inference, you need NCN Credits in your account:

  • Follow the instructions provided on the dashboard to top up your NCN Credits.

  • Credits are used to pay for inference and are required to run the model.


Step 3: Generate and Copy Your API Key

An API key is necessary to connect your chatbot to the NeurochainAI network:

  1. Go to the Use Distributed Inference Network section on the homepage of the dashboard.

  2. Find the Flux Image option.

  3. Click on Generate Key and copy your API key. You’ll need this key to connect to the network.


Step 4: Test the Flux Model

To test the Flux.1 Schnell model, you can use the following Python code in Replit. This quick setup lets you verify that the model is working and integrate it into your solution.

  1. Go to Replit.

  2. Create a new Python project.

  3. Copy the code below, paste it into the editor, and replace YOUR_API_KEY with the API Key you generated, and your custom prompt in the "YOUR_PROMPT_HERE" field.

import requests
import json 

# Step 1: Define the API endpoint (this is where we are sending the request)
url = "https://ncmb.neurochain.io/tasks/tti"

# Step 2: Create the data (payload) that we will send in the POST request
# This is the information the server needs to understand what we're asking for
data = {
    "model": "flux1-schnell-gguf",  # Model you want to use
    "prompt": "YOUR_PROMPT_HERE",  # The text prompt describing the image you want
    "size": "1024x1024",  # Size of the image
    "quality": "standard",  # Quality of the image
    "n": 1,  # Number of images to generate
    "seed": 1  # Seed for randomness (same seed gives same results)
}

# Step 3: Define the headers for the request
# The 'Authorization' header contains your API key, which allows you to access the service
headers = {
    "Authorization": "Bearer YOUR-API-KEY",  # Your unique API key for authentication
    "Content-Type": "application/json"  # This tells the server that we are sending JSON data
}

# Step 4: Send the POST request
# This line of code sends the request to the server, along with the data and headers we've prepared
response = requests.post(url, json=data, headers=headers)

# Step 5: Check if the request was successful
# We check for both 200 and 201 status codes as both indicate success in most APIs
if response.status_code in [200, 201]:
    print("Request was successful!")

    # Get the response JSON and handle the output
    response_data = response.json()

    # Extracting the first URL from the 'choices[0].text' field
    # The 'text' field is a string with JSON structure, so we need to parse it
    if "choices" in response_data and len(response_data["choices"]) > 0:
        raw_text = response_data["choices"][0]["text"]

        # Parse the text field, as it contains a JSON-like structure
        image_url = json.loads(raw_text)[0]
        print(f"Generated image URL: {image_url}")
    else:
        print("Could not find image URL in response. Full response:", response_data)
else:
    # If something went wrong, print an error message with details
    print(f"Error: Request failed with status code {response.status_code}")
    print("Error message:", response.text)

Run the code in Replit.

If the setup is correct, you should see an inference result from the Flux.1 Schnell model in the output, demonstrating that the model is successfully integrated and running on NeurochainAI’s infrastructure.

Last updated