# How the Negative Prompt Is Passed to the Generation API in Open-Generative-AI

> Discover how the negative prompt is passed to the generation API in Open-Generative-AI. Understand its flow from UI to local models and its current limitations with cloud services.

- Repository: [Anil Chandra Naidu Matcha/Open-Generative-AI](https://github.com/Anil-matcha/Open-Generative-AI)
- Tags: how-to-guide
- Published: 2026-04-24

---

**In the Open-Generative-AI application, the negative prompt flows from the UI to the local diffusion model via the `-n` CLI flag, but is currently discarded when using the remote Muapi cloud service.**

The Anil-matcha/Open-Generative-AI repository provides a unified desktop interface for generative AI models, supporting both local inference and cloud-based generation. Understanding how the **negative prompt** is passed to the generation API requires examining two distinct execution paths: a fully implemented local pipeline that translates the parameter into command-line arguments, and a remote integration where the field is documented but omitted from the actual HTTP payload.

## Local Inference Path (Desktop/Electron)

When running models locally, the application captures the negative prompt from the user interface and propagates it through three distinct layers before reaching the Stable Diffusion binary.

### UI Capture in ImageStudio.js

The negative prompt originates in the advanced settings panel of the image generation studio. In [`src/components/ImageStudio.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/components/ImageStudio.js), a local variable tracks the input value through an event listener:

```javascript
// src/components/ImageStudio.js (lines 44-46, 600)
let negativePrompt = '';
const negPromptInput = advancedPanel.querySelector('#negative-prompt-input');
if (negPromptInput) {
    negPromptInput.oninput = (e) => {
        negativePrompt = e.target.value;
    };
}

```

### Generation Request Construction

When the user initiates generation, the `negativePrompt` variable is passed to the local AI bridge along with other parameters. At line 1192 of [`ImageStudio.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/ImageStudio.js), the code explicitly includes `negative_prompt` in the options object:

```javascript
// src/components/ImageStudio.js (line 1192)
const res = await localAI.generate({
    model: selectedLocalModel,
    prompt,
    negative_prompt: negativePrompt || undefined,
    aspect_ratio: selectedAr,
    steps,
    guidance_scale: guidanceScale,
    seed,
});

```

### Electron CLI Translation

The `localAI.generate()` method forwards the parameters to the Electron main process. Inside [`electron/lib/localInference.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/electron/lib/localInference.js), the code detects the presence of `negative_prompt` and appends the `-n` flag to the arguments array passed to the `sd-cli` binary:

```javascript
// electron/lib/localInference.js (lines 84-86)
if (params.negative_prompt) {
    args.push('-n', params.negative_prompt);
}

```

The local inference layer effectively translates the JavaScript property into a command-line argument that the underlying Stable Diffusion CLI understands, ensuring the model steers away from the unwanted concepts specified by the user.

## Remote API Path (Muapi Cloud)

The cloud generation path through Muapi presents a different scenario where the negative prompt parameter is declared but not transmitted.

### Declared But Not Implemented

In [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js), the JSDoc for the `generateImage` method explicitly documents a `negative_prompt` parameter at line 20:

```javascript
// src/lib/muapi.js (line 20)
/**
 * @param {string} params.negative_prompt
 */
async generateImage(params) { /* … */ }

```

However, the actual payload construction (lines 35-40) omits this field entirely. The `finalPayload` object sent via POST request only includes `prompt`, `aspect_ratio`, `resolution`, and other select fields, while the `negative_prompt` value is discarded before the network request is dispatched.

This creates a functional asymmetry between the two modes: **local inference fully supports negative prompting**, while the **remote Muapi integration acts as a placeholder awaiting backend support**.

## Technical Implementation Summary

The codebase reveals a clear architectural distinction in how parameters flow through the system:

| Component | File Path | Role in Negative Prompt Handling |
|-----------|-----------|----------------------------------|
| **UI State** | [`src/components/ImageStudio.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/components/ImageStudio.js) | Captures input from `#negative-prompt-input` and stores it in the `negativePrompt` variable. |
| **Local Bridge** | [`electron/lib/localInference.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/electron/lib/localInference.js) | Translates the `negative_prompt` property into the `-n` CLI flag for the `sd-cli` binary. |
| **Remote Client** | [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js) | Documents the parameter in JSDoc but excludes it from the POST payload (lines 35-40). |

## Summary

- **Local mode** propagates the negative prompt from the React UI ([`ImageStudio.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/ImageStudio.js)) through the Electron IPC layer ([`localInference.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/localInference.js)), ultimately converting it to a `-n` command-line argument for the local Stable Diffusion binary.
- **Remote mode** currently drops the negative prompt; while the API client interface in [`muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/muapi.js) accepts the parameter, the implementation does not include it in the HTTP request to the Muapi endpoint.
- The `negative_prompt` field is optional in both paths, defaulting to `undefined` when empty to prevent passing empty strings to the CLI or API.

## Frequently Asked Questions

### Does the remote Muapi endpoint support negative prompts?

Currently, no. While the `generateImage` method in [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js) documents a `negative_prompt` parameter in its JSDoc signature at line 20, the actual payload construction (lines 35-40) does not include this field in the POST request. This is a known limitation in the current codebase that prevents negative prompts from reaching the cloud service.

### What CLI flag does the local inference use for negative prompts?

The Electron-based local inference translates the `negative_prompt` property into the `-n` flag. In [`electron/lib/localInference.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/electron/lib/localInference.js) at lines 84-86, the code checks `if (params.negative_prompt)` and executes `args.push('-n', params.negative_prompt)` to pass the value to the `sd-cli` binary.

### Where is the negative prompt stored in the application state?

The negative prompt is stored in a module-level variable named `negativePrompt` declared at line 44 of [`src/components/ImageStudio.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/components/ImageStudio.js). This variable is updated via an `oninput` event listener attached to the `#negative-prompt-input` DOM element at line 600, and is later referenced when constructing the generation request at line 1192.

### Is negative prompt support planned for the remote API?

The codebase structure suggests placeholder support has been prepared, as evidenced by the JSDoc annotation in [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js). However, the actual implementation requires backend support from the Muapi service and additional client-side code to include the parameter in the payload construction logic before the feature becomes functional.