# How Production Mode (IS_PROD) Affects Application Behavior in Screenshot-to-Code

> Discover how IS_PROD affects screenshot-to-code behavior. Learn how production mode enforces official API endpoints and adds monetization prompts, transforming the app for production use.

- Repository: [Abi Raja/screenshot-to-code](https://github.com/abi/screenshot-to-code)
- Tags: internals
- Published: 2026-03-02

---

**Setting `IS_PROD=True` in the screenshot-to-code backend disables custom OpenAI base URLs to enforce official API endpoints and appends credit purchase prompts to error messages, transforming the application from a flexible development tool into a locked-down, monetized production service.**

The `IS_PROD` environment variable acts as a critical feature toggle throughout the **abi/screenshot-to-code** repository. Defined in [`backend/config.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/config.py), this boolean flag determines whether the backend operates in permissive development mode or restricted production mode. Understanding how production mode affects application behavior is essential for self-hosting securely or contributing to the project's deployment infrastructure.

## How IS_PROD Is Defined in backend/config.py

The production flag originates as a simple environment variable read in [`backend/config.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/config.py). By default, the value is `False`, ensuring that fresh installations and local development environments maintain maximum flexibility.

```python

# backend/config.py

import os

# Production flag; set via environment variable `IS_PROD`

IS_PROD = os.environ.get("IS_PROD", False)

```

This global constant is then imported and evaluated in [`backend/routes/generate_code.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/routes/generate_code.py) to gate access to specific code paths.

## IS_PROD Effects on OpenAI API Routing

When `IS_PROD` is enabled, the application enforces strict control over which OpenAI endpoints the backend contacts. This prevents users from redirecting API traffic to unauthorized or non-compliant proxy services.

### Disabling Custom OpenAI Base URLs

In development mode (`IS_PROD=False`), users may supply their own `openAiBaseURL` via the client UI or environment variables, allowing the use of custom proxies or alternative OpenAI-compatible endpoints. In production mode, this capability is completely removed.

As implemented in [`backend/routes/generate_code.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/routes/generate_code.py) (lines 78-81), the code checks the flag before reading any user-provided base URL:

```python

# backend/routes/generate_code.py (excerpt)

openai_base_url: str | None = None

# Only allow a user-provided base URL when NOT in production

if not IS_PROD:
    openai_base_url = self._get_from_settings_dialog_or_env(
        params, "openAiBaseURL", OPENAI_BASE_URL
    )
if not openai_base_url:
    print("Using official OpenAI URL")

```

When `IS_PROD=True`, the conditional block is skipped, forcing `openai_base_url` to remain `None`. The subsequent fallback logic (lines 83-84) then ensures all traffic routes through the official OpenAI endpoint at `https://api.openai.com`.

## Error Message Modifications in Production Mode

Production mode also alters the user-facing error handling to support the hosted service's business model. Specifically, technical error messages are augmented with calls-to-action for purchasing code generation credits.

### Appending Credit Purchase Hints

In [`backend/routes/generate_code.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/routes/generate_code.py), error handlers for OpenAI authentication failures, rate limits, and model errors check the `IS_PROD` flag before constructing the response message. When enabled, the code appends a commercial prompt that does not appear in development environments:

```python

# backend/routes/generate_code.py (excerpt – OpenAI auth error)

error_message = (
    "Incorrect OpenAI key. Please make sure your OpenAI API key is correct, "
    "or create a new OpenAI API key on your OpenAI dashboard."
    + (" Alternatively, you can purchase code generation credits directly on this website."
       if IS_PROD else "")
)
await self.send_message("variantError", error_message, index, None, None)

```

This pattern appears consistently across error handling blocks (approximately lines 1006-1008 and similar locations), ensuring that production users receive monetization guidance while development instances remain uncluttered.

## Security and Compliance Implications

Enabling `IS_PROD` effectively **locks down the backend** to a controlled state suitable for multi-tenant hosting. By preventing arbitrary OpenAI base URLs, the flag mitigates risks associated with:
- **Data exfiltration** through malicious proxy endpoints
- **Compliance violations** from routing data through unauthorized regions
- **API key leakage** to third-party services

Concurrently, the error message modifications provide a seamless monetization path for the official hosted version without affecting open-source users running local instances.

## Summary

- **`IS_PROD` defaults to `False`** in [`backend/config.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/config.py), enabling development flexibility.
- **When `True`**, the flag disables custom `openAiBaseURL` inputs in [`generate_code.py`](https://github.com/abi/screenshot-to-code/blob/main/generate_code.py), forcing traffic exclusively to official OpenAI endpoints.
- **Production error messages** include credit purchase CTAs appended within conditional blocks checking `IS_PROD`.
- **Security posture** shifts from permissive (development) to restrictive (production) to prevent endpoint manipulation.

## Frequently Asked Questions

### What is the default value of IS_PROD in screenshot-to-code?

By default, `IS_PROD` is set to `False` in [`backend/config.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/config.py) via `os.environ.get("IS_PROD", False)`. This ensures that local development environments and fresh clones operate in permissive mode without requiring explicit configuration.

### Can I use a custom OpenAI endpoint when IS_PROD is enabled?

No. When `IS_PROD=True`, the code in [`backend/routes/generate_code.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/routes/generate_code.py) (lines 78-81) explicitly bypasses the logic that reads custom `openAiBaseURL` parameters from user settings. This forces all API traffic to the official OpenAI endpoint regardless of client-side configuration.

### Why do error messages change in production mode?

The application appends commercial calls-to-action ("purchase code generation credits") to technical error messages only when `IS_PROD` is true. This targets the hosted service's monetization model while keeping error messages concise and technical for local development users.

### Where should I set the IS_PROD environment variable?

Set `IS_PROD=True` in your production environment's configuration before launching the backend service. The application reads this variable once at startup in [`backend/config.py`](https://github.com/abi/screenshot-to-code/blob/main/backend/config.py), and the value persists throughout the lifecycle of the process, affecting all subsequent API routing decisions in [`generate_code.py`](https://github.com/abi/screenshot-to-code/blob/main/generate_code.py).