Description
## Prerequisites
- **Go 1.21+**: Download and install from [https://go.dev/doc/install](https://go.dev/doc/install).
- **OpenAI API Key**: Create an account at [https://platform.openai.com/api-keys](https://platform.openai.com/api-keys) and generate a key with DALL-E access (requires billing enabled for paid usage).
- **ngrok or Cloudflare Tunnel**: For exposing local server to HTTPS (free tier sufficient).
- **ChatGPT Desktop app**: Latest version with Developer Mode support.
- Git for cloning the repository.
## Setup for ChatGPT Desktop
### Option 1: Using Developer Mode (Recommended)
1. Open ChatGPT Desktop app.
2. Go to **Settings → Apps & Connectors → Advanced settings → Enable Developer Mode**.
3. Start the MCP server locally (see Start Command above; it runs on `http://localhost:8080`).
4. Install and run ngrok: `ngrok http 8080` (sign up for free authtoken if needed). Copy the HTTPS URL (e.g., `https://abc123.ngrok-free.app`).
5. In ChatGPT: **Settings → Apps & Connectors → Create**.
6. Enter **Connector URL**: `https://abc123.ngrok-free.app/mcp` (append `/mcp`).
7. **Authentication**: None (uses env vars on server).
8. Save and test the connector.
### Option 2: Local Server Setup
1. Follow the Start Command to run the server on `localhost:8080`.
2. Use Cloudflare Tunnel:
- Install: `brew install cloudflared` (macOS) or equivalent.
- Run: `cloudflared tunnel --url http://localhost:8080`.
- Use the provided HTTPS URL + `/mcp` in ChatGPT connector.
3. Verify server logs show "Server listening on :8080" and test endpoint: `curl http://localhost:8080/mcp/health`.
## Configuration Examples
### Basic Setup
```bash
export OPENAI_API_KEY="sk-..."
go run .
```
- Saves images to `./images` with 1024x1024 default.
### Advanced Setup
```bash
export OPENAI_API_KEY="sk-..."
export IMAGE_SAVE_PATH="/path/to/custom/images"
export DEFAULT_SIZE="1792x1024" # DALL-E 3 HD landscape
export DALLE_MODEL="dall-e-3"
export PORT=9090 # Custom port
go run .
```
Update ngrok/Cloudflare to match port.
### Production Setup
- Use systemd/PM2 equivalent for Go (e.g., `nohup go run . &`).
- Secure with Cloudflare Zero Trust Tunnel (requires account).
- Set `IMAGE_SAVE_PATH` to persistent volume.
- Monitor OpenAI usage dashboard for costs.
- HTTPS only via tunnel; avoid direct localhost.
## Using with ChatGPT
- **Available Tools**: `generate_image` (text-to-image), `generate_variations` (image edits/variations).
- **Example Prompts**:
- "Use DALL-E to generate a futuristic cityscape at night."
- "Create a variation of [describe image] with more vibrant colors."
- "Generate a 1024x1024 portrait of a dragon in watercolor style."
- Images auto-save locally and return URLs/paths in responses.
- **Limitations/Considerations**:
- DALL-E 3/2 API costs apply (~$0.04–0.12/image).
- Rate limits: 50 images/min (adjustable via OpenAI tiers).
- No internet images; text prompts only.
- Custom sizes: 1024x1024, 1792x1024, etc. (DALL-E 3 supports HD).
- Server must stay running; reconnect if ngrok URL expires.
## Troubleshooting
- **"Invalid API Key"**: Verify `OPENAI_API_KEY` env var and DALL-E permissions.
- **Connector fails**: Ensure HTTPS URL with `/mcp`, check server logs for errors, test `curl https://your-url/mcp`.
- **Ngrok connection refused**: Server not running or wrong port; restart ngrok after server.
- **No images generated**: Check OpenAI quota/billing; prompt too vague (add details like style/size).
- **Port conflict**: Set `PORT=9090` env and update tunnel.
- **Logs**: Server prints to stdout; tail with `go run . 2>&1 | tee server.log`.
- **Go errors**: Run `go mod tidy`; ensure Go 1.21+ (`go version`).