Environment Variables
Configuration
Udility Diffuser requires an API key to communicate with OpenRouter for LLM-powered SVG generation. This key must be configured in your environment before the library can be initialized.
Required Environment Variables
| Variable | Description | Requirement |
| :--- | :--- | :--- |
| OPENROUTER_API_KEY | Your unique OpenRouter API key used for authenticating requests to Meta Llama models. | Required |
Obtaining an API Key
- Visit OpenRouter.
- Create an account or sign in.
- Navigate to the Keys section in your dashboard to generate a new API key.
- Copy the key for use in your configuration.
Setting the Environment Variable
You can configure the OPENROUTER_API_KEY using one of the following methods depending on your workflow:
Method 1: Operating System (Recommended)
Setting the variable in your shell is the most secure method as it keeps credentials out of your source code.
macOS / Linux:
export OPENROUTER_API_KEY='your_api_key_here'
Windows (Command Prompt):
set OPENROUTER_API_KEY=your_api_key_here
Windows (PowerShell):
$env:OPENROUTER_API_KEY = "your_api_key_here"
Method 2: Python Runtime
For quick testing or notebook environments (like Google Colab), you can set the variable directly in your script using the os module:
import os
from Udility import diffuser
# Set the environment variable before calling any diffuser functions
os.environ['OPENROUTER_API_KEY'] = 'your_api_key_here'
# Now you can generate images
diffuser.generate_image_from_text("A diagram of a plant cell.")
Method 3: Using a .env File
For production projects, use a .env file and the python-dotenv package to manage your secrets securely:
- Create a
.envfile in your project root:OPENROUTER_API_KEY=your_api_key_here - Load it in your Python script:
from dotenv import load_dotenv import os load_dotenv() # The diffuser will now be able to access the key via os.getenv
Error Handling
If the OPENROUTER_API_KEY is missing or cannot be retrieved from the environment, the library will raise an EnvironmentError:
EnvironmentError: The OpenRouter API key is not set. Please set it as an environment variable.
Ensure the key is set before importing or calling functions from Udility.diffuser, as the API client initializes upon module access.